All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
space_test.cc
Go to the documentation of this file.
1 /**
2  * @file test/Utilities/space_test.cc
3  * @brief Unit test for `lardataalg/Utilities/quantities/spacetime.h` header.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date January 13, 2020
6  * @see `lardataalg/Utilities/quantities.h`
7  *
8  * This test covers only the space units of `spacetime.h`.
9  * It's not overwhelmingly complete, either.
10  */
11 
12 // Boost libraries
13 #define BOOST_TEST_MODULE ( space_test )
14 #include <boost/test/unit_test.hpp>
15 
16 // LArSoft libraries
18 
19 // C/C++ standard libraries
20 #include <iostream>
21 #include <type_traits> // std::decay_t<>
22 
23 
24 // -----------------------------------------------------------------------------
26 
27  using namespace util::quantities::space_literals;
28 
29  //
30  // NOTE: the test with physics constants is cool, but floating point
31  // arithmetics having finite precision, static tests based on equality
32  // may fail... if that happens, my magic recipe is... use less digits.
33  // Wow.
34  //
35 
36  constexpr auto l_m = 299792458_m; // space covered by a photon in vacuum in 1"
37  static_assert
38  (std::is_same<decltype(l_m), util::quantities::meter const>());
39  static_assert(l_m.value() == 299792458);
40  static_assert(l_m == 299792458_m);
41  std::cout << "Tested " << l_m << std::endl;
42 
43  constexpr auto l_km = 299792.458_km;
44  static_assert
45  (std::is_same<decltype(l_km), util::quantities::kilometer const>());
46  static_assert(l_km == 299792.458_km);
47  static_assert(l_km.value() == 299792.458);
48  static_assert(l_km == 299792458_m);
49  std::cout << "Tested " << l_km << std::endl;
50 
51  constexpr auto l_cm = 29979245800_cm;
52  static_assert(std::is_same<decltype
53  (l_cm), util::quantities::centimeter const>());
54  static_assert(l_cm == 29979245800_cm);
55  static_assert(l_cm.value() == 29979245800);
56  static_assert(l_cm == 299792458_m);
57  std::cout << "Tested " << l_cm << std::endl;
58 
59  constexpr auto l_mm = 299792458000_mm;
60  static_assert
61  (std::is_same<decltype(l_mm), util::quantities::millimeter const>());
62  static_assert(l_mm == 299792458000_mm);
63  static_assert(l_mm.value() == 299792458000);
64  static_assert(l_mm == 299792458_m);
65  std::cout << "Tested " << l_mm << std::endl;
66 
67  constexpr auto l_um = 1063_um; // dE/dl peak of CMB according to Wikipedia
68  static_assert
69  (std::is_same<decltype(l_um), util::quantities::micrometer const>());
70  static_assert(l_um == 1063_um);
71  static_assert(l_um.value() == 1063);
72  static_assert(l_um == 1.063_mm);
73  std::cout << "Tested " << l_um << std::endl;
74 
75  constexpr auto l_nm = 1063000_nm;
76  static_assert
77  (std::is_same<decltype(l_nm), util::quantities::nanometer const>());
78  static_assert(l_nm == 1063000_nm);
79  static_assert(l_nm.value() == 1063000);
80  static_assert(l_nm == 1063_um);
81  std::cout << "Tested " << l_nm << std::endl;
82 
83  constexpr auto l_pm = 1063000000_pm;
84  static_assert
85  (std::is_same<decltype(l_pm), util::quantities::picometer const>());
86  static_assert(l_pm == 1063000000_pm);
87  static_assert(l_pm.value() == 1063000000);
88  static_assert(l_pm == 1063000_nm);
89  std::cout << "Tested " << l_pm << std::endl;
90 
91  constexpr auto l_fm = 52918_fm; // Bohr radius (rounded)
92  static_assert
93  (std::is_same<decltype(l_fm), util::quantities::femtometer const>());
94  static_assert(l_fm == 52918_fm);
95  static_assert(l_fm.value() == 52918);
96  static_assert(l_fm == 52.918_pm);
97  std::cout << "Tested " << l_fm << std::endl;
98 
99 } // test_meter_literals()
100 
101 
102 // -----------------------------------------------------------------------------
103 // BEGIN Test cases -----------------------------------------------------------
104 // -----------------------------------------------------------------------------
105 BOOST_AUTO_TEST_CASE(meter_testcase) {
106 
108 
109 } // BOOST_AUTO_TEST_CASE(meter_testcase)
110 
111 
112 // -----------------------------------------------------------------------------
113 // END Test cases -------------------------------------------------------------
114 // -----------------------------------------------------------------------------
BOOST_AUTO_TEST_CASE(AllTests)
void test_meter_literals()
Definition: space_test.cc:25
A value measured in the specified unit.
Definition: quantities.h:566
Dimensioned variables representing space or time quantities.
BEGIN_PROLOG could also be cout