Cheetah - SKA - PSS - Prototype Time Domain Search Pipeline
ModifiedJulianClockTest.cpp
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  */
24 #include "cheetah/utils/test/ModifiedJulianClockTest.h"
25 #include "cheetah/utils/ModifiedJulianClock.h"
26 #include <ctime>
27 
28 
29 namespace ska {
30 namespace cheetah {
31 namespace utils {
32 namespace test {
33 
34 
35 ModifiedJulianClockTest::ModifiedJulianClockTest()
36  : ::testing::Test()
37 {
38 }
39 
40 ModifiedJulianClockTest::~ModifiedJulianClockTest()
41 {
42 }
43 
44 void ModifiedJulianClockTest::SetUp()
45 {
46 }
47 
48 void ModifiedJulianClockTest::TearDown()
49 {
50 }
51 
52 TEST_F(ModifiedJulianClockTest, test_julian_day)
53 {
54  ASSERT_EQ(julian_day(1), std::chrono::hours(24));
55  ASSERT_EQ(julian_day(2), std::chrono::hours(48));
56 }
57 
58 TEST_F(ModifiedJulianClockTest, test_time_since_epoch)
59 {
60  std::chrono::time_point<ModifiedJulianClock> epoc;
61  ASSERT_EQ(julian_day(0), epoc.time_since_epoch());
62 
63  std::chrono::time_point<ModifiedJulianClock> hundred = epoc + julian_day(100.0);
64  ASSERT_EQ(julian_day(100.0), hundred.time_since_epoch());
65 
66 }
67 
68 TEST_F(ModifiedJulianClockTest, test_time_point_add)
69 {
70  typename ModifiedJulianClock::time_point base(julian_day(48.0));
71  typename ModifiedJulianClock::time_point expected(julian_day(48.5));
72  typename ModifiedJulianClock::time_point midday = base + std::chrono::duration_cast<julian_day>(std::chrono::hours(12));
73  ASSERT_TRUE(expected == midday);
74 }
75 
76 TEST_F(ModifiedJulianClockTest, test_time_point_subtract)
77 {
78  typename ModifiedJulianClock::time_point base(julian_day(48.0));
79  typename ModifiedJulianClock::time_point expected(julian_day(47.5));
80  typename ModifiedJulianClock::time_point midday = base - std::chrono::duration_cast<julian_day>(std::chrono::hours(12));
81  ASSERT_TRUE(expected == midday);
82 }
83 
84 TEST_F(ModifiedJulianClockTest, test_time_point_conversion)
85 {
86  typename ModifiedJulianClock::time_point epoch(julian_day(40587.0));
87  std::chrono::time_point<std::chrono::system_clock> system_epoch;
88  ASSERT_TRUE( static_cast<std::chrono::time_point<std::chrono::system_clock>>(epoch) == system_epoch);
89  ASSERT_TRUE( static_cast<ModifiedJulianClock::time_point>(system_epoch) == epoch);
90 
91 }
92 
93 TEST_F(ModifiedJulianClockTest, test_cout)
94 {
95  auto today = ModifiedJulianClock::now();
96  std::cout << "time now=" << today << "\n";
97 }
98 
99 } // namespace test
100 } // namespace utils
101 } // namespace cheetah
102 } // namespace ska
Some limits and constants for FLDO.
Definition: Brdz.h:35