astrotypes  0.0
ModifiedJulianClockTest.cpp
Go to the documentation of this file.
1 /*
2  * The MIT License (MIT)
3  *
4  * Copyright (c) 2016 The SKA organisation
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  */
27 #include <ctime>
28 
29 
30 namespace pss {
31 namespace astrotypes {
32 namespace units {
33 namespace test {
34 
35 
37  : ::testing::Test()
38 {
39 }
40 
42 {
43 }
44 
46 {
47 }
48 
50 {
51 }
52 
54 {
55  ASSERT_EQ(julian_day(1), std::chrono::hours(24));
56  ASSERT_EQ(julian_day(2), std::chrono::hours(48));
57 }
58 
59 TEST_F(ModifiedJulianClockTest, test_time_since_epoch)
60 {
61  std::chrono::time_point<ModifiedJulianClock> epoc;
62  ASSERT_EQ(julian_day(0), epoc.time_since_epoch());
63 
64  std::chrono::time_point<ModifiedJulianClock> hundred = epoc + julian_day(100.0);
65  ASSERT_EQ(julian_day(100.0), hundred.time_since_epoch());
66 
67 }
68 
69 TEST_F(ModifiedJulianClockTest, test_time_point_add)
70 {
71  typename ModifiedJulianClock::time_point base(julian_day(48.0));
72  typename ModifiedJulianClock::time_point expected(julian_day(48.5));
73  typename ModifiedJulianClock::time_point midday = base + std::chrono::duration_cast<julian_day>(std::chrono::hours(12));
74  ASSERT_TRUE(expected == midday);
75 }
76 
77 TEST_F(ModifiedJulianClockTest, test_time_point_subtract)
78 {
79  typename ModifiedJulianClock::time_point base(julian_day(48.0));
80  typename ModifiedJulianClock::time_point expected(julian_day(47.5));
81  typename ModifiedJulianClock::time_point midday = base - std::chrono::duration_cast<julian_day>(std::chrono::hours(12));
82  ASSERT_TRUE(expected == midday);
83 }
84 
85 TEST_F(ModifiedJulianClockTest, test_time_point_conversion)
86 {
87  typename ModifiedJulianClock::time_point epoch(julian_day(40587.0));
88  std::chrono::time_point<std::chrono::system_clock> system_epoch;
89  ASSERT_TRUE( static_cast<std::chrono::time_point<std::chrono::system_clock>>(epoch) == system_epoch);
90  ASSERT_TRUE( static_cast<ModifiedJulianClock::time_point>(system_epoch) == epoch);
91 }
92 
93 TEST_F(ModifiedJulianClockTest, test_equal_time_points)
94 {
95  typename ModifiedJulianClock::time_point tp(julian_day(40000.576453212111));
96  typename ModifiedJulianClock::time_point tp2(tp);
97  ASSERT_EQ(tp, tp2);
98  ASSERT_TRUE( typename ModifiedJulianClock::duration(0.0) == tp -tp2);
99  ASSERT_FALSE( (tp -tp2) >= boost::units::quantity<boost::units::si::time>(0.1 * boost::units::si::seconds) );
100  ASSERT_FALSE( (tp -tp2) > boost::units::quantity<boost::units::si::time>(0.1 * boost::units::si::seconds) );
101  ASSERT_TRUE( (tp -tp2) < boost::units::quantity<boost::units::si::time>(0.1 * boost::units::si::seconds) );
102 }
103 
105 {
106  auto today = ModifiedJulianClock::now();
107  std::cout << "time now=" << today << "\n";
108 }
109 
110 } // namespace test
111 } // namespace units
112 } // namespace astrotypes
113 } // namespace pss
TEST_F(DispersionConstantTest, test_dimensionally_correct)
constexpr std::enable_if< boost::units::is_quantity< BoostQuantity >::value &&boost::units::is_unit_of_dimension< typename BoostQuantity::unit_type, boost::units::time_dimension >::value &&!is_equivalent< BoostQuantity, std::chrono::duration< ChronoNumericalRep, PeriodType > >::value, BoostQuantity >::type duration_cast(const std::chrono::duration< ChronoNumericalRep, PeriodType > &duration)
Mimic the std::duration_cast to convert to/from boost::units::quantity tyeps.
std::chrono::duration< double, std::ratio< 86400 > > julian_day
representation of julian time is in days
Definition: JulianClock.h:39