Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-19 07:48:54

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Utilities/Ranges.hpp"
0012 
0013 #include <array>
0014 #include <ranges>
0015 #include <set>
0016 #include <vector>
0017 
0018 namespace ActsTests {
0019 
0020 BOOST_AUTO_TEST_SUITE(RangesTests)
0021 
0022 BOOST_AUTO_TEST_CASE(ToVectorFromView) {
0023   std::array<int, 6> values = {1, 2, 3, 4, 5, 6};
0024 
0025   auto evenTimesTen =
0026       values | std::views::filter([](int value) { return value % 2 == 0; }) |
0027       std::views::transform([](int value) { return value * 10; });
0028 
0029   auto result = evenTimesTen | Acts::Ranges::to<std::vector>;
0030 
0031   std::vector<int> expected = {20, 40, 60};
0032   BOOST_CHECK_EQUAL_COLLECTIONS(expected.begin(), expected.end(),
0033                                 result.begin(), result.end());
0034 }
0035 
0036 BOOST_AUTO_TEST_CASE(ToSetRemovesDuplicatesAndOrders) {
0037   std::vector<int> values = {4, 1, 4, 3, 2, 2};
0038 
0039   auto result = values | Acts::Ranges::to<std::set>;
0040 
0041   std::set<int> expected = {1, 2, 3, 4};
0042   BOOST_CHECK_EQUAL_COLLECTIONS(expected.begin(), expected.end(),
0043                                 result.begin(), result.end());
0044 }
0045 
0046 BOOST_AUTO_TEST_CASE(ToAdaptorCallableSyntax) {
0047   std::vector<int> values = {5, 6, 7};
0048 
0049   auto adaptor = Acts::Ranges::to_adaptor<std::vector>{};
0050   auto result = adaptor(values);
0051 
0052   std::vector<int> expected = {5, 6, 7};
0053   BOOST_CHECK_EQUAL_COLLECTIONS(expected.begin(), expected.end(),
0054                                 result.begin(), result.end());
0055 }
0056 
0057 BOOST_AUTO_TEST_SUITE_END()
0058 
0059 }  // namespace ActsTests