All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
enumerate_test.cc
Go to the documentation of this file.
1 /**
2  * @file enumerate_test.cc
3  * @brief Test of `util::enumerate` and support utilities.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date April 14, 2019
6  *
7  */
8 
9 
10 // testing library
12 
13 // Boost libraries
14 #define BOOST_TEST_MODULE ( enumerate_test )
15 #include <boost/test/unit_test.hpp>
16 
17 // C/C++ libraries
18 #include <vector>
19 #include <array>
20 #include <cstddef> // std::size_t
21 #include <cassert>
22 
23 
24 // -----------------------------------------------------------------------------
26 
27  //
28  // standard use case with zipping included
29  //
30 
31  // prepare the data set
32  constexpr std::size_t N = 7U;
33 
34  std::array<int, N> twice;
35  std::vector<double> thrice(N + 1);
36 
37  for (std::size_t i = 0; i < N; ++i) {
38  twice[i] = 2 * i;
39  thrice[i] = 3.0 * i;
40  } // for
41  thrice[N] = 3.0 * N;
42 
43  //
44  // iteration using the first element as lead
45  //
46  unsigned int iLoop = 0;
47  for (auto&& [i, a, b]: util::enumerate(twice, thrice)) {
48 
49  BOOST_TEST(i == iLoop);
50 
51  BOOST_TEST(a == twice[iLoop]);
52  BOOST_TEST(&a == &(twice[iLoop]));
53 
54  BOOST_TEST(b == thrice[iLoop]);
55  BOOST_TEST(&b == &thrice[iLoop]);
56 
57  ++iLoop;
58  } // for
59  BOOST_TEST(iLoop == twice.size());
60 
61  //
62  // iteration using the second element as lead
63  //
64 
65  // (make the second object shorter, so that we can check easily it leads)
66  thrice.pop_back();
67  thrice.pop_back();
68  assert(thrice.size() == N - 1);
69 
70  iLoop = 0;
71  for (auto&& [i, a, b]: util::enumerate<1>(twice, thrice)) {
72 
73  BOOST_TEST(i == iLoop);
74 
75  BOOST_TEST(a == twice[iLoop]);
76  BOOST_TEST(&a == &(twice[iLoop]));
77 
78  BOOST_TEST(b == thrice[iLoop]);
79  BOOST_TEST(&b == &thrice[iLoop]);
80 
81  ++iLoop;
82  } // for
83  BOOST_TEST(iLoop == thrice.size());
84 
85 
86 } // test_enumerate()
87 
88 
89 // -----------------------------------------------------------------------------
90 // BEGIN Test cases -----------------------------------------------------------
91 // -----------------------------------------------------------------------------
92 BOOST_AUTO_TEST_CASE(enumerate_testcase) {
93 
95 
96 } // BOOST_AUTO_TEST_CASE(enumerate_testcase)
97 
98 
99 // -----------------------------------------------------------------------------
100 // END Test cases -------------------------------------------------------------
101 // -----------------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(AllTests)
Definition of util::enumerate().
void test_enumerate()
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
process_name gaushit a
process_name largeant stream1 can override from command line with o or output physics producers generator N