frequency_test.cc
Go to the documentation of this file.
1 /**
2  * @file test/Utilities/frequency_test.cc
3  * @brief Unit test for `lardataalg/Utilities/quantities/frequency.h` header.
4  * @author Gianluca Petrillo (petrillo@slac.stanford.edu)
5  * @date November 2, 2018
6  * @see `lardataalg/Utilities/quantities.h`
7  *
8  */
9 
10 // Boost libraries
11 #define BOOST_TEST_MODULE ( frequency_test )
12 #include <boost/test/unit_test.hpp>
13 
14 // LArSoft libraries
16 
17 // C/C++ standard libraries
18 #include <type_traits> // std::decay_t<>
19 
20 
21 // -----------------------------------------------------------------------------
23 
25 
26  constexpr auto f_Hz = 2_Hz;
27  static_assert(std::is_same<decltype(f_Hz), util::quantities::hertz const>());
28  static_assert(double(f_Hz) == 2.0);
29  static_assert(f_Hz == 2.0_Hz);
30 
31  constexpr auto f_kHz = 20_kHz;
32  static_assert
33  (std::is_same<decltype(f_kHz), util::quantities::kilohertz const>());
34  static_assert(double(f_kHz) == 20.0);
35  static_assert(f_kHz == 20.0_kHz);
36 
37  constexpr auto f_MHz = 200_MHz;
38  static_assert
39  (std::is_same<decltype(f_MHz), util::quantities::megahertz const>());
40  static_assert(double(f_MHz) == 200.0);
41  static_assert(f_MHz == 200.0_MHz);
42 
43  constexpr auto f_GHz = 5_GHz;
44  static_assert
45  (std::is_same<decltype(f_GHz), util::quantities::gigahertz const>());
46  static_assert(double(f_GHz) == 5.0);
47  static_assert(f_GHz == 5.0_GHz);
48 
49 } // test_frequency_literals()
50 
51 
52 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
54 
55  using namespace util::quantities::time_literals;
57 
58  // ---------------------------------------------------------------------------
59 
60  static_assert(std::is_same<decltype(5_us * 2_MHz), double>());
61  static_assert(5_us * 2_MHz == 10.0);
62  static_assert(5_ms * 2_MHz == 10'000.0);
63 
64  static_assert(std::is_same<decltype(2_MHz * 5_us), double>());
65  static_assert(2_MHz * 5_us == 10.0);
66  static_assert(2_MHz * 5_ms == 10'000.0);
67 
68  // ---------------------------------------------------------------------------
69 
70  static_assert
71  (std::is_same<decltype(10 / 5_us), util::quantities::megahertz>());
72  static_assert(10 / 5_us == 2_MHz);
73  static_assert(10'000.0 / 5_ms == 2_MHz);
74 
75  // ---------------------------------------------------------------------------
76 
77  static_assert
78  (std::is_same<decltype(10 / 2_MHz), util::quantities::microsecond>());
79  static_assert(10 / 2_MHz == 5_us);
80  static_assert(10'000.0 / 2_MHz == 5_ms);
81 
82  // ---------------------------------------------------------------------------
83 
84 } // test_constexpr_operations()
85 
86 
87 // -----------------------------------------------------------------------------
88 // BEGIN Test cases -----------------------------------------------------------
89 // -----------------------------------------------------------------------------
90 BOOST_AUTO_TEST_CASE(frequency_testcase) {
91 
94 
95 } // BOOST_AUTO_TEST_CASE(frequency_testcase)
96 
97 // -----------------------------------------------------------------------------
98 // END Test cases -------------------------------------------------------------
99 // -----------------------------------------------------------------------------
Dimensioned variables representing frequency quantities.
void test_frequency_literals()
Literal constants for frequency quantities.
Definition: frequency.h:130
void test_frequency_special_operations()
A value measured in the specified unit.
Definition: quantities.h:566
Literal constants for time quantities.
Definition: spacetime.h:175
BOOST_AUTO_TEST_CASE(frequency_testcase)