CppEphem
test_CETime.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * test_CETime.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 <iostream>
25 #include "test_CETime.h"
26 #include "CENamespace.h"
27 
28 
29 /**********************************************************************/
33  CETestSuite()
34 {
35  // Create the base objects for comparison
36  base_ = CETime(123456.789, CETimeType::UTC);
37  naptime_ = std::chrono::milliseconds(500);
38 
39  SetDblTol(1e-11);
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 CETime:\n";
60 
61  // Run each of the tests
63 
64  return pass();
65 }
66 
67 
68 /**********************************************************************/
74 {
75  // Vectors containing the same information
76  double timeA = 123456.789; // 12:34:56.789
77  std::vector<double> timeB = {12.0, 34.0, 56.0, 0.789};
78 
79  // Create a comparison running date object that should be different
80  CETime test1(timeA, CETimeType::UTC);
81  test_double(test1.Hour(), timeB[0], __func__, __LINE__);
82  test_double(test1.Min(), timeB[1], __func__, __LINE__);
83  test_double(test1.Sec(), timeB[2]+timeB[3], __func__, __LINE__);
84  std::cout << test1.Sec() - (timeB[2]+timeB[3]) << std::endl;
85 
86  // Copy constructor
87  CETime test2(timeB, CETimeType::UTC);
88  test_double(test2.Hour(), timeB[0], __func__, __LINE__);
89  test_double(test2.Min(), timeB[1], __func__, __LINE__);
90  test_double(test2.Sec(), timeB[2]+timeB[3], __func__, __LINE__);
91 
92  // Default constructor
93 
94  return pass();
95 }
96 
97 
98 /**********************************************************************/
101 int main(int argc, char** argv)
102 {
103  test_CETime tester;
104  return (!tester.runtests());
105 }
UTC
Definition: CETime.h:53
CENamespace.h
CETime::Hour
double Hour(void) const
Return the Hour associated with this time object.
Definition: CETime.h:141
CETime
Definition: CETime.h:37
test_CETime.h
main
int main(int argc, char **argv)
Main method that actually runs the tests.
Definition: test_CETime.cpp:101
test_CETime::base_
CETime base_
Definition: test_CETime.h:57
CETime::Sec
double Sec(void) const
Return the Second associated with this time object.
Definition: CETime.h:165
test_CETime::runtests
virtual bool runtests()
Run tests.
Definition: test_CETime.cpp:57
test_CETime::test_construct
virtual bool test_construct(void)
Test constructors.
Definition: test_CETime.cpp:73
test_CETime::naptime_
std::chrono::milliseconds naptime_
Definition: test_CETime.h:58
CETime::Min
double Min(void) const
Return the Minute associated with this time object.
Definition: CETime.h:153
test_CETime::test_CETime
test_CETime()
Default constructor.
Definition: test_CETime.cpp:32
test_CETime::~test_CETime
virtual ~test_CETime()
Destructor.
Definition: test_CETime.cpp:48
test_CETime
Definition: test_CETime.h:27