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

Test for GridContainers classes. More...

#include "lardata/Utilities/GridContainers.h"
#include "boost/test/unit_test.hpp"

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   ( PointIsolationAlg_test )
 

Functions

void GridContainer2DTest ()
 Test for a GridContainer2D of integers. More...
 
void GridContainer3DTest ()
 Test for a GridContainer3D of integers. More...
 
 BOOST_AUTO_TEST_CASE (GridContainer2DTestCase)
 
 BOOST_AUTO_TEST_CASE (GridContainer3DTestCase)
 

Detailed Description

Test for GridContainers classes.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
Date
June 30, 2016
See Also
GridContainers.h

This test instantiates some GridContainer objects.

The test is run with no arguments.

Tests are run:

See the documentation of the three functions for more information.

Definition in file GridContainers_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( PointIsolationAlg_test )

Definition at line 25 of file GridContainers_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( GridContainer2DTestCase  )

Definition at line 218 of file GridContainers_test.cc.

218  {
220 } // GridContainer2DTestCase
void GridContainer2DTest()
Test for a GridContainer2D of integers.
BOOST_AUTO_TEST_CASE ( GridContainer3DTestCase  )

Definition at line 222 of file GridContainers_test.cc.

222  {
224 } // GridContainer3DTestCase
void GridContainer3DTest()
Test for a GridContainer3D of integers.
void GridContainer2DTest ( )

Test for a GridContainer2D of integers.

The test instantiates a GridContainer2D<int> container with a hard-coded, known content, and verifies all the elements of the interface (except the move version of the insertion methods).

Definition at line 39 of file GridContainers_test.cc.

39  {
40 
41  //
42  // initialise
43  //
44  using Container_t = util::GridContainer2D<int>;
45  // BUG the double brace syntax is required to work around clang bug 21629
46  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
47  // not sure precisely why this is required a second time... it has to do
48  // with using the constructor of a base class
49  Container_t grid({{{ 2U, 3U }}});
50 
51  //
52  // container structure and indexing
53  //
54  BOOST_TEST(grid.dims() == 2U);
55 
56  BOOST_TEST(grid.size() == 6U);
57  BOOST_TEST(grid.sizeX() == 2U);
58  BOOST_TEST(grid.sizeY() == 3U);
59 
60  // BUG the double brace syntax is required to work around clang bug 21629
61  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
62  BOOST_TEST(grid.index({{ 0, 0 }}) == 0U);
63  BOOST_TEST(grid.index({{ 1, 2 }}) == 5U);
64  BOOST_CHECK_NO_THROW(grid.index({{ 2, 2 }})); // out-of-bound
65 
66  BOOST_TEST( grid.has(0));
67  BOOST_TEST( grid.has(grid.size() - 1));
68  BOOST_TEST(!grid.has(grid.size()));
69 
70  // BUG the double brace syntax is required to work around clang bug 21629
71  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
72  BOOST_TEST(grid.indexOffset({{ 0, 1 }}, {{ 1, 2 }}) == 4);
73  BOOST_TEST(grid.indexOffset({{ 1, 2 }}, {{ 0, 1 }}) == -4);
74 
75  //
76  // fill the container
77  //
78  Container_t::CellID_t cellID;
79  for (cellID[0] = 0; (size_t) cellID[0] < grid.sizeX(); ++cellID[0]) {
80  for (cellID[1] = 0; (size_t) cellID[1] < grid.sizeY(); ++cellID[1]) {
81 
82  auto cellIndex = grid.index(cellID);
83 
84  int count = cellID[0] + cellID[1];
85  while (count-- > 0) {
86  if (count & 1) grid.insert(cellID, count);
87  else grid.insert(cellIndex, count);
88  } // while
89 
90  } // for iy
91  } // for ix
92 
93  //
94  // read the container
95  //
96  for (cellID[0] = 0; (size_t) cellID[0] < grid.sizeX(); ++cellID[0]) {
97  for (cellID[1] = 0; (size_t) cellID[1] < grid.sizeY(); ++cellID[1]) {
98 
99  int count = cellID[0] + cellID[1];
100 
101  auto cellIndex = grid.index(cellID);
102  auto const& cell = (count & 1)? grid[cellIndex]: grid[cellID];
103 
104  BOOST_TEST_CHECKPOINT
105  ("[" << cellID[0] << "][" << cellID[1] << "]");
106  BOOST_TEST(cell.size() == (size_t) count);
107 
108  for (size_t k = 0; k < cell.size(); ++k) {
109  int val = cell[k];
110  BOOST_TEST_CHECKPOINT(" [" << k << "]");
111  BOOST_TEST(val == --count);
112  } // for
113 
114  } // for iy
115  } // for ix
116 
117 } // GridContainer2DTest()
Base class for a container of data arranged on a 2D-grid.
g grid
pdgs k
Definition: selectors.fcl:22
std::size_t count(Cont const &cont)
void GridContainer3DTest ( )

Test for a GridContainer3D of integers.

The test instantiates a GridContainer3D<int> container with a hard-coded, known content, and verifies all the elements of the interface (except the move version of the insertion methods).

Definition at line 129 of file GridContainers_test.cc.

129  {
130 
131  //
132  // initialise
133  //
134  using Container_t = util::GridContainer3D<int>;
135  // BUG the double brace syntax is required to work around clang bug 21629
136  // (https://bugs.llvm.org/show_bug.cgi?id=21629);
137  // not sure precisely why this is required a second time... it has to do
138  // with using the constructor of a base class
139  Container_t grid({{{ 2U, 3U, 4U }}});
140 
141  //
142  // container structure and indexing
143  //
144  BOOST_TEST(grid.dims() == 3U);
145 
146  BOOST_TEST(grid.size() == 24U);
147  BOOST_TEST(grid.sizeX() == 2U);
148  BOOST_TEST(grid.sizeY() == 3U);
149  BOOST_TEST(grid.sizeZ() == 4U);
150 
151  // BUG the double brace syntax is required to work around clang bug 21629
152  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
153  BOOST_TEST(grid.index({{ 0, 0, 0 }}) == 0U);
154  BOOST_TEST(grid.index({{ 1, 2, 3 }}) == 23U);
155  BOOST_CHECK_NO_THROW(grid.index({{ 2, 2, 3 }})); // out-of-bound
156 
157  BOOST_TEST( grid.has(0));
158  BOOST_TEST( grid.has(grid.size() - 1));
159  BOOST_TEST(!grid.has(grid.size()));
160 
161  // BUG the double brace syntax is required to work around clang bug 21629
162  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
163  BOOST_TEST(grid.indexOffset({{ 0, 1, 2 }}, {{ 1, 2, 3 }}) == 17);
164  BOOST_TEST(grid.indexOffset({{ 1, 2, 3 }}, {{ 0, 1, 2 }}) == -17);
165 
166  //
167  // fill the container
168  //
169  Container_t::CellID_t cellID;
170  for (cellID[0] = 0; (size_t) cellID[0] < grid.sizeX(); ++cellID[0]) {
171  for (cellID[1] = 0; (size_t) cellID[1] < grid.sizeY(); ++cellID[1]) {
172  for (cellID[2] = 0; (size_t) cellID[2] < grid.sizeZ(); ++cellID[2]) {
173 
174  auto cellIndex = grid.index(cellID);
175 
176  int count = cellID[0] + cellID[1] + cellID[2];
177  while (count-- > 0) {
178  if (count & 1) grid.insert(cellID, count);
179  else grid.insert(cellIndex, count);
180  } // while
181 
182  } // for iz
183  } // for iy
184  } // for ix
185 
186  //
187  // read the container
188  //
189  for (cellID[0] = 0; (size_t) cellID[0] < grid.sizeX(); ++cellID[0]) {
190  for (cellID[1] = 0; (size_t) cellID[1] < grid.sizeY(); ++cellID[1]) {
191  for (cellID[2] = 0; (size_t) cellID[2] < grid.sizeZ(); ++cellID[2]) {
192 
193  int count = cellID[0] + cellID[1] + cellID[2];
194 
195  auto cellIndex = grid.index(cellID);
196  auto const& cell = (count & 1)? grid[cellIndex]: grid[cellID];
197 
198  BOOST_TEST_CHECKPOINT
199  ("[" << cellID[0] << "][" << cellID[1] << "][" << cellID[2] << "]");
200  BOOST_TEST(cell.size() == (size_t) count);
201 
202  for (size_t k = 0; k < cell.size(); ++k) {
203  int val = cell[k];
204  BOOST_TEST_CHECKPOINT(" [" << k << "]");
205  BOOST_TEST(val == --count);
206  } // for
207 
208  } // for iz
209  } // for iy
210  } // for ix
211 
212 } // GridContainer3DTest()
g grid
pdgs k
Definition: selectors.fcl:22
std::size_t count(Cont const &cont)
Base class for a container of data arranged on a 3D-grid.