Macros | Functions
TrajectoryPointFlags_test.cc File Reference

Simple test on a recob::TrajectoryPointFlags object. More...

#include "boost/test/unit_test.hpp"
#include "lardataobj/RecoBase/TrajectoryPointFlags.h"
#include <set>
#include <iostream>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   ( trajectorypointflags_test )
 

Functions

void CheckFlagsByIndex (recob::TrajectoryPointFlags const &flags, std::set< util::flags::Index_t > const &expectedDefined, std::set< util::flags::Index_t > const &expectedSet)
 
void TrajectoryPointFlagsTest_DefaultConstructor ()
 
void TrajectoryPointFlagsTest_FlagsConstructor ()
 
void TrajectoryPointFlagsTest_BitmaskConstructor ()
 
void TrajectoryPointFlagsDocumentationTest_TrajectoryPointFlags_FromMaskTag_t ()
 
void TrajectoryPointFlagsDocumentationTest_TrajectoryPointFlags_HitIndex_t_Flags ()
 
void TrajectoryPointFlagsDocumentationTest_makeMask ()
 
void TrajectoryPointFlagsDocumentationTest ()
 
 BOOST_AUTO_TEST_CASE (TrajectoryPointFlagsTestCase)
 
 BOOST_AUTO_TEST_CASE (TrajectoryPointFlagsDocumentationTestCase)
 

Detailed Description

Simple test on a recob::TrajectoryPointFlags object.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
Date
January 25, 2016
Version
1.0

This test simply creates recob::TrajectoryPointFlags objects and verifies that the values it can access are the right ones.

See http://www.boost.org/libs/test for the Boost test library home page.

Definition in file TrajectoryPointFlags_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( trajectorypointflags_test )

Definition at line 26 of file TrajectoryPointFlags_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( TrajectoryPointFlagsTestCase  )

Definition at line 444 of file TrajectoryPointFlags_test.cc.

444  {
445 
449 
450 } // BOOST_AUTO_TEST_CASE(TrajectoryPointFlagsTestCase)
void TrajectoryPointFlagsTest_DefaultConstructor()
void TrajectoryPointFlagsTest_FlagsConstructor()
void TrajectoryPointFlagsTest_BitmaskConstructor()
BOOST_AUTO_TEST_CASE ( TrajectoryPointFlagsDocumentationTestCase  )

Definition at line 453 of file TrajectoryPointFlags_test.cc.

453  {
454 
456 
457 } // BOOST_AUTO_TEST_CASE(TrajectoryPointFlagsDocumentationTestCase)
void TrajectoryPointFlagsDocumentationTest()
void CheckFlagsByIndex ( recob::TrajectoryPointFlags const &  flags,
std::set< util::flags::Index_t > const &  expectedDefined,
std::set< util::flags::Index_t > const &  expectedSet 
)

Definition at line 40 of file TrajectoryPointFlags_test.cc.

44  {
45 
46  using trkflag = recob::TrajectoryPointFlags::flag;
47 
48  /*
49  * FlagIndex_t nFlags() const
50  */
51  BOOST_TEST(flags.nFlags() == trkflag::maxFlags());
52 
53  for(
55  i <= trkflag::maxFlags();
56  ++i)
57  {
58  bool const allocated = (i < trkflag::maxFlags());
59  bool const defined = (expectedDefined.count(i) > 0);
60  bool const set = (expectedSet.count(i) > 0);
61 
62  BOOST_TEST_MESSAGE("Testing flag #" << i);
63 
64  /*
65  * constexpr bool isAllocated(FlagIndex_t flag) const
66  */
67  BOOST_TEST(flags.isAllocated(i) == allocated);
68 
69  // for unallocated flag indices, most of the flag interface has
70  // undefined behaviour
71  if (!allocated) {
72  /*
73  * bool test(FlagIndex_t flag) const
74  */
75  BOOST_CHECK_THROW
77 
78  continue;
79  } // if not allocated
80 
81  /*
82  * constexpr bool isFlag(FlagIndex_t flag) const
83  */
84  BOOST_TEST(flags.isFlag(i) == allocated);
85 
86  /*
87  * constexpr bool isDefined(FlagIndex_t flag) const
88  */
89  BOOST_TEST(flags.isDefined(i) == defined);
90 
91  /*
92  * bool test(FlagIndex_t flag) const
93  */
94  if (!defined) {
95  BOOST_CHECK_THROW(
97  );
98  continue;
99  }
100  BOOST_TEST(flags.test(i) == set);
101 
102  /*
103  * get(FlagIndex_t flag) const
104  */
105  BOOST_TEST(flags.get(i) == set);
106 
107  /*
108  * bool isSet(FlagIndex_t flag) const
109  */
110  BOOST_TEST(flags.isSet(i) == set);
111 
112  /*
113  * bool isUnset(FlagIndex_t flag) const
114  */
115  BOOST_TEST(flags.isUnset(i) == !set);
116 
117  } // for
118 
119 } // CheckFlagsByIndex()
TrajectoryPointFlagTraits flag
Type of flag traits (indices and meaning of flags).
typename Mask_t::OutOfRangeError OutOfRangeError
Out-of-range flag index.
Definition: FlagSet.h:70
typename Mask_t::FlagNotDefinedError FlagNotDefinedError
Flag not defined.
Definition: FlagSet.h:73
Flags_t::FlagIndex_t FlagIndex_t
Type of index of single flag.
void TrajectoryPointFlagsDocumentationTest ( )

Definition at line 425 of file TrajectoryPointFlags_test.cc.

425  {
426  // This test is meant to check that the code in the documentation,
427  // which is copied here, is compilable.
431 
432 } // TrajectoryPointFlagsTest()
void TrajectoryPointFlagsDocumentationTest_makeMask()
void TrajectoryPointFlagsDocumentationTest_TrajectoryPointFlags_FromMaskTag_t()
void TrajectoryPointFlagsDocumentationTest_TrajectoryPointFlags_HitIndex_t_Flags()
void TrajectoryPointFlagsDocumentationTest_makeMask ( )

Definition at line 414 of file TrajectoryPointFlags_test.cc.

414  {
415  /*
416  * Mask_t makeMask(Flags... flags)
417  */
418 
419  using trkflag = recob::TrajectoryPointFlags::flag;
420  constexpr auto mask [[gnu::unused]] = recob::TrajectoryPointFlags::makeMask
421  (trkflag::NoPoint, trkflag::Merged);
422 } // TrajectoryPointFlagsDocumentationTest_makeMask()
TrajectoryPointFlagTraits flag
Type of flag traits (indices and meaning of flags).
static constexpr Mask_t makeMask(Flags...flags)
Returns a bit mask with only the specified bit set.
void TrajectoryPointFlagsDocumentationTest_TrajectoryPointFlags_FromMaskTag_t ( )

Definition at line 382 of file TrajectoryPointFlags_test.cc.

383 {
384 
385  /*
386  * constexpr TrajectoryPointFlags(FromMaskTag_t, HitIndex_t, Mask_t)
387  */
388  using trkflag = recob::TrajectoryPointFlags::flag;
389  constexpr recob::TrajectoryPointFlags flags [[gnu::unused]](
390  12,
392  trkflag::NoPoint,
393  trkflag::HitIgnored
394  )
395  );
396 } // TrajectoryPointFlagsDocumentationTest_TrajectoryPointFlags_FromMaskTag_t()
TrajectoryPointFlagTraits flag
Type of flag traits (indices and meaning of flags).
static constexpr Mask_t makeMask(Flags...flags)
Returns a bit mask with only the specified bit set.
Set of flags pertaining a point of the track.
void TrajectoryPointFlagsDocumentationTest_TrajectoryPointFlags_HitIndex_t_Flags ( )

Definition at line 399 of file TrajectoryPointFlags_test.cc.

400 {
401 
402  /*
403  * constexpr TrajectoryPointFlags(HitIndex_t fromHit, Flags... flags)
404  */
405  using trkflag = recob::TrajectoryPointFlags::flag;
406  constexpr recob::TrajectoryPointFlags flags [[gnu::unused]](
408  trkflag::NoPoint,
409  trkflag::Merged
410  );
411 
412 } // TrajectoryPointFlagsDocumentationTest_TrajectoryPointFlags_HitIndex_t_Flags
TrajectoryPointFlagTraits flag
Type of flag traits (indices and meaning of flags).
static constexpr HitIndex_t InvalidHitIndex
Value marking an invalid hit index.
Set of flags pertaining a point of the track.
void TrajectoryPointFlagsTest_BitmaskConstructor ( )

Definition at line 301 of file TrajectoryPointFlags_test.cc.

301  {
302 
303  using trkflag = recob::TrajectoryPointFlags::flag;
304 
306 
307  constexpr auto flagbitmask = recob::TrajectoryPointFlags::makeMask(
308  trkflag::NoPoint, trkflag::Rejected,
309  util::flags::Unset(trkflag::HitIgnored)
310  );
311 
312  std::set<util::flags::Index_t> expectedSet;
313  expectedSet.insert(trkflag::NoPoint.index());
314  expectedSet.insert(trkflag::Rejected.index());
315  std::set<util::flags::Index_t> expectedDefined = expectedSet;
316  expectedDefined.insert(trkflag::HitIgnored.index());
317 
318  std::set<Flag_t> const expectedValues(expectedSet.begin(), expectedSet.end());
319  std::set<Flag_t> const expectedFlags
320  (expectedDefined.begin(), expectedDefined.end());
321 
322  /*
323  * constexpr TrajectoryPointFlags(FromMaskTag_t, HitIndex_t, Mask_t)
324  */
325  constexpr recob::TrajectoryPointFlags flags(12, flagbitmask);
326 
327  BOOST_TEST(flags == recob::TrajectoryPointFlags(12,
328  trkflag::NoPoint + trkflag::Rejected + -trkflag::HitIgnored));
329 /*
330  static_assert(flags == recob::TrajectoryPointFlags(12,
331  trkflag::NoPoint + trkflag::Rejected + -trkflag::HitIgnored),
332  "Constexpr declaration with mask failed.");
333  */
334 
335  /*
336  * void dump(...) const;
337  */
338  for (unsigned int level = 0; level < 2; ++level) {
339  std::cout << "Bitmask-constructed flags, dump(verbosity=" << level << "):"
340  << std::endl;
341  flags.dump(std::cout, level, " ");
342  std::cout << "\n" << std::endl;
343  } // for
344 
345 
346  BOOST_TEST_MESSAGE("Flag check for bitmask-constructed object");
347  CheckFlagsByIndex(flags, expectedDefined, expectedSet);
348 
349 
350  /*
351  * Mask_t mask() const
352  */
353  BOOST_TEST(flags.mask() == flagbitmask);
354 
355  /*
356  * bool isHitIgnored() const
357  */
358  BOOST_TEST
359  (flags.isHitIgnored() == (expectedValues.count(trkflag::HitIgnored) > 0));
360 
361  /*
362  * bool isPointValid() const
363  */
364  BOOST_TEST
365  (flags.isPointValid() == (expectedValues.count(trkflag::NoPoint) == 0));
366 
367  /*
368  * hasOriginalHitIndex() const
369  */
370  BOOST_TEST(flags.hasOriginalHitIndex());
371 
372  /*
373  * HitIndex_t fromHit() const
374  */
375  BOOST_TEST(flags.fromHit() == 12U);
376 
377 
378 } // TrajectoryPointFlagsTest_BitmaskConstructor()
TrajectoryPointFlagTraits flag
Type of flag traits (indices and meaning of flags).
static constexpr Mask_t makeMask(Flags...flags)
Returns a bit mask with only the specified bit set.
Flags_t::Flag_t Flag_t
Type of single flag.
void CheckFlagsByIndex(recob::TrajectoryPointFlags const &flags, std::set< util::flags::Index_t > const &expectedDefined, std::set< util::flags::Index_t > const &expectedSet)
Set of flags pertaining a point of the track.
constexpr BitMask< Storage > Unset(Flag_t< Storage > flag)
Returns a bit mask which unsets the specified flag.
QTextStream & endl(QTextStream &s)
void TrajectoryPointFlagsTest_DefaultConstructor ( )

Definition at line 123 of file TrajectoryPointFlags_test.cc.

123  {
124 
125  constexpr auto InvalidHitIndex = recob::TrajectoryPointFlags::InvalidHitIndex;
126 
127  /*
128  * constexpr TrajectoryPointFlags()
129  */
130  constexpr recob::TrajectoryPointFlags flags;
131 
132  // we build our expectation based on the following mask:
133  constexpr auto expectedMask = recob::TrajectoryPointFlags::DefaultFlagsMask();
134  std::set<util::flags::Index_t> expectedDefined, expectedSet;
135  for (unsigned int i = 0; i < expectedMask.capacity(); ++i) {
136  if (expectedMask.isUndefined(i)) continue;
137  expectedDefined.insert(i);
138  if (expectedMask.isSet(i)) expectedSet.insert(i);
139  } // for
140 
141  /*
142  * void dump(...) const;
143  */
144  for (unsigned int level = 0; level < 2; ++level) {
145  std::cout << "Default-constructed flags, dump(verbosity=" << level << "):"
146  << std::endl;
147  flags.dump(std::cout, level, " ");
148  std::cout << "\n" << std::endl;
149  } // for
150 
151 
152  BOOST_TEST_MESSAGE("Flag check for default constructed object");
153  CheckFlagsByIndex(flags, expectedDefined, expectedSet);
154 
155  /*
156  * Mask_t mask() const
157  */
158  BOOST_TEST
160 
161  /*
162  * bool isHitIgnored() const
163  */
164  BOOST_TEST(!flags.isHitIgnored());
165 
166  /*
167  * bool isPointValid() const
168  */
169  BOOST_TEST(flags.isPointValid());
170 
171  /*
172  * bool isMerged() const
173  */
174  BOOST_TEST(!flags.isMerged());
175 
176  /*
177  * bool isShared() const
178  */
179  BOOST_TEST(!flags.isShared());
180 
181  /*
182  * bool isDeltaRay() const
183  */
184  BOOST_TEST(!flags.isDeltaRay());
185 
186  /*
187  * bool hasDetectorIssues() const
188  */
189  BOOST_TEST(!flags.hasDetectorIssues());
190 
191  /*
192  * bool isOtherwiseSuspicious() const
193  */
194  BOOST_TEST(!flags.isOtherwiseSuspicious());
195 
196  /*
197  * bool isExclusive() const
198  */
199  BOOST_TEST(flags.isExclusive());
200 
201  /*
202  * bool isExcludedFromFit() const
203  */
204  BOOST_TEST(!flags.isExcludedFromFit());
205 
206  /*
207  * bool belongsToTrack() const
208  */
209  BOOST_TEST(flags.belongsToTrack());
210 
211  /*
212  * bool isHitReinterpreted() const
213  */
214  BOOST_TEST(!flags.isHitReinterpreted());
215 
216  /*
217  * bool isIncludedInFit() const
218  */
219  BOOST_TEST(flags.isIncludedInFit());
220 
221  /*
222  * bool isPointFlawed() const
223  */
224  BOOST_TEST(!flags.isPointFlawed());
225 
226  /*
227  * bool isPointFlawless() const
228  */
229  BOOST_TEST(flags.isPointFlawless());
230 
231  /*
232  * hasOriginalHitIndex() const
233  */
234  BOOST_TEST(!flags.hasOriginalHitIndex());
235 
236  /*
237  * HitIndex_t fromHit() const
238  */
239  BOOST_TEST(flags.fromHit() == InvalidHitIndex);
240 
241 } // TrajectoryPointFlagsTest_DefaultConstructor()
static constexpr Mask_t DefaultFlagsMask()
Flags used in default construction.
static constexpr HitIndex_t InvalidHitIndex
Value marking an invalid hit index.
void CheckFlagsByIndex(recob::TrajectoryPointFlags const &flags, std::set< util::flags::Index_t > const &expectedDefined, std::set< util::flags::Index_t > const &expectedSet)
Set of flags pertaining a point of the track.
QTextStream & endl(QTextStream &s)
void TrajectoryPointFlagsTest_FlagsConstructor ( )

Definition at line 245 of file TrajectoryPointFlags_test.cc.

245  {
246 
247  using trkflag = recob::TrajectoryPointFlags::flag;
248  constexpr auto InvalidHitIndex = recob::TrajectoryPointFlags::InvalidHitIndex;
249 
250  std::set<recob::TrajectoryPointFlags::Flag_t> const expectedBits
251  = { trkflag::NoPoint, trkflag::HitIgnored };
252 
253  constexpr auto flagbitmask = recob::TrajectoryPointFlags::makeMask
254  (trkflag::NoPoint, trkflag::HitIgnored);
255 
256  /*
257  * constexpr TrajectoryPointFlags(HitIndex_t fromHit, Flags... flags)
258  */
259  constexpr recob::TrajectoryPointFlags flags
260  (InvalidHitIndex, trkflag::NoPoint, trkflag::HitIgnored);
261 
262  std::set<util::flags::Index_t> expectedDefined;
263  expectedDefined.insert(trkflag::NoPoint.index());
264  expectedDefined.insert(trkflag::HitIgnored.index());
265  std::set<util::flags::Index_t> expectedSet = expectedDefined;
266 
267  /*
268  * void dump(...) const;
269  */
270  for (unsigned int level = 0; level < 2; ++level) {
271  std::cout << "Flag-constructed flags, dump(verbosity=" << level << "):"
272  << std::endl;
273  flags.dump(std::cout, level, " ");
274  std::cout << "\n" << std::endl;
275  } // for
276 
277  BOOST_TEST_MESSAGE("Flag check for flag-constructed object");
278  CheckFlagsByIndex(flags, expectedDefined, expectedSet);
279 
280 
281  /*
282  * Mask_t mask() const
283  */
284  BOOST_TEST(flags.mask() == flagbitmask);
285 
286  /*
287  * hasOriginalHitIndex() const
288  */
289  BOOST_TEST(!flags.hasOriginalHitIndex());
290 
291  /*
292  * HitIndex_t fromHit() const
293  */
294  BOOST_TEST(flags.fromHit() == InvalidHitIndex);
295 
296 
297 } // TrajectoryPointFlagsTest_FlagsConstructor()
TrajectoryPointFlagTraits flag
Type of flag traits (indices and meaning of flags).
static constexpr Mask_t makeMask(Flags...flags)
Returns a bit mask with only the specified bit set.
static constexpr HitIndex_t InvalidHitIndex
Value marking an invalid hit index.
void CheckFlagsByIndex(recob::TrajectoryPointFlags const &flags, std::set< util::flags::Index_t > const &expectedDefined, std::set< util::flags::Index_t > const &expectedSet)
Set of flags pertaining a point of the track.
QTextStream & endl(QTextStream &s)