energy_test.cc
Go to the documentation of this file.
1 /**
2  * @file test/Utilities/energy_test.cc
3  * @brief Unit test for `lardataalg/Utilities/quantities/energy.h` header.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date January 10, 2020
6  * @see `lardataalg/Utilities/quantities.h`
7  *
8  */
9 
10 // Boost libraries
11 #define BOOST_TEST_MODULE ( energy_test )
12 #include <boost/test/unit_test.hpp>
13 
14 // LArSoft libraries
16 
17 // C/C++ standard libraries
18 #include <iostream>
19 #include <type_traits> // std::decay_t<>
20 
21 
22 // -----------------------------------------------------------------------------
24 
25  using namespace util::quantities::energy_literals;
26 
27  //
28  // NOTE: the test with physics constants is cool, but floating point
29  // arithmetics having finite precision, static tests based on equality
30  // may fail... if that happens, my magic recipe is... use less digits.
31  // Wow.
32  //
33 
34  constexpr auto E_eV = 13.6_eV; // hydrogen binding energy
35  static_assert
36  (std::is_same<decltype(E_eV), util::quantities::electronvolt const>());
37  static_assert(E_eV.value() == 13.6);
38  static_assert(E_eV == 13.6_eV);
39  std::cout << "Tested " << E_eV << std::endl;
40 
41  constexpr auto E_meV = 34.8_meV; // room temperature (300 K)
42  static_assert
43  (std::is_same<decltype(E_meV), util::quantities::millielectronvolt const>());
44  static_assert(E_meV == 34.8_meV);
45  static_assert(E_meV.value() == 34.8);
46  static_assert(E_meV == 0.0348_eV);
47  std::cout << "Tested " << E_meV << std::endl;
48 
49  constexpr auto E_ueV = 662.6_ueV; // CMB temperature
50  static_assert
51  (std::is_same<decltype(E_ueV), util::quantities::microelectronvolt const>());
52  static_assert(E_ueV == 662.6_ueV);
53  static_assert(E_ueV.value() == 662.6);
54  static_assert(E_ueV == 0.6626_meV);
55  std::cout << "Tested " << E_ueV << std::endl;
56 
57  constexpr auto E_keV = 510.99893_keV; // electron mass
58  static_assert
59  (std::is_same<decltype(E_keV), util::quantities::kiloelectronvolt const>());
60  static_assert(E_keV == 510.99893_keV);
61  static_assert(E_keV.value() == 510.99893);
62  static_assert(E_keV == 0.51099893_MeV);
63  std::cout << "Tested " << E_keV << std::endl;
64 
65  constexpr auto E_MeV = 2.22452_MeV; // deuteron binding energy
66  static_assert
67  (std::is_same<decltype(E_MeV), util::quantities::megaelectronvolt const>());
68  static_assert(E_MeV == 2.22452_MeV);
69  static_assert(E_MeV.value() == 2.22452);
70  static_assert(E_MeV == 2224.52_keV);
71  std::cout << "Tested " << E_MeV << std::endl;
72 
73  constexpr auto E_GeV = 91.1876_GeV; // Z boson mass
74  static_assert
75  (std::is_same<decltype(E_GeV), util::quantities::gigaelectronvolt const>());
76  static_assert(E_GeV == 91.1876_GeV);
77  static_assert(E_GeV.value() == 91.1876);
78  static_assert(E_GeV == 91187.6_MeV);
79  std::cout << "Tested " << E_GeV << std::endl;
80 
81  constexpr auto E_TeV = 0.980_TeV; // Tevatron beam energy
82  static_assert
83  (std::is_same<decltype(E_TeV), util::quantities::teraelectronvolt const>());
84  static_assert(E_TeV == 0.980_TeV);
85  static_assert(E_TeV.value() == 0.980);
86  static_assert(E_TeV == 980_GeV);
87  std::cout << "Tested " << E_TeV << std::endl;
88 
89 } // test_electronvolt_literals()
90 
91 
92 // -----------------------------------------------------------------------------
93 // BEGIN Test cases -----------------------------------------------------------
94 // -----------------------------------------------------------------------------
95 BOOST_AUTO_TEST_CASE(electronvolt_testcase) {
96 
98 
99 } // BOOST_AUTO_TEST_CASE(electronvolt_testcase)
100 
101 
102 // -----------------------------------------------------------------------------
103 // END Test cases -------------------------------------------------------------
104 // -----------------------------------------------------------------------------
Literal constants for energy quantities.
Definition: energy.h:162
A value measured in the specified unit.
Definition: quantities.h:566
Dimensioned variables representing energy.
G4double E_eV[100]
Definition: G4S2Light.cc:60
QTextStream & endl(QTextStream &s)
BOOST_AUTO_TEST_CASE(electronvolt_testcase)
Definition: energy_test.cc:95
void test_electronvolt_literals()
Definition: energy_test.cc:23