Classes | Macros | Functions
intervals_test.cc File Reference

Unit test for intervals.h header. More...

#include <boost/test/unit_test.hpp>
#include "lardataalg/Utilities/intervals.h"
#include "lardataalg/Utilities/quantities/spacetime.h"
#include "larcorealg/CoreUtils/DebugUtils.h"
#include "test/Utilities/disable_boost_fpc_tolerance.hpp"
#include <type_traits>

Go to the source code of this file.

Classes

struct  ObjectWithoutCategory
 
struct  ObjectWithCategory
 

Macros

#define BOOST_TEST_MODULE   ( intervals_test )
 

Functions

void test_interval_construction ()
 
void test_interval_comparisons ()
 
void test_interval_queries ()
 
void test_interval_operations ()
 
void test_point_construction ()
 
void test_point_comparisons ()
 
void test_point_queries ()
 
void test_point_operations ()
 
 BOOST_AUTO_TEST_CASE (intervals_testcase)
 
 BOOST_AUTO_TEST_CASE (points_testcase)
 

Detailed Description

Unit test for intervals.h header.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.slac..nosp@m.stan.nosp@m.ford..nosp@m.edu)
Date
May 29, 2019
See also
lardataalg/Utilities/intervals.h

Definition in file intervals_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( intervals_test )

Definition at line 11 of file intervals_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( intervals_testcase  )

Definition at line 601 of file intervals_test.cc.

601  {
602 
607 
608 } // BOOST_AUTO_TEST_CASE(intervals_testcase)
void test_interval_construction()
void test_interval_operations()
void test_interval_queries()
void test_interval_comparisons()
BOOST_AUTO_TEST_CASE ( points_testcase  )

Definition at line 611 of file intervals_test.cc.

611  {
612 
617 
618 } // BOOST_AUTO_TEST_CASE(points_testcase)
void test_point_comparisons()
void test_point_operations()
void test_point_construction()
void test_point_queries()
void test_interval_comparisons ( )

Definition at line 195 of file intervals_test.cc.

195  {
196 
197  using namespace util::quantities::time_literals;
200 
201  constexpr microseconds t1 { +6.0_us };
202  constexpr nanoseconds t2 { -4'000'000.0_ps };
203 
204  constexpr microseconds t1s = t1;
205 
206  static_assert( t1 == 6_us );
207  static_assert( t1 == 6000_ns );
208  static_assert( 6_us == t1 );
209  static_assert( 6000_ns == t1 );
210  static_assert( t1 == t1s );
211  static_assert(!(t1 == 5_us ));
212  static_assert(!(t1 == 5_ns ));
213  static_assert(!(5_us == t1 ));
214  static_assert(!(5_ns == t1 ));
215  static_assert(!(t1 == t2 ));
216 
217  static_assert(!(t1 != 6_us ));
218  static_assert(!(t1 != 6000_ns));
219  static_assert(!(6_us != t1 ));
220  static_assert(!(6000_ns != t1 ));
221  static_assert(!(t1 != t1s ));
222  static_assert( t1 != 5_us );
223  static_assert( t1 != 5_ns );
224  static_assert( 5_us != t1 );
225  static_assert( 5_ns != t1 );
226  static_assert( t1 != t2 );
227 
228  static_assert( t1 >= 6_us );
229  static_assert( t1 >= 6000_ns );
230  static_assert( 6_us >= t1 );
231  static_assert( 6000_ns >= t1 );
232  static_assert( t1 >= t1s );
233  static_assert( t1 >= 5_us );
234  static_assert( t1 >= 5000_ns );
235  static_assert(!(5_us >= t1 ));
236  static_assert(!(5000_ns >= t1 ));
237  static_assert(!(t1 >= 8_us ));
238  static_assert(!(t1 >= 8000_ns));
239  static_assert( 8_us >= t1 );
240  static_assert( 8000_ns >= t1 );
241  static_assert( t1 >= t2 );
242 
243  static_assert(!(t1 > 6_us ));
244  static_assert(!(t1 > 6000_ns));
245  static_assert(!(6_us > t1 ));
246  static_assert(!(6000_ns > t1 ));
247  static_assert(!(t1 > t1s ));
248  static_assert( t1 > 5_us );
249  static_assert( t1 > 5000_ns );
250  static_assert(!(5_us > t1 ));
251  static_assert(!(5000_ns > t1 ));
252  static_assert(!(t1 > 8_us ));
253  static_assert(!(t1 > 8000_ns));
254  static_assert( 8_us > t1 );
255  static_assert( 8000_ns > t1 );
256  static_assert( t1 > t2 );
257 
258  static_assert( t1 <= 6_us );
259  static_assert( t1 <= 6000_ns );
260  static_assert( 6000_ns <= t1 );
261  static_assert( t1 <= t1s );
262  static_assert(!(t1 <= 5_us ));
263  static_assert(!(t1 <= 5000_ns));
264  static_assert( 5_us <= t1 );
265  static_assert( 5000_ns <= t1 );
266  static_assert( t1 <= 8_us );
267  static_assert( t1 <= 8000_ns );
268  static_assert(!(8_us <= t1 ));
269  static_assert(!(8000_ns <= t1 ));
270  static_assert(!(t1 <= t2 ));
271 
272  static_assert(!(t1 < 6_us ));
273  static_assert(!(t1 < 6000_ns));
274  static_assert(!(6_us < t1 ));
275  static_assert(!(6000_ns < t1 ));
276  static_assert(!(t1 < t1s ));
277  static_assert(!(t1 < 5_us ));
278  static_assert(!(t1 < 5000_ns));
279  static_assert( 5_us < t1 );
280  static_assert( 5000_ns < t1 );
281  static_assert( t1 < 8_us );
282  static_assert( t1 < 8000_ns );
283  static_assert(!(8_us < t1 ));
284  static_assert(!(8000_ns < t1 ));
285  static_assert(!(t1 < t2 ));
286 
287 } // test_interval_comparisons()
microseconds_as<> microseconds
Type of time interval stored in microseconds, in double precision.
Definition: spacetime.h:259
microsecond microseconds
Alias for common language habits.
Definition: spacetime.h:122
Literal constants for time quantities.
Definition: spacetime.h:175
nanoseconds_as<> nanoseconds
Type of time interval stored in nanoseconds, in double precision.
Definition: spacetime.h:270
nanosecond nanoseconds
Alias for common language habits.
Definition: spacetime.h:139
void test_interval_construction ( )

Definition at line 172 of file intervals_test.cc.

172  {
173 
174  using namespace util::quantities::time_literals;
175 
178 
179  microseconds ct0; // can't be constant since it's uninitialized
180  (void) ct0; // don't let this fall unused
181 
182  constexpr microseconds ct1 { 2.0 };
183  static_assert(ct1.value() == 2.0);
184 
185  constexpr microseconds ct2 { +6.0_us };
186  static_assert(ct2.value() == 6.0);
187 
188  constexpr microseconds ct3 { -4000.0_ns };
189  static_assert(ct3.value() == -4.0);
190 
191 } // void test_interval_construction()
microseconds_as<> microseconds
Type of time interval stored in microseconds, in double precision.
Definition: spacetime.h:259
microsecond microseconds
Alias for common language habits.
Definition: spacetime.h:122
Literal constants for time quantities.
Definition: spacetime.h:175
nanoseconds_as<> nanoseconds
Type of time interval stored in nanoseconds, in double precision.
Definition: spacetime.h:270
void test_interval_operations ( )

Definition at line 312 of file intervals_test.cc.

312  {
313 
314  using namespace util::quantities::time_literals;
315 
318 
319  constexpr microseconds ct1 { +6.0_us };
320  constexpr microseconds ct2 { -4000.0_ns };
321 
322  static_assert_type<microseconds>{ct1 + -4000.0_ns};
323  static_assert(ct1 + -4000.0_ns == 2_us);
324 
325  static_assert_type<microseconds>{ct1 + ct2};
326  static_assert(ct1 + ct2 == 2_us);
327 
328  static_assert_type<microseconds>{ct1 - -4000.0_ns};
329  static_assert(ct1 - -4000.0_ns == 10_us);
330 
331  static_assert_type<microseconds>{ct1 - ct2};
332  static_assert(ct1 - ct2 == 10_us);
333 
334  static_assert_type<microseconds>{+ct1};
335  static_assert(+ct1 == 6_us);
336 
337  static_assert_type<microseconds>{-ct1};
338  static_assert(-ct1 == -6_us);
339 
340  static_assert_type<microseconds>{ct1.abs()};
341  static_assert(ct1.abs() == 6_us);
342  static_assert(ct2.abs() == 4_us);
343 
344  static_assert_type<microseconds>{ct1 * 3.0};
345  static_assert(ct1 * 3.0 == 6_us * 3.0);
346 
347  static_assert_type<microseconds>{3.0 * ct1};
348  static_assert(3.0 * ct1 == 6_us * 3.0);
349 
350  static_assert_type<microseconds>{ct1 / 2.0};
351  static_assert(ct1 / 2.0 == 6_us / 2.0);
352 
353  microseconds t1 { +6.0_us };
354  nanoseconds const t2 { -4000.0_ns };
355 
356  decltype(auto) incr = (t1 += 2000_ns);
357  static_assert_type<microseconds&>{incr};
358  BOOST_TEST(t1 == 8_us);
359  BOOST_TEST(&incr == &t1);
360 
361  decltype(auto) incr2 = (t1 += t2);
362  static_assert_type<microseconds&>{incr2};
363  BOOST_TEST(t1 == 4_us);
364  BOOST_TEST(t2 == -4_us);
365  BOOST_TEST(&incr2 == &t1);
366 
367  decltype(auto) decr = (t1 -= 2000_ns);
368  static_assert_type<microseconds&>{decr};
369  BOOST_TEST(t1 == 2_us);
370  BOOST_TEST(&decr == &t1);
371 
372  decltype(auto) decr2 = (t1 -= t2);
373  static_assert_type<microseconds&>{decr2};
374  BOOST_TEST(t1 == 6_us);
375  BOOST_TEST(t2 == -4_us);
376  BOOST_TEST(&decr2 == &t1);
377 
378  decltype(auto) expand = (t1 *= 2);
379  static_assert_type<microseconds&>{expand};
380  BOOST_TEST(t1 == 12_us);
381  BOOST_TEST(&expand == &t1);
382 
383  decltype(auto) shrink = (t1 /= 2);
384  static_assert_type<microseconds&>{shrink};
385  BOOST_TEST(t1 == 6_us);
386  BOOST_TEST(&shrink == &t1);
387 
388 } // test_interval_operations()
microseconds_as<> microseconds
Type of time interval stored in microseconds, in double precision.
Definition: spacetime.h:259
microsecond microseconds
Alias for common language habits.
Definition: spacetime.h:122
Literal constants for time quantities.
Definition: spacetime.h:175
nanoseconds_as<> nanoseconds
Type of time interval stored in nanoseconds, in double precision.
Definition: spacetime.h:270
nanosecond nanoseconds
Alias for common language habits.
Definition: spacetime.h:139
void test_interval_queries ( )

Definition at line 291 of file intervals_test.cc.

291  {
292 
293  using namespace util::quantities::time_literals;
294 
297 
298  constexpr microseconds t1 { +6.0_us };
299  constexpr nanoseconds t2 { -4'000'000.0_ps };
300 
301  static_assert(std::is_same_v<microseconds::quantity_t, util::quantities::microsecond>);
302  static_assert(std::is_same_v<microseconds::unit_t, util::quantities::microsecond::unit_t>);
303 
304  static_assert(t1.quantity() == 6_us );
305  static_assert(t2.quantity() == -4_us );
306  static_assert(t1.value() == 6.0 );
307  static_assert(t2.value() == -4000.0 );
308 
309 } // test_interval_queries()
microseconds_as<> microseconds
Type of time interval stored in microseconds, in double precision.
Definition: spacetime.h:259
microsecond microseconds
Alias for common language habits.
Definition: spacetime.h:122
Literal constants for time quantities.
Definition: spacetime.h:175
nanoseconds_as<> nanoseconds
Type of time interval stored in nanoseconds, in double precision.
Definition: spacetime.h:270
nanosecond nanoseconds
Alias for common language habits.
Definition: spacetime.h:139
void test_point_comparisons ( )

Definition at line 417 of file intervals_test.cc.

417  {
418  using namespace util::quantities::time_literals;
421 
422  constexpr microsecond const t1 { +6.0_us };
423  constexpr nanosecond const t2 { -4'000'000.0_ps };
424 
425  constexpr microsecond const t1s = t1;
426 
427  static_assert( t1 == 6_us );
428  static_assert( t1 == 6000_ns );
429  static_assert( 6_us == t1 );
430  static_assert( 6000_ns == t1 );
431  static_assert( t1 == t1s );
432  static_assert(!(t1 == 5_us ));
433  static_assert(!(t1 == 5_ns ));
434  static_assert(!(5_us == t1 ));
435  static_assert(!(5_ns == t1 ));
436  static_assert(!(t1 == t2 ));
437 
438  static_assert(!(t1 != 6_us ));
439  static_assert(!(t1 != 6000_ns));
440  static_assert(!(6_us != t1 ));
441  static_assert(!(6000_ns != t1 ));
442  static_assert(!(t1 != t1s ));
443  static_assert( t1 != 5_us );
444  static_assert( t1 != 5_ns );
445  static_assert( 5_us != t1 );
446  static_assert( 5_ns != t1 );
447  static_assert( t1 != t2 );
448 
449  static_assert( t1 >= 6_us );
450  static_assert( t1 >= 6000_ns );
451  static_assert( 6_us >= t1 );
452  static_assert( 6000_ns >= t1 );
453  static_assert( t1 >= t1s );
454  static_assert( t1 >= 5_us );
455  static_assert( t1 >= 5000_ns );
456  static_assert(!(5_us >= t1 ));
457  static_assert(!(5000_ns >= t1 ));
458  static_assert(!(t1 >= 8_us ));
459  static_assert(!(t1 >= 8000_ns));
460  static_assert( 8_us >= t1 );
461  static_assert( 8000_ns >= t1 );
462  static_assert( t1 >= t2 );
463 
464  static_assert(!(t1 > 6_us ));
465  static_assert(!(t1 > 6000_ns));
466  static_assert(!(6_us > t1 ));
467  static_assert(!(6000_ns > t1 ));
468  static_assert(!(t1 > t1s ));
469  static_assert( t1 > 5_us );
470  static_assert( t1 > 5000_ns );
471  static_assert(!(5_us > t1 ));
472  static_assert(!(5000_ns > t1 ));
473  static_assert(!(t1 > 8_us ));
474  static_assert(!(t1 > 8000_ns));
475  static_assert( 8_us > t1 );
476  static_assert( 8000_ns > t1 );
477  static_assert( t1 > t2 );
478 
479  static_assert( t1 <= 6_us );
480  static_assert( t1 <= 6000_ns );
481  static_assert( 6_us <= t1 );
482  static_assert( 6000_ns <= t1 );
483  static_assert( t1 <= t1s );
484  static_assert(!(t1 <= 5_us ));
485  static_assert(!(t1 <= 5000_ns));
486  static_assert( 5_us <= t1 );
487  static_assert( 5000_ns <= t1 );
488  static_assert( t1 <= 8_us );
489  static_assert( t1 <= 8000_ns );
490  static_assert(!(8_us <= t1 ));
491  static_assert(!(8000_ns <= t1 ));
492  static_assert(!(t1 <= t2 ));
493 
494  static_assert(!(t1 < 6_us ));
495  static_assert(!(t1 < 6000_ns));
496  static_assert(!(6_us < t1 ));
497  static_assert(!(6000_ns < t1 ));
498  static_assert(!(t1 < t1s ));
499  static_assert(!(t1 < 5_us ));
500  static_assert(!(t1 < 5000_ns));
501  static_assert( 5_us < t1 );
502  static_assert( 5000_ns < t1 );
503  static_assert( t1 < 8_us );
504  static_assert( t1 < 8000_ns );
505  static_assert(!(8_us < t1 ));
506  static_assert(!(8000_ns < t1 ));
507  static_assert(!(t1 < t2 ));
508 
509 } // test_point_comparisons()
microsecond_as<> microsecond
Type of time stored in microseconds, in double precision.
Definition: spacetime.h:119
microsecond_as<> microsecond
Type of time point stored in microseconds, in double precision.
Definition: spacetime.h:328
Literal constants for time quantities.
Definition: spacetime.h:175
nanosecond_as<> nanosecond
Type of time stored in nanoseconds, in double precision.
Definition: spacetime.h:136
nanosecond_as<> nanosecond
Type of time point stored in nanoseconds, in double precision.
Definition: spacetime.h:339
void test_point_construction ( )

Definition at line 394 of file intervals_test.cc.

394  {
395 
396  using namespace util::quantities::time_literals;
397 
400 
401  microsecond ct0;
402  (void) ct0; // don't let this fall unused
403 
404  constexpr microsecond ct1 { 2.0 };
405  static_assert(ct1.value() == 2.0);
406 
407  constexpr microsecond ct2 { +6.0_us };
408  static_assert(ct2.value() == 6.0);
409 
410  constexpr microsecond ct3 { -4000.0_ns };
411  static_assert(ct3.value() == -4.0);
412 
413 } // void test_point_construction()
microsecond_as<> microsecond
Type of time stored in microseconds, in double precision.
Definition: spacetime.h:119
microsecond_as<> microsecond
Type of time point stored in microseconds, in double precision.
Definition: spacetime.h:328
Literal constants for time quantities.
Definition: spacetime.h:175
nanosecond_as<> nanosecond
Type of time point stored in nanoseconds, in double precision.
Definition: spacetime.h:339
void test_point_operations ( )

Definition at line 535 of file intervals_test.cc.

535  {
536 
537  using namespace util::quantities::time_literals;
538 
541 
542  constexpr microsecond cp1 { +6.0_us };
543  constexpr util::quantities::intervals::microseconds ct { 3.0_us };
544 
545  static_assert_type<microsecond>{cp1 + 3000_ns};
546  static_assert(cp1 + 3000_ns == 9_us);
547 
548  static_assert_type<microsecond>{cp1 + ct};
549  static_assert(cp1 + ct == 9_us);
550 
551  static_assert_type<microsecond>{cp1 - 3000_ns};
552  static_assert(cp1 - 3000_ns == 3_us);
553 
554  static_assert_type<microsecond>{cp1 - ct};
555  static_assert(cp1 - ct == 3_us);
556 
557  static_assert_type<microsecond>{+cp1};
558  static_assert(+cp1 == 6_us);
559 
560  static_assert_type<microsecond>{-cp1};
561  static_assert(-cp1 == -6_us);
562 
563  microsecond p1 { +6.0_us };
564  microsecond p2 { -4000.0_ns };
566 
567  decltype(auto) incr = (p1 += 2000_ns);
568  static_assert_type<microsecond&>{incr};
569  BOOST_TEST(p1 == 8_us);
570  BOOST_TEST(&incr == &p1);
571 
572  decltype(auto) incr2 = (p1 += t);
573  static_assert_type<microsecond&>{incr2};
574  BOOST_TEST(p1 == 11_us);
575  BOOST_TEST(t == 3_us);
576  BOOST_TEST(&incr2 == &p1);
577 
578  decltype(auto) decr = (p1 -= 2000_ns);
579  static_assert_type<microsecond&>{decr};
580  BOOST_TEST(p1 == 9_us);
581  BOOST_TEST(&decr == &p1);
582 
583  decltype(auto) decr2 = (p1 -= t);
584  static_assert_type<microsecond&>{decr2};
585  BOOST_TEST(p1 == 6_us);
586  BOOST_TEST(t == 3_us);
587  BOOST_TEST(&decr2 == &p1);
588 
589  decltype(auto) diff = (p1 - p2);
590  static_assert_type<util::quantities::intervals::microseconds>{diff};
591  BOOST_TEST(p1 == 6_us);
592  BOOST_TEST(p2 == -4_us);
593  BOOST_TEST(diff == 10_us);
594 
595 } // test_point_operations()
Namespace for general, non-LArSoft-specific utilities.
microsecond_as<> microsecond
Type of time stored in microseconds, in double precision.
Definition: spacetime.h:119
microsecond microseconds
Alias for common language habits.
Definition: spacetime.h:122
microsecond_as<> microsecond
Type of time point stored in microseconds, in double precision.
Definition: spacetime.h:328
An interval (duration, length, distance) between two quantity points.
Definition: intervals.h:114
Literal constants for time quantities.
Definition: spacetime.h:175
nanosecond_as<> nanosecond
Type of time point stored in nanoseconds, in double precision.
Definition: spacetime.h:339
void test_point_queries ( )

Definition at line 513 of file intervals_test.cc.

513  {
514 
515  using namespace util::quantities::time_literals;
516 
519 
520  constexpr microsecond t1 { +6.0_us };
521  constexpr nanosecond t2 { -4'000'000.0_ps };
522 
523  static_assert(std::is_same_v<microsecond::quantity_t, util::quantities::microsecond>);
524  static_assert(std::is_same_v<microsecond::unit_t, util::quantities::microsecond::unit_t>);
525 
526  static_assert(t1.quantity() == 6_us );
527  static_assert(t2.quantity() == -4_us );
528  static_assert(t1.value() == 6.0 );
529  static_assert(t2.value() == -4000.0 );
530 
531 } // test_points_queries()
microsecond_as<> microsecond
Type of time stored in microseconds, in double precision.
Definition: spacetime.h:119
microsecond_as<> microsecond
Type of time point stored in microseconds, in double precision.
Definition: spacetime.h:328
Literal constants for time quantities.
Definition: spacetime.h:175
nanosecond_as<> nanosecond
Type of time stored in nanoseconds, in double precision.
Definition: spacetime.h:136
nanosecond_as<> nanosecond
Type of time point stored in nanoseconds, in double precision.
Definition: spacetime.h:339