Macros | Functions
readout_types_test.cc File Reference

Test of readout_types.h types. More...

#include "boost/test/unit_test.hpp"
#include "larcoreobj/SimpleTypesAndConstants/readout_types.h"

Go to the source code of this file.

Macros

#define READOUT_TYPES_TEST_SKIP_COMPILATION_ERRORS   1
 
#define BOOST_TEST_MODULE   ( readout_types_test )
 

Functions

template<typename ID >
constexpr bool assertGeoIDlevel ()
 
void TestIDvalidity (readout::CryostatID const &id, bool answer)
 
template<typename TESTID , typename REFID = TESTID>
void TestCompareSmallerID (TESTID const &id, REFID const &smaller)
 Test comparison operators. More...
 
template<typename TESTID , typename REFID = TESTID>
void TestCompareSameID (TESTID const &id, REFID const &same)
 Test comparison operators. More...
 
template<typename TESTID >
void TestCompareSelfID (TESTID const &id)
 Test comparison operators. More...
 
template<typename TESTID , typename REFID = TESTID>
void TestCompareLargerID (TESTID const &id, REFID const &larger)
 Test comparison operators. More...
 
template<typename TESTID , typename REFID = TESTID>
void TestIDcomparison (TESTID const &id, REFID const &smaller, REFID const &same, REFID const &larger)
 Test comparison operators. More...
 
void test_CryostatID_defaultConstructor ()
 
void test_CryostatID_directConstructor ()
 
void test_TPCsetID_defaultConstructor ()
 
void test_TPCsetID_integralConstructor ()
 
void test_TPCsetID_nestedConstructor ()
 
void test_TPCsetID_directConstructor ()
 
void test_ROPID_defaultConstructor ()
 
void test_ROPID_integralConstructor ()
 
void test_ROPID_nestedConstructor ()
 
void test_ROPID_directConstructor ()
 
 BOOST_AUTO_TEST_CASE (CryostatIDtest)
 
 BOOST_AUTO_TEST_CASE (TPCsetIDtest)
 
 BOOST_AUTO_TEST_CASE (ROPIDtest)
 

Detailed Description

Test of readout_types.h types.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
Date
June 19th, 2015

Definition in file readout_types_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( readout_types_test )

Definition at line 24 of file readout_types_test.cc.

#define READOUT_TYPES_TEST_SKIP_COMPILATION_ERRORS   1

Definition at line 11 of file readout_types_test.cc.

Function Documentation

template<typename ID >
constexpr bool assertGeoIDlevel ( )

Definition at line 33 of file readout_types_test.cc.

34  { return geo::details::geoElementLevel<ID>() == ID::Level; }
Level
Definition: Level.h:13
BOOST_AUTO_TEST_CASE ( CryostatIDtest  )

Definition at line 442 of file readout_types_test.cc.

442  {
445 }
void test_CryostatID_defaultConstructor()
void test_CryostatID_directConstructor()
BOOST_AUTO_TEST_CASE ( TPCsetIDtest  )

Definition at line 450 of file readout_types_test.cc.

450  {
455 }
void test_TPCsetID_integralConstructor()
void test_TPCsetID_defaultConstructor()
void test_TPCsetID_nestedConstructor()
void test_TPCsetID_directConstructor()
BOOST_AUTO_TEST_CASE ( ROPIDtest  )

Definition at line 460 of file readout_types_test.cc.

460  {
465 }
void test_ROPID_directConstructor()
void test_ROPID_integralConstructor()
void test_ROPID_nestedConstructor()
void test_ROPID_defaultConstructor()
void test_CryostatID_defaultConstructor ( )

Definition at line 165 of file readout_types_test.cc.

165  {
166 
167  BOOST_TEST_MESSAGE("Testing default-constructed cryostat ID");
168 
170 
171  // a default-constructed ID is invalid:
172  TestIDvalidity(cid, false);
173 
174 /* // feature not added
175  // test assignment from ID_t
176  cid = 1;
177  BOOST_TEST(cid.Cryostat == 1);
178 */
179 
180 } // test_CryostatID_defaultConstructor()
void TestIDvalidity(readout::CryostatID const &id, bool answer)
The data type to uniquely identify a cryostat.
Definition: geo_types.h:190
void test_CryostatID_directConstructor ( )

Definition at line 183 of file readout_types_test.cc.

183  {
184 
185  BOOST_TEST_CHECKPOINT("Testing cryostat ID constructed with an integer");
186 
187  readout::CryostatID cid(1);
188 
189  // an explicitly constructed ID is valid:
190  TestIDvalidity(cid, true);
191 
192  // check the ID value
193  BOOST_TEST(cid.Cryostat == readout::CryostatID::CryostatID_t(1));
194 
195  // test comparison operators
196  // (exercise copy constructor too)
197  readout::CryostatID smaller_cid(0), same_cid(cid), larger_cid(2);
198 
199  TestIDcomparison(cid, smaller_cid, same_cid, larger_cid);
200 
201 
202  // make sure the ID with cryostat 0 is fine (it's not a bad ID!)
203  BOOST_TEST_CHECKPOINT("Testing cryostat ID constructed with an integer 0");
204 
205  readout::CryostatID first_cid(0);
206  TestIDvalidity(cid, true);
207 
208  // check the ID value
209  BOOST_TEST(first_cid.Cryostat == readout::CryostatID::CryostatID_t(0));
210 
211 } // test_CryostatID_directConstructor()
void TestIDvalidity(readout::CryostatID const &id, bool answer)
unsigned int CryostatID_t
Type for the ID number.
Definition: geo_types.h:191
void TestIDcomparison(TESTID const &id, REFID const &smaller, REFID const &same, REFID const &larger)
Test comparison operators.
The data type to uniquely identify a cryostat.
Definition: geo_types.h:190
void test_ROPID_defaultConstructor ( )

Definition at line 315 of file readout_types_test.cc.

315  {
316 
317  BOOST_TEST_CHECKPOINT("Testing default-constructed ROP ID");
318 
319  readout::ROPID rid;
320 
321  // a default-constructed ID is invalid:
322  TestIDvalidity(rid, false);
323 
324 } // test_ROPID_defaultConstructor()
Class identifying a set of planes sharing readout channels.
void TestIDvalidity(readout::CryostatID const &id, bool answer)
void test_ROPID_directConstructor ( )

Definition at line 372 of file readout_types_test.cc.

372  {
373 
374  BOOST_TEST_CHECKPOINT("Testing ROP ID constructed with indices");
375 
376  readout::ROPID rid(1, 15, 32);
377 
378  // an explicitly constructed ID is valid:
379  TestIDvalidity(rid, true);
380 
381  // check the ID value
382  BOOST_TEST(rid.Cryostat == readout::CryostatID::CryostatID_t( 1));
383  BOOST_TEST(rid.TPCset == readout::TPCsetID::TPCsetID_t(15));
384  BOOST_TEST(rid.ROP == readout::ROPID::ROPID_t(32));
385 
386  BOOST_TEST_CHECKPOINT("Testing comparison with same TPC set ID");
387 
389  smaller_rid(1, 15, 31), same_rid(1, 15, 32), larger_rid(1, 15, 33);
390  TestIDcomparison(rid, smaller_rid, same_rid, larger_rid);
391 
392  BOOST_TEST_CHECKPOINT("Testing comparison with different TPC set ID (1)");
393  readout::ROPID smaller_sid1(1, 14, 33), larger_sid1(1, 16, 31);
394  TestCompareSmallerID(rid, smaller_sid1);
395  TestCompareLargerID(rid, larger_sid1);
396  BOOST_TEST_CHECKPOINT("Testing comparison with different TPC set ID (2)");
397  readout::ROPID smaller_sid2(1, 14, 32), larger_sid2(1, 16, 32);
398  TestCompareSmallerID(rid, smaller_sid2);
399  TestCompareLargerID(rid, larger_sid2);
400 
401  BOOST_TEST_CHECKPOINT("Testing comparison with different cryostat ID");
402  readout::ROPID smaller_cid1(0, 15, 33), larger_cid1(2, 15, 31);
403  TestCompareSmallerID(rid, smaller_cid1);
404  TestCompareLargerID(rid, larger_cid1);
405  BOOST_TEST_CHECKPOINT("Testing comparison with different cryostat ID (2)");
406  readout::ROPID smaller_cid2(0, 15, 32), larger_cid2(2, 15, 32);
407  TestCompareSmallerID(rid, smaller_cid2);
408  TestCompareLargerID(rid, larger_cid2);
409 
410  // test setting and accessing a single index
411  BOOST_TEST(rid.getIndex<0U>() == 1);
412  rid.writeIndex<0U>() = 2;
413  BOOST_TEST(rid.getIndex<0U>() == 2);
414 
415  BOOST_TEST(rid.getIndex<1U>() == 15);
416  rid.writeIndex<1U>() = 19;
417  BOOST_TEST(rid.getIndex<1U>() == 19);
418 
419  BOOST_TEST(rid.getIndex<2U>() == 32);
420  rid.writeIndex<2U>() = 76;
421  BOOST_TEST(rid.getIndex<2U>() == 76);
422 
423  // make sure the ID with TPC 0 is fine (it's not a bad ID!)
424  BOOST_TEST_CHECKPOINT("Testing ROP ID constructed with a ROP #0");
425 
426  readout::ROPID first_rid(0, 0, 0);
427  TestIDvalidity(first_rid, true);
428 
429  // - check the ID value
430  BOOST_TEST(first_rid.Cryostat == readout::CryostatID::CryostatID_t(0));
431  BOOST_TEST(first_rid.TPCset == readout::TPCsetID::TPCsetID_t(0));
432  BOOST_TEST(first_rid.ROP == readout::ROPID::ROPID_t(0));
433 
434 } // test_ROPID_directConstructor()
unsigned int ROPID_t
Type for the ID number.
unsigned short TPCsetID_t
Type for the ID number.
Definition: readout_types.h:71
void TestCompareSmallerID(TESTID const &id, REFID const &smaller)
Test comparison operators.
void TestCompareLargerID(TESTID const &id, REFID const &larger)
Test comparison operators.
Class identifying a set of planes sharing readout channels.
void TestIDvalidity(readout::CryostatID const &id, bool answer)
unsigned int CryostatID_t
Type for the ID number.
Definition: geo_types.h:191
void TestIDcomparison(TESTID const &id, REFID const &smaller, REFID const &same, REFID const &larger)
Test comparison operators.
void test_ROPID_integralConstructor ( )

Definition at line 327 of file readout_types_test.cc.

327  {
328 
329  BOOST_TEST_CHECKPOINT("Testing integral-constructed ROP ID");
330 
331 #if READOUT_TYPES_TEST_SKIP_COMPILATION_ERRORS
332  BOOST_TEST_MESSAGE(" (test skipped)");
333 #else
334  readout::ROPID rid(1);
335 
336  BOOST_TEST_MESSAGE("ROPID(1) = " << std::string(rid));
337 
338  readout::ROPID::ROPID_t what = rid;
339 
340  BOOST_TEST_MESSAGE("int(ROPID(1)) = " << what);
341 
342 #endif // READOUT_TYPES_TEST_SKIP_COMPILATION_ERRORS
343 
344 } // test_ROPID_integralConstructor()
std::string string
Definition: nybbler.cc:12
unsigned int ROPID_t
Type for the ID number.
Class identifying a set of planes sharing readout channels.
void test_ROPID_nestedConstructor ( )

Definition at line 347 of file readout_types_test.cc.

347  {
348 
349  BOOST_TEST_CHECKPOINT("Testing ID-constructed ROP ID");
350 
351  readout::TPCsetID sid(1, 15);
352  readout::ROPID rid(sid, 32);
353 
354  // an explicitly constructed ID is valid:
355  TestIDvalidity(rid, true);
356 
357  // check the ID value
358  BOOST_TEST(rid.Cryostat == readout::CryostatID::CryostatID_t( 1));
359  BOOST_TEST(rid.TPCset == readout::TPCsetID::TPCsetID_t(15));
360  BOOST_TEST(rid.ROP == readout::ROPID::ROPID_t(32));
361 
362  // test comparison operators (exercise copy constructor too)
363  BOOST_TEST_CHECKPOINT("Testing comparison with ROP ID");
364  readout::ROPID smaller_rid(sid, rid.ROP - 1), same_rid(rid),
365  larger_rid(sid, rid.ROP + 1);
366 
367  TestIDcomparison(rid, smaller_rid, same_rid, larger_rid);
368 
369 } // test_ROPID_nestedConstructor()
unsigned int ROPID_t
Type for the ID number.
unsigned short TPCsetID_t
Type for the ID number.
Definition: readout_types.h:71
Class identifying a set of TPC sharing readout channels.
Definition: readout_types.h:70
Class identifying a set of planes sharing readout channels.
void TestIDvalidity(readout::CryostatID const &id, bool answer)
unsigned int CryostatID_t
Type for the ID number.
Definition: geo_types.h:191
void TestIDcomparison(TESTID const &id, REFID const &smaller, REFID const &same, REFID const &larger)
Test comparison operators.
void test_TPCsetID_defaultConstructor ( )

Definition at line 215 of file readout_types_test.cc.

215  {
216 
217  BOOST_TEST_CHECKPOINT("Testing default-constructed TPC set ID");
218 
219  readout::TPCsetID sid;
220 
221  // a default-constructed ID is invalid:
222  TestIDvalidity(sid, false);
223 
224 } // test_TPCsetID_defaultConstructor()
Class identifying a set of TPC sharing readout channels.
Definition: readout_types.h:70
void TestIDvalidity(readout::CryostatID const &id, bool answer)
void test_TPCsetID_directConstructor ( )

Definition at line 272 of file readout_types_test.cc.

272  {
273 
274  BOOST_TEST_CHECKPOINT("Testing TPC set ID constructed with indices");
275 
276  readout::TPCsetID sid(1, 15);
277 
278  // an explicitly constructed ID is valid:
279  TestIDvalidity(sid, true);
280 
281  BOOST_TEST_CHECKPOINT("Testing comparison with same cryostat ID");
282 
283  readout::TPCsetID smaller_sid(1, 14), same_sid(1, 15), larger_sid(1, 16);
284  TestIDcomparison(sid, smaller_sid, same_sid, larger_sid);
285 
286  BOOST_TEST_CHECKPOINT("Testing comparison with different cryostat ID");
287  readout::TPCsetID smaller_cid(0, 16), larger_cid(2, 14);
288  TestCompareSmallerID(sid, smaller_cid);
289  TestCompareLargerID(sid, larger_cid);
290 
291  // test setting and accessing a single index
292  BOOST_TEST(sid.getIndex<0U>() == 1);
293  sid.writeIndex<0U>() = 2;
294  BOOST_TEST(sid.getIndex<0U>() == 2);
295 
296  BOOST_TEST(sid.getIndex<1U>() == 15);
297  sid.writeIndex<1U>() = 19;
298  BOOST_TEST(sid.getIndex<1U>() == 19);
299 
300  // make sure the ID with TPC set 0 is fine (it's not a bad ID!)
301  BOOST_TEST_CHECKPOINT("Testing TPC set ID constructed with a TPC set #0");
302 
303  readout::TPCsetID first_sid(0, 0);
304  TestIDvalidity(first_sid, true);
305 
306  // - check the ID value
307  BOOST_TEST(first_sid.Cryostat == readout::CryostatID::CryostatID_t(0));
308  BOOST_TEST(first_sid.TPCset == readout::TPCsetID::TPCsetID_t(0));
309 
310 
311 } // test_TPCsetID_directConstructor()
unsigned short TPCsetID_t
Type for the ID number.
Definition: readout_types.h:71
void TestCompareSmallerID(TESTID const &id, REFID const &smaller)
Test comparison operators.
void TestCompareLargerID(TESTID const &id, REFID const &larger)
Test comparison operators.
Class identifying a set of TPC sharing readout channels.
Definition: readout_types.h:70
void TestIDvalidity(readout::CryostatID const &id, bool answer)
unsigned int CryostatID_t
Type for the ID number.
Definition: geo_types.h:191
void TestIDcomparison(TESTID const &id, REFID const &smaller, REFID const &same, REFID const &larger)
Test comparison operators.
void test_TPCsetID_integralConstructor ( )

Definition at line 227 of file readout_types_test.cc.

227  {
228 
229  BOOST_TEST_CHECKPOINT("Testing integral-constructed TPC set ID");
230 
231 #if READOUT_TYPES_TEST_SKIP_COMPILATION_ERRORS
232  BOOST_TEST_MESSAGE(" (test skipped)");
233 #else
234  readout::TPCsetID sid(1);
235 
236  BOOST_TEST_MESSAGE("TPCsetID(1) = " << std::string(sid));
237 
239 
240  BOOST_TEST_MESSAGE("int(TPCsetID(1)) = " << what);
241 
242 #endif // READOUT_TYPES_TEST_SKIP_COMPILATION_ERRORS
243 
244 } // test_TPCsetID_integralConstructor()
std::string string
Definition: nybbler.cc:12
unsigned short TPCsetID_t
Type for the ID number.
Definition: readout_types.h:71
Class identifying a set of TPC sharing readout channels.
Definition: readout_types.h:70
void test_TPCsetID_nestedConstructor ( )

Definition at line 247 of file readout_types_test.cc.

247  {
248 
249  BOOST_TEST_CHECKPOINT("Testing ID-constructed TPC set ID");
250 
251  readout::CryostatID cid(1);
252  readout::TPCsetID sid(cid, 15);
253 
254  // an explicitly constructed ID is valid:
255  TestIDvalidity(sid, true);
256 
257  // check the ID value
258  BOOST_TEST(sid.Cryostat == readout::CryostatID::CryostatID_t( 1));
259  BOOST_TEST(sid.TPCset == readout::TPCsetID::TPCsetID_t(15));
260 
261  // test comparison operators (exercise copy constructor too)
262  // - with TPC ID
263  BOOST_TEST_CHECKPOINT("Testing comparison with TPC set ID");
264  readout::TPCsetID smaller_sid(cid, sid.TPCset - 1), same_sid(sid),
265  larger_sid(cid, sid.TPCset + 1);
266 
267  TestIDcomparison(sid, smaller_sid, same_sid, larger_sid);
268 
269 } // test_TPCsetID_nestedConstructor()
unsigned short TPCsetID_t
Type for the ID number.
Definition: readout_types.h:71
Class identifying a set of TPC sharing readout channels.
Definition: readout_types.h:70
void TestIDvalidity(readout::CryostatID const &id, bool answer)
unsigned int CryostatID_t
Type for the ID number.
Definition: geo_types.h:191
void TestIDcomparison(TESTID const &id, REFID const &smaller, REFID const &same, REFID const &larger)
Test comparison operators.
The data type to uniquely identify a cryostat.
Definition: geo_types.h:190
template<typename TESTID , typename REFID = TESTID>
void TestCompareLargerID ( TESTID const &  id,
REFID const &  larger 
)

Test comparison operators.

Definition at line 140 of file readout_types_test.cc.

140  {
141  BOOST_TEST( id < larger );
142  BOOST_TEST( id != larger );
143  BOOST_TEST(!(id == larger) );
144  BOOST_TEST(!(larger < id) );
145  BOOST_TEST(larger.cmp(id) > 0);
146  BOOST_TEST(id.cmp(larger) < 0);
147 } // TestCompareLargerID()
template<typename TESTID , typename REFID = TESTID>
void TestCompareSameID ( TESTID const &  id,
REFID const &  same 
)

Test comparison operators.

Definition at line 124 of file readout_types_test.cc.

124  {
125  BOOST_TEST(!(id < same) );
126  BOOST_TEST( id == same );
127  BOOST_TEST(!(id != same) );
128  BOOST_TEST(!(same < id) );
129  BOOST_TEST(same.cmp(id) == 0);
130  BOOST_TEST(id.cmp(same) == 0);
131 } // TestCompareSameID()
template<typename TESTID >
void TestCompareSelfID ( TESTID const &  id)

Test comparison operators.

Definition at line 135 of file readout_types_test.cc.

136  { return TestCompareSameID(id, id); }
void TestCompareSameID(TESTID const &id, REFID const &same)
Test comparison operators.
template<typename TESTID , typename REFID = TESTID>
void TestCompareSmallerID ( TESTID const &  id,
REFID const &  smaller 
)

Test comparison operators.

Definition at line 113 of file readout_types_test.cc.

113  {
114  BOOST_TEST(!(id < smaller) );
115  BOOST_TEST(!(id == smaller) );
116  BOOST_TEST( id != smaller );
117  BOOST_TEST( smaller < id );
118  BOOST_TEST(smaller.cmp(id) < 0);
119  BOOST_TEST(id.cmp(smaller) > 0);
120 } // TestCompareSmallerID()
template<typename TESTID , typename REFID = TESTID>
void TestIDcomparison ( TESTID const &  id,
REFID const &  smaller,
REFID const &  same,
REFID const &  larger 
)

Test comparison operators.

Definition at line 152 of file readout_types_test.cc.

157  {
158  TestCompareSmallerID(id, smaller);
159  TestCompareSameID(id, same);
160  TestCompareSelfID(id);
161  TestCompareLargerID(id, larger);
162 } // TestCryostatComparison()
void TestCompareSelfID(TESTID const &id)
Test comparison operators.
void TestCompareSmallerID(TESTID const &id, REFID const &smaller)
Test comparison operators.
void TestCompareLargerID(TESTID const &id, REFID const &larger)
Test comparison operators.
void TestCompareSameID(TESTID const &id, REFID const &same)
Test comparison operators.
void TestIDvalidity ( readout::CryostatID const &  id,
bool  answer 
)

Definition at line 102 of file readout_types_test.cc.

102  {
103  // - check isValid
104  BOOST_TEST(id.isValid == answer);
105  // - check operator!
106  BOOST_TEST(!id == !answer);
107  // - check operator bool
108  BOOST_TEST((bool)id == answer);
109 } // TestIDvalidity()