ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UnitConversionTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file UnitConversionTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2018 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <boost/test/unit_test.hpp>
10 
12 #include "Acts/Utilities/Units.hpp"
13 
14 using namespace Acts::UnitLiterals;
15 
16 BOOST_AUTO_TEST_SUITE(unit_conversions)
17 
18 BOOST_AUTO_TEST_CASE(length_conversions) {
19  CHECK_CLOSE_REL(1_m, 1e-3_km, 1e-15);
20  CHECK_CLOSE_REL(1_m, 1e2_cm, 1e-15);
21  CHECK_CLOSE_REL(1_m, 1e3_mm, 1e-15);
22  CHECK_CLOSE_REL(1_m, 1e6_um, 1e-15);
23  CHECK_CLOSE_REL(1_m, 1e9_nm, 1e-15);
24  CHECK_CLOSE_REL(1_m, 1e12_pm, 1e-15);
25  CHECK_CLOSE_REL(1_m, 1e15_fm, 1e-15);
26 }
27 
28 BOOST_AUTO_TEST_CASE(area_conversions) {
29  CHECK_CLOSE_REL(1_mm * 1_mm, 1_mm2, 1e-15);
30  CHECK_CLOSE_REL(1_mm * 1_mm, 0.01_cm2, 1e-15);
31  CHECK_CLOSE_REL(1_mm * 1_mm, 0.000001_m2, 1e-15);
32  CHECK_CLOSE_REL(1_cm * 1_cm, 100_mm2, 1e-15);
33  CHECK_CLOSE_REL(1_cm * 1_cm, 1_cm2, 1e-15);
34  CHECK_CLOSE_REL(1_cm * 1_cm, 0.0001_m2, 1e-15);
35  CHECK_CLOSE_REL(1_m * 1_m, 1000000_mm2, 1e-15);
36  CHECK_CLOSE_REL(1_m * 1_m, 10000_cm2, 1e-15);
37  CHECK_CLOSE_REL(1_m * 1_m, 1_m2, 1e-15);
38 }
39 
40 BOOST_AUTO_TEST_CASE(volume_conversions) {
41  CHECK_CLOSE_REL(1_mm * 1_mm * 1_mm, 1_mm3, 1e-15);
42  CHECK_CLOSE_REL(1_mm2 * 1_mm, 1_mm3, 1e-15);
43  CHECK_CLOSE_REL(1_cm * 1_cm * 1_cm, 1_cm3, 1e-15);
44  CHECK_CLOSE_REL(1_cm2 * 1_cm, 1_cm3, 1e-15);
45  CHECK_CLOSE_REL(1_m * 1_m * 1_m, 1_m3, 1e-15);
46  CHECK_CLOSE_REL(1_m2 * 1_m, 1_m3, 1e-15);
47 }
48 
49 BOOST_AUTO_TEST_CASE(time_conversions) {
50  CHECK_CLOSE_REL(1_h, 60_min, 1e-15);
51  CHECK_CLOSE_REL(1_h, 3600_s, 1e-15);
52  CHECK_CLOSE_REL(1_min, 60_s, 1e-15);
53  CHECK_CLOSE_REL(1_s, 1e3_ms, 1e-15);
54  CHECK_CLOSE_REL(1_s, 1e6_us, 1e-15);
55  CHECK_CLOSE_REL(1_s, 1e9_ns, 1e-15);
56  CHECK_CLOSE_REL(1_s, 1e12_ps, 1e-15);
57  CHECK_CLOSE_REL(1_s, 1e15_fs, 1e-15);
58 }
59 
60 BOOST_AUTO_TEST_CASE(angle_conversions) {
61  CHECK_CLOSE_REL(45_degree, M_PI / 4 * 1_rad, 1e-15);
62  CHECK_CLOSE_REL(90_degree, M_PI / 2 * 1_rad, 1e-15);
63  CHECK_CLOSE_REL(180_degree, M_PI * 1_rad, 1e-15);
64  CHECK_CLOSE_REL(360_degree, 2 * M_PI * 1_rad, 1e-15);
65  CHECK_CLOSE_REL(1_mm / 1_m, 1_mrad, 1e-15);
66  CHECK_CLOSE_REL(1_um / 1_mm, 1_mrad, 1e-15);
67 }
68 
69 BOOST_AUTO_TEST_CASE(energy_conversions) {
70  CHECK_CLOSE_REL(1_MeV, 1e6_eV, 1e-15);
71  CHECK_CLOSE_REL(1_MeV, 1e3_keV, 1e-15);
72  CHECK_CLOSE_REL(1_MeV, 1e-3_GeV, 1e-15);
73  CHECK_CLOSE_REL(1_MeV, 1e-6_TeV, 1e-15);
74 }
75 
76 BOOST_AUTO_TEST_CASE(mass_conversions) {
77  CHECK_CLOSE_REL(1_kg, 1000_g, 1e-15);
78  CHECK_CLOSE_REL(0.001_kg, 1_g, 1e-15);
79  CHECK_CLOSE_REL(1_u, 931.49410242_MeV, 1e-15);
80  CHECK_CLOSE_REL(1_u, 1.66053906660e-24_g, 1e-7);
81 }
82 
83 BOOST_AUTO_TEST_CASE(mass_energy_conversions) {
84  // always assumes c == 1
85  CHECK_CLOSE_REL(1.782662e-36_kg, 1_eV, 1e-15);
86  CHECK_CLOSE_REL(1.782662e-33_kg, 1_keV, 1e-15);
87  CHECK_CLOSE_REL(1.782662e-30_kg, 1_MeV, 1e-15);
88  CHECK_CLOSE_REL(1.782662e-27_kg, 1_GeV, 1e-15);
89  CHECK_CLOSE_REL(1.782662e-33_g, 1_eV, 1e-15);
90  CHECK_CLOSE_REL(1.782662e-30_g, 1_keV, 1e-15);
91  CHECK_CLOSE_REL(1.782662e-27_g, 1_MeV, 1e-15);
92  CHECK_CLOSE_REL(1.782662e-24_g, 1_GeV, 1e-15);
93 }
94 
95 BOOST_AUTO_TEST_CASE(charge_conversions) {
96  CHECK_CLOSE_REL(1_C, 1.602176634e19_e, 1e-15);
97 }
98 
99 BOOST_AUTO_TEST_CASE(magnetic_field_conversions) {
100  CHECK_CLOSE_REL(10_kGauss, 1_T, 1e-15);
101  CHECK_CLOSE_REL(1_kGauss, 1000_Gauss, 1e-15);
102 }
103 
104 BOOST_AUTO_TEST_CASE(momentum_to_radius_conversion) {
105  // note: no conversion factors necessary
106  CHECK_CLOSE_REL(1_GeV / (1_e * 1_T), 3.3336_m, 1e-3);
107  CHECK_CLOSE_REL(1_GeV / (1_e * 2_T), 166.8_cm, 1e-3);
108  CHECK_CLOSE_REL(1_GeV / (2_e * 1_T), 166.8_cm, 1e-3);
109  CHECK_CLOSE_REL(1_GeV / (1_e * 4_T), 83.39_cm, 1e-3);
110  CHECK_CLOSE_REL(1_GeV / (2_e * 2_T), 83.39_cm, 1e-3);
111 }
112 
113 BOOST_AUTO_TEST_SUITE_END()