All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions
zip_test.cc File Reference

Test of util::zip(). More...

#include "larcorealg/CoreUtils/zip.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   ( zip_test )
 

Functions

void test_zip ()
 
void test_no_zip ()
 
 BOOST_AUTO_TEST_CASE (zip_testcase)
 

Detailed Description

Test of util::zip().

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 zip_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( zip_test )

Definition at line 14 of file zip_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( zip_testcase  )

Definition at line 99 of file zip_test.cc.

99  {
100 
101  test_zip();
102  test_no_zip();
103 
104 } // BOOST_AUTO_TEST_CASE(zip_testcase)
void test_no_zip()
Definition: zip_test.cc:86
void test_zip()
Definition: zip_test.cc:25
void test_no_zip ( )

Definition at line 86 of file zip_test.cc.

86  {
87 
88  unsigned int iLoop = 0U;
89  for (auto&& i [[gnu::unused]]: util::zip()) {}
90 
91  BOOST_TEST(iLoop == 0);
92 
93 } // test_no_zip()
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.
Definition: zip.h:295
void test_zip ( )

Definition at line 25 of file zip_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&& [ a, b ]: util::zip(twice, thrice)) {
48 
49  BOOST_TEST(a == twice[iLoop]);
50  BOOST_TEST(&a == &(twice[iLoop]));
51 
52  BOOST_TEST(b == thrice[iLoop]);
53  BOOST_TEST(&b == &thrice[iLoop]);
54 
55  ++iLoop;
56  } // for
57  BOOST_TEST(iLoop == twice.size());
58 
59  //
60  // iteration using the second element as lead
61  //
62 
63  // (make the second object shorter, so that we can check easily it leads)
64  thrice.pop_back();
65  thrice.pop_back();
66  assert(thrice.size() == N - 1);
67 
68  iLoop = 0;
69  for (auto&& [ a, b ]: util::zip<1>(twice, thrice)) {
70 
71  BOOST_TEST(a == twice[iLoop]);
72  BOOST_TEST(&a == &(twice[iLoop]));
73 
74  BOOST_TEST(b == thrice[iLoop]);
75  BOOST_TEST(&b == &thrice[iLoop]);
76 
77  ++iLoop;
78  } // for
79  BOOST_TEST(iLoop == thrice.size());
80 
81 
82 } // test_zip()
process_name gaushit a
process_name largeant stream1 can override from command line with o or output physics producers generator N
auto zip(Iterables &&...iterables)
Range-for loop helper iterating across many collections at the same time.
Definition: zip.h:295