Macros | Functions
energy_test.cc File Reference

Unit test for lardataalg/Utilities/quantities/energy.h header. More...

#include <boost/test/unit_test.hpp>
#include "lardataalg/Utilities/quantities/energy.h"
#include <iostream>
#include <type_traits>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   ( energy_test )
 

Functions

void test_electronvolt_literals ()
 
 BOOST_AUTO_TEST_CASE (electronvolt_testcase)
 

Detailed Description

Unit test for lardataalg/Utilities/quantities/energy.h header.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.slac..nosp@m.stan.nosp@m.ford..nosp@m.edu)
Date
January 10, 2020
See also
lardataalg/Utilities/quantities.h

Definition in file energy_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( energy_test )

Definition at line 11 of file energy_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( electronvolt_testcase  )

Definition at line 95 of file energy_test.cc.

95  {
96 
98 
99 } // BOOST_AUTO_TEST_CASE(electronvolt_testcase)
void test_electronvolt_literals()
Definition: energy_test.cc:23
void test_electronvolt_literals ( )

Definition at line 23 of file energy_test.cc.

23  {
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()
Literal constants for energy quantities.
Definition: energy.h:162
A value measured in the specified unit.
Definition: quantities.h:566
G4double E_eV[100]
Definition: G4S2Light.cc:60
QTextStream & endl(QTextStream &s)