Macros | Functions
space_test.cc File Reference

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

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

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   ( space_test )
 

Functions

void test_meter_literals ()
 
 BOOST_AUTO_TEST_CASE (meter_testcase)
 

Detailed Description

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

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

This test covers only the space units of spacetime.h. It's not overwhelmingly complete, either.

Definition in file space_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( space_test )

Definition at line 13 of file space_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( meter_testcase  )

Definition at line 105 of file space_test.cc.

105  {
106 
108 
109 } // BOOST_AUTO_TEST_CASE(meter_testcase)
void test_meter_literals()
Definition: space_test.cc:25
void test_meter_literals ( )

Definition at line 25 of file space_test.cc.

25  {
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()
A value measured in the specified unit.
Definition: quantities.h:566
QTextStream & endl(QTextStream &s)
Literal constants for space quantities.
Definition: spacetime.h:543