CppEphem
test_CEObservation.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * test_CEObservation.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 
26 #include <iostream>
27 
28 #include "test_CEObservation.h"
29 #include "CENamespace.h"
30 
31 
32 /**********************************************************************/
36  CETestSuite()
37 {
38  // Setup the observer
44 
45  // Setup the date
48 
49  // Set the object that will be observed
50  base_body_ = CEBody("test", CEAngle::Deg(83.663), CEAngle::Deg(22.0145),
52 
53  // Put it all together
55 }
56 
57 
58 /**********************************************************************/
62 {}
63 
64 
65 /**********************************************************************/
71 {
72  std::cout << "\nTesting CEObservation:\n";
73 
74  // Run each of the tests
77  test_cache();
78 
79  return pass();
80 }
81 
82 
83 /**********************************************************************/
88 {
89  // Default constructor
90  CEObservation test1;
91  test(test1.Body() == nullptr, __func__, __LINE__);
92  test(test1.Date() == nullptr, __func__, __LINE__);
93  test(test1.Observer() == nullptr, __func__, __LINE__);
94 
95  // Test the copy constructor
96  CEObservation test2(base_obs_);
97  test(test2.Body() == base_obs_.Body(), __func__, __LINE__);
98  test(test2.Date() == base_obs_.Date(), __func__, __LINE__);
99  test(test2.Observer() == base_obs_.Observer(), __func__, __LINE__);
100 
101  // Test construction from base objects
103  test(test3.Body() == &base_body_, __func__, __LINE__);
104  test(test3.Date() == &base_date_, __func__, __LINE__);
105  test(test3.Observer() == &base_observer_, __func__, __LINE__);
106 
107  // Test the copy assignment operator
108  CEObservation test4 = test3;
109  test(test4.Body() == &base_body_, __func__, __LINE__);
110  test(test4.Date() == &base_date_, __func__, __LINE__);
111  test(test4.Observer() == &base_observer_, __func__, __LINE__);
112 
113  return pass();
114 }
115 
116 
117 /**********************************************************************/
122 {
123  // Test getting the pointers to the objects
124  CEObservation test1 = base_obs_;
125  test(test1.Body() != nullptr, __func__, __LINE__);
126  test(test1.Body() == &base_body_, __func__, __LINE__);
127  test(test1.Date() != nullptr, __func__, __LINE__);
128  test(test1.Date() == &base_date_, __func__, __LINE__);
129  test(test1.Observer() != nullptr, __func__, __LINE__);
130  test(test1.Observer() == &base_observer_, __func__, __LINE__);
131 
132  // Copy base objects for testing (the pointers will be different)
133  CEBody test_body(base_body_);
134  CEDate test_date(base_date_);
135  CEObserver test_observer(base_observer_);
136 
137  // Now reset the pointers
138  test1.SetBody(&test_body);
139  test1.SetDate(&test_date);
140  test1.SetObserver(&test_observer);
141 
142  // Test that the pointers have been reset
143  test(test1.Body() != nullptr, __func__, __LINE__);
144  test(test1.Date() != nullptr, __func__, __LINE__);
145  test(test1.Observer() != nullptr, __func__, __LINE__);
146 
147  return pass();
148 }
149 
150 
151 /**********************************************************************/
156 {
157  // Test default values
158  CEObservation test1;
159  test_double(test1.GetAltitude_Deg(), 90.0, __func__, __LINE__);
160  test_double(test1.GetAzimuth_Deg(), 0.0, __func__, __LINE__);
161  test_double(test1.GetZenith_Deg(), 0.0, __func__, __LINE__);
162  test_double(test1.GetApparentXCoordinate_Deg(), 0.0, __func__, __LINE__);
163  test_double(test1.GetApparentYCoordinate_Deg(), 0.0, __func__, __LINE__);
164  test_double(test1.GetHourAngle_Deg(), 0.0, __func__, __LINE__);
165 
166  // Now we setup the actual tests for observed coordinates
167  // Note: these coordinates are derived from CESkyCoord tests
168  CESkyCoord obs_coords(CEAngle::Deg(35.55160709646245),
169  CEAngle::Deg(152.5681387256824),
174 
175  // Test that the coordinates update when the date is changed
176  test(obs_coords == test2, __func__, __LINE__);
177  test_double(base_obs_.GetApparentXCoordinate_Deg(), 0.0, __func__, __LINE__);
178  test_double(base_obs_.GetApparentYCoordinate_Deg(), 0.0, __func__, __LINE__);
179  test_double(base_obs_.GetHourAngle_Deg(), 0.0, __func__, __LINE__);
180 
181  // Test the actual coordinates
182  double test_x(0), test_y(0);
183 
184  // Test observed coordinates
185  base_obs_.GetAzimuthZenith_Deg(&test_x, &test_y);
186  test_double(test_x, test2.XCoord().Deg(), __func__, __LINE__);
187  test_double(test_y, test2.YCoord().Deg(), __func__, __LINE__);
188 
189  // Test apparent coordinates
190  base_obs_.GetApparentXYCoordinate_Deg(&test_x, &test_y);
191  test_double(test_x, 0.0, __func__, __LINE__);
192  test_double(test_y, 0.0, __func__, __LINE__);
193 
194  return pass();
195 }
196 
197 
198 /**********************************************************************/
201 int main(int argc, char** argv)
202 {
203  test_CEObservation tester;
204  return (!tester.runtests());
205 }
test_CEObservation::test_CEObservation
test_CEObservation()
Default constructor.
Definition: test_CEObservation.cpp:35
CESkyCoordType::ICRS
RA, Dec (referenced at the barycenter of the solarsystem)
CEObservation::GetZenith_Deg
virtual double GetZenith_Deg()
Definition: CEObservation.h:199
CEObservation::SetObserver
virtual void SetObserver(CEObserver *new_observer)
Set underlying CEObserver object.
Definition: CEObservation.h:135
CENamespace.h
CEDate
Definition: CEDate.h:43
CEObservation::GetAzimuthZenith_Deg
virtual void GetAzimuthZenith_Deg(double *azimuth, double *zenith)
Returns both the azimuth and zenith angle of a given 'body_' as observed by 'observer_' on the date g...
Definition: CEObservation.cpp:119
CEObservation::GetApparentYCoordinate_Deg
virtual double GetApparentYCoordinate_Deg()
Definition: CEObservation.h:282
CESkyCoord
Definition: CESkyCoord.h:49
CEObservation::Observer
CEObserver * Observer()
Access the underlying objects.
Definition: CEObservation.h:103
test_CEObservation::runtests
virtual bool runtests(void)
Run tests.
Definition: test_CEObservation.cpp:70
CEObservation::GetApparentXYCoordinate_Deg
virtual void GetApparentXYCoordinate_Deg(double *apparent_X, double *apparent_Y)
Returns both the observed x,y coordinates of a given 'body_' as observed by 'observer_' on the date g...
Definition: CEObservation.cpp:150
CEObserver::SetRelativeHumidity
void SetRelativeHumidity(const double &humidity=0.0)
Set the observer's relative humidity.
Definition: CEObserver.h:349
CEObservation::GetHourAngle_Deg
virtual double GetHourAngle_Deg()
Definition: CEObservation.h:241
CEObserver::SetWavelength_um
void SetWavelength_um(const double &new_wavelength_um)
Set the observer's observing wavelength (micrometers)
Definition: CEObserver.h:393
test_CEObservation::base_date_
CEDate base_date_
Definition: test_CEObservation.h:63
CEObserver::SetPressure_hPa
void SetPressure_hPa(const double &pressure=CppEphem::EstimatePressure_hPa(CppEphem::SeaLevelTemp_C()))
Set the observer's pressure.
Definition: CEObserver.h:338
CEObservation::GetApparentXCoordinate_Deg
virtual double GetApparentXCoordinate_Deg()
Definition: CEObservation.h:261
main
int main(int argc, char **argv)
Main method that actually runs the tests.
Definition: test_CEObservation.cpp:201
CEObserver::SetTemperature_C
void SetTemperature_C(const double &temp_C=CppEphem::SeaLevelTemp_C())
Set the observer's temperature (Celsius)
Definition: CEObserver.h:360
CppEphem::julian_date_J2000
double julian_date_J2000()
Julian Date corresponding to J2000.
Definition: CENamespace.h:67
test_CEObservation.h
CEAngleType::DEGREES
JD
Julian Date.
Definition: CEDate.h:56
test_CEObservation::~test_CEObservation
virtual ~test_CEObservation()
Destructor.
Definition: test_CEObservation.cpp:61
CEObservation::Body
CEBody * Body()
Access underlying CEBody object.
Definition: CEObservation.h:113
test_CEObservation::base_obs_
CEObservation base_obs_
Definition: test_CEObservation.h:65
test_CEObservation::base_body_
CEBody base_body_
Definition: test_CEObservation.h:62
test_CEObservation::test_cache
bool test_cache(void)
Tests accessing and updating of cached parameters.
Definition: test_CEObservation.cpp:155
test_CEObservation::test_obj_return
bool test_obj_return(void)
Tests accessing underlying observer, date, and object classes.
Definition: test_CEObservation.cpp:121
CEObservation::GetAzimuth_Rad
virtual double GetAzimuth_Rad()
Definition: CEObservation.h:167
CEObserver
Definition: CEObserver.h:28
CEAngle::Deg
double Deg(void) const
Return angle in degrees as a double.
Definition: CEAngle.cpp:328
test_CEObservation
Definition: test_CEObservation.h:27
CEObservation
Definition: CEObservation.h:33
CEObservation::GetAzimuth_Deg
virtual double GetAzimuth_Deg()
Definition: CEObservation.h:178
CEBody
Definition: CEBody.h:39
CEObservation::SetBody
virtual void SetBody(CEBody *new_body)
Set underlying CEBody object.
Definition: CEObservation.h:146
test_CEObservation::test_constructor
bool test_constructor(void)
Tests constructing a CEObservation object.
Definition: test_CEObservation.cpp:87
CEObservation::GetZenith_Rad
virtual double GetZenith_Rad()
Definition: CEObservation.h:188
CEDate::SetReturnType
void SetReturnType(CEDateType return_type)
Set the return type from the overloaded 'operator double'.
Definition: CEDate.h:247
CEObservation::Date
CEDate * Date()
Access underlying CEDate object.
Definition: CEObservation.h:124
CEObservation::GetAltitude_Deg
virtual double GetAltitude_Deg()
Definition: CEObservation.h:220
test_CEObservation::base_observer_
CEObserver base_observer_
Definition: test_CEObservation.h:64
CEObservation::SetDate
virtual void SetDate(CEDate *new_date)
Set underlying CEDate object.
Definition: CEObservation.h:157
CESkyCoordType::OBSERVED
Azimuth, Zenith (requires additional observer information)