CppEphem
test_CERunningDate.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * test_CERunningDate.cpp: CppEphem *
3  * ----------------------------------------------------------------------- *
4  * Copyright © 2019 JCardenzana *
5  * ----------------------------------------------------------------------- *
6  * *
7  * This program is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 
22 #include <stdlib.h>
23 #include <thread>
24 #include "test_CERunningDate.h"
25 #include "CENamespace.h"
26 
27 
28 /**********************************************************************/
32  CETestSuite()
33 {
34  // Create the base objects for comparison
35  base_date_ = CEDate();
36  base_ = CERunningDate();
37  naptime_ms_ = 500;
38  naptime_ = std::chrono::milliseconds(naptime_ms_);
39 
40  // pause execution to give the the date time to run
41  std::this_thread::sleep_for(naptime_);
42 }
43 
44 
45 /**********************************************************************/
49 {}
50 
51 
52 /**********************************************************************/
58 {
59  std::cout << "\nTesting CERunningDate:\n";
60 
61  // Run each of the tests
64 
65  return pass();
66 }
67 
68 
69 /**********************************************************************/
75 {
76  // Create a comparison running date object that should be different
77  CERunningDate test1(base_);
78 
79  // Default constructor
80  test(base_date_.JD() != base_.JD(), __func__, __LINE__);
81  test(base_date_.MJD() != base_.MJD(), __func__, __LINE__);
82  test(base_date_.Gregorian() != base_.Gregorian(), __func__, __LINE__);
83 
84  // These should give the same value
85  test_double(test1.JD(), base_.JD(), __func__, __LINE__);
86 
87  // Make sure the timer has run
88  test_greaterthan(test1.RunTime(), naptime_ms_/1000.0, __func__, __LINE__);
89 
90  return pass();
91 }
92 
93 
94 /**********************************************************************/
100 {
101  // Get a copy of the base timer
102  CERunningDate test1(base_);
103 
104  // Test updating the timer speed
105  test_double(test1.GetTimerSpeed(), 1.0, __func__, __LINE__);
106  double new_speed(100.0);
107  test1.SetTimerSpeed(new_speed);
108  test_double(test1.GetTimerSpeed(), new_speed, __func__, __LINE__);
109 
110  // Pause for some amount of time and test that the
111  test1.ResetTime();
112  test1.SetTimerSpeed(new_speed);
113  std::this_thread::sleep_for(naptime_);
114  test_greaterthan(test1.ScaledRunTime(), naptime_ms_*2.0/1000.0, __func__, __LINE__);
115 
116  // Reset the timer
117  return pass();
118 }
119 
120 
121 /**********************************************************************/
124 int main(int argc, char** argv)
125 {
126  test_CERunningDate tester;
127  return (!tester.runtests());
128 }
test_CERunningDate::base_
CERunningDate base_
Definition: test_CERunningDate.h:59
CERunningDate
Definition: CERunningDate.h:29
test_CERunningDate::runtests
virtual bool runtests()
Run tests.
Definition: test_CERunningDate.cpp:57
CENamespace.h
test_CERunningDate::test_construct
virtual bool test_construct(void)
Test constructors.
Definition: test_CERunningDate.cpp:74
CEDate
Definition: CEDate.h:43
CERunningDate::MJD
virtual double MJD() const
Get the current modified Julian date.
Definition: CERunningDate.cpp:107
test_CERunningDate
Definition: test_CERunningDate.h:27
test_CERunningDate::test_CERunningDate
test_CERunningDate()
Default constructor.
Definition: test_CERunningDate.cpp:31
CERunningDate::ResetTime
void ResetTime(void)
Method for resetting the 'start' variable.
Definition: CERunningDate.h:81
test_CERunningDate::test_timer_manip
virtual bool test_timer_manip(void)
Test manipulating the timer.
Definition: test_CERunningDate.cpp:99
CERunningDate::Gregorian
virtual double Gregorian() const
Get the current Gregorian calendar date formatted as YYYYMMDD.D.
Definition: CERunningDate.cpp:117
CERunningDate::RunTime
virtual double RunTime(void) const
Method for getting the number of seconds since this object was created or reset.
Definition: CERunningDate.cpp:126
main
int main(int argc, char **argv)
Main method that actually runs the tests.
Definition: test_CERunningDate.cpp:124
test_CERunningDate::~test_CERunningDate
virtual ~test_CERunningDate()
Destructor.
Definition: test_CERunningDate.cpp:48
CERunningDate::ScaledRunTime
double ScaledRunTime(void) const
Return the scaled ellapsed time since this object was created.
Definition: CERunningDate.h:103
test_CERunningDate::base_date_
CEDate base_date_
Definition: test_CERunningDate.h:58
CERunningDate::GetTimerSpeed
virtual double GetTimerSpeed(void) const
Get the rate at which the timer is progressing.
Definition: CERunningDate.h:71
test_CERunningDate::naptime_
std::chrono::milliseconds naptime_
Definition: test_CERunningDate.h:61
test_CERunningDate::naptime_ms_
long long naptime_ms_
Definition: test_CERunningDate.h:60
CERunningDate::SetTimerSpeed
virtual void SetTimerSpeed(const double &scale=1.0)
Set the rate at which the timer progresses.
Definition: CERunningDate.h:92
CEDate::MJD
virtual double MJD() const
Get the Modified Julian date represented by this object.
Definition: CEDate.h:160
CEDate::Gregorian
virtual double Gregorian() const
Get the Gregorian calendar date formatted as a double.
Definition: CEDate.h:170
test_CERunningDate.h
CEDate::JD
virtual double JD() const
Get the Julian date represented by this object.
Definition: CEDate.h:150
CERunningDate::JD
virtual double JD() const
Get the current Julian date.
Definition: CERunningDate.cpp:96