astrotypes  0.0
JulianClockTest.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  */
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 TEST_F(JulianClockTest, test_julian_day)
52 {
53  ASSERT_EQ(julian_day(1), std::chrono::hours(24));
54  ASSERT_EQ(julian_day(2), std::chrono::hours(48));
55 }
56 
57 TEST_F(JulianClockTest, test_time_since_epoch)
58 {
59  std::chrono::time_point<JulianClock> epoc;
60  ASSERT_EQ(julian_day(0), epoc.time_since_epoch());
61 
62  std::chrono::time_point<JulianClock> hundred = epoc + julian_day(100.0);
63  ASSERT_EQ(julian_day(100.0), hundred.time_since_epoch());
64 
65  std::chrono::time_point<JulianClock> hundred_hours = epoc + std::chrono::duration_cast<julian_day>(std::chrono::hours(24));
66  ASSERT_EQ(julian_day(1.0), hundred_hours.time_since_epoch());
67 }
68 
69 TEST_F(JulianClockTest, test_time_point_conversion)
70 {
71  typename JulianClock::time_point epoch(julian_day(2440587.5));
72  std::chrono::time_point<std::chrono::system_clock> system_epoch;
73  ASSERT_TRUE( static_cast<std::chrono::time_point<std::chrono::system_clock>>(epoch) == system_epoch);
74  ASSERT_TRUE( static_cast<JulianClock::time_point>(system_epoch) == epoch);
75 
76 }
77 
79 {
80  auto today = JulianClock::now();
81  std::cout << "time now=" << today << "\n";
82 }
83 
84 } // namespace test
85 } // namespace units
86 } // namespace astrotypes
87 } // 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