Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:24:17

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 // detray core
0010 #include "detray/utils/ranges.hpp"
0011 
0012 #include "detray/definitions/containers.hpp"
0013 
0014 // GTest include(s)
0015 #include <gtest/gtest.h>
0016 
0017 using namespace detray;
0018 
0019 // Integration test for enumeration of a subrange
0020 GTEST_TEST(detray_utils, ranges_subrange_iota) {
0021   std::array<std::size_t, 2> seq{1u, 10u};
0022   std::array<std::size_t, 2> interval{3u, 7u};
0023 
0024   auto iota_sr = detray::ranges::subrange(detray::views::iota(seq), interval);
0025 
0026   // Check iterator category
0027   static_assert(detray::ranges::forward_range<decltype(iota_sr)>);
0028   static_assert(detray::ranges::bidirectional_range<decltype(iota_sr)>);
0029   static_assert(detray::ranges::random_access_range<decltype(iota_sr)>);
0030 
0031   std::size_t i{4u};
0032   for (const auto v : iota_sr) {
0033     ASSERT_EQ(i++, v);
0034   }
0035 
0036   // Check range composition with pipe operator
0037   auto iota_sr_comp = detray::views::iota(seq) |
0038                       detray::ranges::subrange(interval[0], interval[1]);
0039   i = 4u;
0040   for (const auto v : iota_sr_comp) {
0041     ASSERT_EQ(i++, v);
0042   }
0043 }
0044 
0045 // Integration test for enumeration of a subrange
0046 GTEST_TEST(detray_utils, ranges_enumerated_subrange) {
0047   struct uint_holder {
0048     unsigned int ui{0u};
0049   };
0050 
0051   dvector<uint_holder> seq = {{0u}, {1u}, {2u}, {3u}, {4u}, {5u}};
0052 
0053   std::size_t begin{1u};
0054   std::size_t end{4u};
0055   std::array<std::size_t, 2> interval{begin, end};
0056 
0057   auto enum_sr =
0058       detray::views::enumerate(detray::ranges::subrange(seq, interval));
0059 
0060   // Check iterator category
0061   static_assert(detray::ranges::random_access_range<decltype(enum_sr)>);
0062 
0063   dvector<unsigned int> expected{};
0064   for (const auto [i, v] : enum_sr) {
0065     ASSERT_EQ(i, v.ui - 1u);
0066     expected.push_back(v.ui);
0067   }
0068 
0069   // Check range composition with pipe operator
0070   auto enum_sr_comp = seq | detray::ranges::subrange(interval[0], interval[1]) |
0071                       detray::views::enumerate(2u);
0072 
0073   for (const auto [i, v] : enum_sr_comp) {
0074     // Enumeration starts at 'two'
0075     ASSERT_EQ(expected[i - 2u], v.ui);
0076   }
0077 }
0078 
0079 // Integration test for the picking of indexed elements from another range
0080 GTEST_TEST(detray_utils, ranges_pick_static_joined_sequence) {
0081   darray<dindex, 2> interval_1 = {2u, 4u};
0082   darray<dindex, 2> interval_2 = {7u, 9u};
0083 
0084   // The indices of the iota elements to be picked
0085   std::vector<dindex> reference = {2u, 3u, 7u, 8u};
0086   std::vector<dindex> check = {};
0087 
0088   struct uint_holder {
0089     unsigned int ui{0u};
0090   };
0091 
0092   dvector<uint_holder> seq = {{0u}, {1u}, {2u}, {3u}, {4u},
0093                               {5u}, {6u}, {7u}, {8u}};
0094 
0095   auto indices = detray::views::static_join(detray::views::iota(interval_1),
0096                                             detray::views::iota(interval_2));
0097   auto selected = detray::views::pick(seq, indices);
0098 
0099   // Check iterator category
0100   static_assert(detray::ranges::forward_range<decltype(indices)>);
0101   static_assert(detray::ranges::bidirectional_range<decltype(indices)>);
0102   static_assert(detray::ranges::random_access_range<decltype(indices)>);
0103   static_assert(detray::ranges::forward_range<decltype(selected)>);
0104   static_assert(detray::ranges::bidirectional_range<decltype(selected)>);
0105   static_assert(detray::ranges::random_access_range<decltype(selected)>);
0106 
0107   // Test inherited member functions
0108   const auto [i, v] = selected[2];
0109   ASSERT_EQ(i, 7u);
0110   ASSERT_EQ(v.ui, 7u);
0111   ASSERT_EQ(selected.size(), 4u);
0112   const auto [i_front, v_front] = selected.front();
0113   ASSERT_EQ(i_front, 2u);
0114   ASSERT_EQ(v_front.ui, 2u);
0115   const auto [i_back, v_back] = selected.back();
0116   ASSERT_EQ(i_back, 8u);
0117   ASSERT_EQ(v_back.ui, 8u);
0118 
0119   for (auto [j, w] : selected) {
0120     ASSERT_TRUE(j == w.ui);
0121     check.push_back(w.ui);
0122   }
0123   ASSERT_EQ(check.size(), reference.size());
0124   ASSERT_EQ(check, reference);
0125 
0126   // Check range composition with pipe operator
0127   auto selected_comp = seq | detray::views::pick(indices);
0128 
0129   check.clear();
0130   for (auto [j, w] : selected_comp) {
0131     ASSERT_TRUE(j == w.ui);
0132     check.push_back(w.ui);
0133   }
0134   ASSERT_EQ(check.size(), reference.size());
0135   ASSERT_EQ(check, reference);
0136 }