astrotypes  0.0
TimePointTest.cpp
Go to the documentation of this file.
1 /*
2  * MIT License
3  *
4  * Copyright (c) 2018 PulsarSearchSoft
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
26 
27 
28 namespace pss {
29 namespace astrotypes {
30 namespace units {
31 namespace test {
32 
33 
35  : ::testing::Test()
36 {
37 }
38 
40 {
41 }
42 
44 {
45 }
46 
48 {
49 }
50 
51 struct TestClock : public std::chrono::system_clock
52 {
53  static constexpr const char* symbol = "TestClock";
54 };
55 
56 TEST_F(TimePointTest, test_time_point_minus_time_point)
57 {
58  typedef std::chrono::duration<double, std::ratio<100000>> Duration;
60  TimePoint time_point_1(Duration(4000));
61  TimePoint time_point_2(Duration(3999));
62  auto res = time_point_1 - time_point_2;
63  ASSERT_EQ(res, Duration(1));
64 
65  TimePoint time_point_3(Duration(3999.999999999999));
66  double res_val = 4000.0 - 3999.999999999999;
67  auto res2 = time_point_1 - time_point_3;
68  ASSERT_EQ(res2, Duration(res_val));
69 
70 }
71 
72 TEST_F(TimePointTest, test_time_point_plus_boost_quantity)
73 {
74  typedef std::chrono::duration<double, std::ratio<100>> Duration;
76  TimePoint time_point(Duration(4000));
77  boost::units::quantity<boost::units::si::time, double> boost_type(100 * boost::units::si::seconds);
78  TimePoint res = time_point + boost_type;
79  ASSERT_EQ(res, TimePoint(Duration(4001)));
80 }
81 
82 TEST_F(TimePointTest, test_time_point_plus_equal_boost_quantity)
83 {
84  typedef std::chrono::duration<double, std::ratio<100>> Duration;
86  TimePoint time_point(Duration(4000));
87  boost::units::quantity<boost::units::si::time, double> boost_type(100 * boost::units::si::seconds);
88  time_point += boost_type;
89  ASSERT_EQ(time_point, TimePoint(Duration(4001)));
90 }
91 
92 TEST_F(TimePointTest, test_time_point_minus_boost_quantity)
93 {
94  typedef std::chrono::duration<double, std::ratio<100>> Duration;
96  TimePoint time_point(Duration(4000));
97  boost::units::quantity<boost::units::si::time, double> boost_type(200 * boost::units::si::seconds);
98  TimePoint res = time_point - boost_type;
99  ASSERT_EQ(res, TimePoint(Duration(3998)));
100 }
101 
102 TEST_F(TimePointTest, test_time_point_minus_equal_boost_quantity)
103 {
104  typedef std::chrono::duration<double, std::ratio<100>> Duration;
106  TimePoint time_point(Duration(4000));
107  boost::units::quantity<boost::units::si::time, double> boost_type(100 * boost::units::si::seconds);
108  time_point -= boost_type;
109  ASSERT_EQ(time_point, TimePoint(Duration(3999)));
110 }
111 
112 } // namespace test
113 } // namespace units
114 } // namespace astrotypes
115 } // namespace pss
TEST_F(DispersionConstantTest, test_dimensionally_correct)
static constexpr const char * symbol
extension of std::chrono::time_point for astrotypes clocks
Definition: TimePoint.h:53