CppEphem
test_CEObserver.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * test_CEObserver.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_CEObserver.h"
29 #include "CESkyCoord.h"
30 #include "CENamespace.h"
31 
32 
33 /**********************************************************************/
37  CETestSuite()
38 {
39  base_obs_ = CEObserver(0.0, 0.0, 0.0, CEAngleType::DEGREES);
43 }
44 
45 
46 /**********************************************************************/
50 {}
51 
52 
53 /**********************************************************************/
59 {
60  std::cout << "\nTesting CEObserver:\n";
61 
62  // Run each of the tests
66  test_time();
67 
68  return pass();
69 }
70 
71 
72 /**********************************************************************/
78 {
79  // Default constructor
80  CEObserver test1;
81  test_double(test1.Longitude_Rad(), 0.0, __func__, __LINE__);
82  test_double(test1.Latitude_Rad(), 0.0, __func__, __LINE__);
83  test_double(test1.Temperature_C(), CppEphem::SeaLevelTemp_C(), __func__, __LINE__);
84  test_double(test1.Pressure_hPa(), CppEphem::EstimatePressure_hPa(test1.Elevation_m()), __func__, __LINE__);
85  test_double(test1.RelativeHumidity(), 0.0, __func__, __LINE__);
86  test_double(test1.Wavelength_um(), 0.5, __func__, __LINE__);
87 
88  // Create a copy for testing
89  CEObserver test2(base_obs_);
90  test_double(test2.Longitude_Rad(), base_obs_.Longitude_Rad(), __func__, __LINE__);
91  test_double(test2.Latitude_Rad(), base_obs_.Latitude_Rad(), __func__, __LINE__);
92  test_double(test2.Temperature_K(), base_obs_.Temperature_K(), __func__, __LINE__);
93  test_double(test2.Pressure_hPa(), base_obs_.Pressure_hPa(), __func__, __LINE__);
94  test_double(test2.RelativeHumidity(), base_obs_.RelativeHumidity(), __func__, __LINE__);
95  test_double(test2.Wavelength_um(), base_obs_.Wavelength_um(), __func__, __LINE__);
96 
97  // Copy assignment operator
98  CEObserver test3 = base_obs_;
99  test_double(test3.Longitude_Rad(), base_obs_.Longitude_Rad(), __func__, __LINE__);
100  test_double(test3.Latitude_Rad(), base_obs_.Latitude_Rad(), __func__, __LINE__);
101  test_double(test3.Temperature_K(), base_obs_.Temperature_K(), __func__, __LINE__);
102  test_double(test3.Pressure_hPa(), base_obs_.Pressure_hPa(), __func__, __LINE__);
103  test_double(test3.RelativeHumidity(), base_obs_.RelativeHumidity(), __func__, __LINE__);
104  test_double(test3.Wavelength_um(), base_obs_.Wavelength_um(), __func__, __LINE__);
105 
106  return pass();
107 }
108 
109 
110 /**********************************************************************/
116 {
117  // Create a copy with different values for testing
118  CEObserver obs(base_obs_);
119 
120  // Test longitude
121  double lon = obs.Longitude_Deg() + 10.0;
123  test_double(obs.Longitude_Deg(), lon, __func__, __LINE__);
124 
125  // Test latitude
126  double lat = obs.Latitude_Deg() + 10.0;
128  test_double(obs.Latitude_Deg(), lat, __func__, __LINE__);
129 
130  // Set both longitude and latitude
131  obs.SetGeoCoordinates(lon-10.0, lat-10.0, CEAngleType::DEGREES);
132  test_double(obs.Longitude_Deg(), base_obs_.Longitude_Deg(), __func__, __LINE__);
133  test_double(obs.Latitude_Deg(), base_obs_.Latitude_Deg(), __func__, __LINE__);
134 
135  // Test elevation
136  double elev = obs.Elevation_m() + 10.0;
137  obs.SetElevation(elev);
138  test_double(obs.Elevation_m(), elev, __func__, __LINE__);
139 
140  // Test setting UTC offset
141  double utc_offset = obs.UTCOffset() + 2.5;
142  obs.SetUTCOffset(utc_offset);
143  test_double(obs.UTCOffset(), utc_offset, __func__, __LINE__);
144 
145  // Test that we get similar positions to Astropy
147  std::vector<double> earth_pos_m = {6378137.00000, 0.0, 0.0};
148  std::vector<double> test_pos_m = base_obs_.PositionGeo();
149  test_vect(test_pos_m, earth_pos_m, __func__, __LINE__);
150 
151  return pass();
152 }
153 
154 
155 /**********************************************************************/
161 {
162  // Cache the tolerance
163  double old_tol(DblTol());
164  SetDblTol(1.0e-11);
165 
166  // Create a copy with different values for testing
167  CEObserver obs(base_obs_);
168 
169  // Test temperature
170  double temp_K = obs.Temperature_K() + 10.0;
171  double temp_C = CppEphem::Temp_K2C(temp_K);
172  double temp_F = CppEphem::Temp_K2F(temp_K);
173  obs.SetTemperature_K(temp_K);
174  test_double(obs.Temperature_K(), temp_K, __func__, __LINE__);
175  test_double(obs.Temperature_C(), temp_C, __func__, __LINE__);
176  test_double(obs.Temperature_F(), temp_F, __func__, __LINE__);
177 
178  // Test Temperature setting
179  temp_F += 10.0;
180  obs.SetTemperature_F(temp_F);
181  test_double(obs.Temperature_F(), temp_F, __func__, __LINE__);
182  temp_C -= 10.0;
183  obs.SetTemperature_C(temp_C);
184  test_double(obs.Temperature_C(), temp_C, __func__, __LINE__);
185 
186  // Test pressure
187  double pres = obs.Pressure_hPa() + 10.0;
188  obs.SetPressure_hPa(pres);
189  test_double(obs.Pressure_hPa(), pres, __func__, __LINE__);
190 
191  // Test Relative humidity
192  double relHumidity = obs.RelativeHumidity();
193  if (relHumidity == 0.25) {
194  relHumidity = 0.5;
195  } else {
196  relHumidity = 0.25;
197  }
198  obs.SetRelativeHumidity(relHumidity);
199  test_double(obs.RelativeHumidity(), relHumidity, __func__, __LINE__);
200 
201  // Test wavelength
202  double wavelength = obs.Wavelength_um() + 10.0;
203  obs.SetWavelength_um(wavelength);
204  test_double(obs.Wavelength_um(), wavelength, __func__, __LINE__);
205 
206  // Make sure the print statement actually does something
207  test(obs.print().size() > 0, __func__, __LINE__);
208 
209  // Reset the tolerance
210  SetDblTol(old_tol);
211  return pass();
212 }
213 
214 
215 /**********************************************************************/
221 {
222  double offset = base_obs_.UTCOffset();
223  double old_tol(DblTol());
224  SetDblTol(1.0e-12);
225 
226  // Make sure the time is noon on J2000
228  std::vector<double> local = base_obs_.Time( date );
229  std::vector<double> utc = base_obs_.Time_UTC( date );
230 
231  test_vect(local, {offset+12, 0.0, 0.0, 0.0}, __func__, __LINE__);
232  test_vect(utc, {12.0, 0.0, 0.0, 0.0}, __func__, __LINE__);
233 
234  SetDblTol(old_tol);
235  return pass();
236 }
237 
238 
239 /**********************************************************************/
242 int main(int argc, char** argv)
243 {
244  test_CEObserver tester;
245  return (!tester.runtests());
246 }
CEObserver::Elevation_m
double Elevation_m() const
Return altitude in meters above sea level.
Definition: CEObserver.h:166
CEObserver::SetTemperature_K
void SetTemperature_K(const double &temp_K=CppEphem::SeaLevelTemp_K())
Set the observer's temperature (Kelvin)
Definition: CEObserver.h:371
test_CEObserver::runtests
virtual bool runtests(void)
Run tests.
Definition: test_CEObserver.cpp:58
CEObserver::SetUTCOffset
void SetUTCOffset(const double &utc_offset)
Set the UTC offset for the observers time.
Definition: CEObserver.h:236
CEObserver::SetLatitude
void SetLatitude(const double &latitude, const CEAngleType &angle_type=CEAngleType::RADIANS)
Set the observer's latitude.
Definition: CEObserver.h:310
CEObserver::Time
std::vector< double > Time(const CEDate &date)
Get the current local time information (see CETime)
Definition: CEObserver.h:258
CENamespace.h
CEDate
Definition: CEDate.h:43
CEObserver::Temperature_C
double Temperature_C() const
Return temperature in degrees Celsius.
Definition: CEObserver.h:186
CEObserver::RelativeHumidity
double RelativeHumidity() const
Return relative humidity.
Definition: CEObserver.h:216
CEObserver::PositionGeo
std::vector< double > PositionGeo(void) const
Returns the observers geocentric position in meters.
Definition: CEObserver.cpp:119
CEObserver::Temperature_F
double Temperature_F() const
Return temperature in degrees Fahrenheit.
Definition: CEObserver.h:206
test_CEObserver::test_constructor
bool test_constructor(void)
Test that we can set the observer latitude,longitude coordinates.
Definition: test_CEObserver.cpp:77
CEObserver::Time_UTC
std::vector< double > Time_UTC(const CEDate &date)
Get the current local time information (see CETime)
Definition: CEObserver.h:274
CEObserver::Longitude_Rad
double Longitude_Rad() const
Return observer geographic longitude in radians.
Definition: CEObserver.h:126
CEObserver::Temperature_K
double Temperature_K() const
Return temperature in Kelvin.
Definition: CEObserver.h:196
CEObserver::SetRelativeHumidity
void SetRelativeHumidity(const double &humidity=0.0)
Set the observer's relative humidity.
Definition: CEObserver.h:349
CEObserver::SetElevation
void SetElevation(const double &elevation=0.0)
Set elevation in meters above sea level.
Definition: CEObserver.h:285
test_CEObserver.h
CEObserver::SetWavelength_um
void SetWavelength_um(const double &new_wavelength_um)
Set the observer's observing wavelength (micrometers)
Definition: CEObserver.h:393
CEObserver::SetPressure_hPa
void SetPressure_hPa(const double &pressure=CppEphem::EstimatePressure_hPa(CppEphem::SeaLevelTemp_C()))
Set the observer's pressure.
Definition: CEObserver.h:338
CppEphem::SeaLevelTemp_C
double SeaLevelTemp_C()
Definition: CENamespace.h:55
CEObserver::Pressure_hPa
double Pressure_hPa() const
Return atmospheric pressure in units of hPa.
Definition: CEObserver.h:176
CEObserver::SetGeoCoordinates
void SetGeoCoordinates(const double &longitude, const double &latitude, const CEAngleType &angle_type=CEAngleType::RADIANS)
Set the observer's longitude and latitude.
Definition: CEObserver.h:324
CEObserver::Wavelength_um
double Wavelength_um() const
Return the wavelength in units of micrometers.
Definition: CEObserver.h:226
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
CEObserver::print
std::string print(void) const
Returns a string containing information about this object.
Definition: CEObserver.cpp:180
CEAngleType::DEGREES
JD
Julian Date.
Definition: CEDate.h:56
test_CEObserver
Definition: test_CEObserver.h:27
main
int main(int argc, char **argv)
Main method that actually runs the tests.
Definition: test_CEObserver.cpp:242
CEObserver::SetLongitude
void SetLongitude(const double &longitude, const CEAngleType &angle_type=CEAngleType::RADIANS)
Set the observer's longitude.
Definition: CEObserver.h:297
test_CEObserver::base_obs_
CEObserver base_obs_
Definition: test_CEObserver.h:62
test_CEObserver::test_CEObserver
test_CEObserver()
Default constructor.
Definition: test_CEObserver.cpp:36
CEObserver::UTCOffset
double UTCOffset() const
Definition: CEObserver.h:246
test_CEObserver::~test_CEObserver
virtual ~test_CEObserver()
Destructor.
Definition: test_CEObserver.cpp:49
CppEphem::Temp_K2C
double Temp_K2C(const double &temp_K)
Definition: CENamespace.h:63
CEObserver::SetTemperature_F
void SetTemperature_F(const double &temp_F=CppEphem::SeaLevelTemp_F())
Set the observer's temperature (Fahrenheit)
Definition: CEObserver.h:382
CEObserver::Latitude_Deg
double Latitude_Deg() const
Return geographic latitude in degrees.
Definition: CEObserver.h:156
CppEphem::EstimatePressure_hPa
double EstimatePressure_hPa(double elevation_m)
Method for estimating atmospheric pressure (in hPa) from altitude (in meters)
Definition: CENamespace.h:100
test_CEObserver::test_set_geoCoords
bool test_set_geoCoords(void)
Test that we can set the observer latitude,longitude coordinates.
Definition: test_CEObserver.cpp:115
CppEphem::Temp_K2F
double Temp_K2F(const double &temp_K)
Definition: CENamespace.h:64
CEObserver
Definition: CEObserver.h:28
test_CEObserver::test_set_atmoPars
bool test_set_atmoPars(void)
Test that we can set the observer latitude,longitude coordinates.
Definition: test_CEObserver.cpp:160
CEObserver::Longitude_Deg
double Longitude_Deg() const
Return observer geographic longitude in degrees.
Definition: CEObserver.h:136
CESkyCoord.h
CEObserver::Latitude_Rad
double Latitude_Rad() const
Return geographic latitude in radians.
Definition: CEObserver.h:146
test_CEObserver::test_time
bool test_time(void)
Test that the time methods are valid.
Definition: test_CEObserver.cpp:220