Macros | Functions
enumerate_test.cc File Reference

Test of util::enumerate and support utilities. More...

#include "larcorealg/CoreUtils/enumerate.h"
#include <boost/test/unit_test.hpp>
#include <vector>
#include <array>
#include <cstddef>
#include <cassert>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   ( enumerate_test )
 

Functions

void test_enumerate ()
 
 BOOST_AUTO_TEST_CASE (enumerate_testcase)
 

Detailed Description

Test of util::enumerate and support utilities.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.slac..nosp@m.stan.nosp@m.ford..nosp@m.edu)
Date
April 14, 2019

Definition in file enumerate_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( enumerate_test )

Definition at line 14 of file enumerate_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( enumerate_testcase  )

Definition at line 92 of file enumerate_test.cc.

92  {
93 
95 
96 } // BOOST_AUTO_TEST_CASE(enumerate_testcase)
void test_enumerate()
void test_enumerate ( )

Definition at line 25 of file enumerate_test.cc.

25  {
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()
auto enumerate(Iterables &&...iterables)
Range-for loop helper tracking the number of iteration.
Definition: enumerate.h:69
const double a
static bool * b
Definition: config.cpp:1043