IonoModel_T.cpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
39 #include "TestUtil.hpp"
40 #include "IonoModel.hpp"
41 
42 using namespace gnsstk;
43 using namespace std;
44 
46 {
47  public:
50  int getSetTest( void );
51  int equalityTest( void );
52  int nonEqualityTest( void );
53  int validTest( void );
54  int exceptionTest( void );
55  protected:
56  private:
57 };
58 
59 
60 //------------------------------------------------------------
61 //------------------------------------------------------------
63 {
64  TUDEF( "IonoModel", "get and set" );
65 
66  const double a[4] = {1.,2.,3.,4.};
67  const double b[4] = {5.,6.,7.,8.};
68  gnsstk::IonoModel model;
69 
70  double gotA[4] = {0.,0.,0.,0.};
71  double gotB[4] = {0.,0.,0.,0.};
72 
73  // Try to get data from an uninitialized model - should fail
74  // becuase the model isn't yet valid.
75  bool unsetResult = model.getModel(gotA, gotB);
76  TUASSERT( unsetResult == false );
77 
78  // Attempt to set and then get a valid model - should succeed
79  model.setModel(a, b);
80  //model.dump();
81  bool setResult = model.getModel(gotA, gotB);
82  TUASSERT( setResult == true );
83 
84  bool aEqual = (a[0] == gotA[0]) && (a[1] == gotA[1]) && (a[2] == gotA[2]) && (a[3] == gotA[3]);
85  TUASSERT( aEqual == true );
86 
87  bool bEqual = (b[0] == gotB[0]) && (b[1] == gotB[1]) && (b[2] == gotB[2]) && (b[3] == gotB[3]);
88  TUASSERT( bEqual == true );
89 
90  TURETURN();
91 }
92 
93 
94 //------------------------------------------------------------
95 // Assert quality of class IonoModel operator ==
96 //------------------------------------------------------------
97 
99 {
100  TestUtil test1( "IonoModel", "operator ==", __FILE__, __LINE__ );
101  std::string test_desc = "IonoModel objects are created and compared to test operator == precision";
102  std::string test_fail_equals = "These should be equal but they are not.";
103  std::string test_false_equals = "These should NOT be equal but they are.";
104 
105  //Create many alpha and beta arrays which define the Ionospheric model
106  double a[4] = {1.,2.,3.,4.};
107  double b[4] = {4.,3.,2.,1.};
108  double c[4] = {1.,2.,3.,4.};
109  double d[4] = {4.,3.,2.,1.};
110  double e[4] = {0.,0.,0.,0.};
111  gnsstk::IonoModel Model1(a,b);
112  gnsstk::IonoModel Model2(c,d);
113  gnsstk::IonoModel Model3(a,e);
114 
115  test1.assert( Model1 == Model2, test_desc + test_fail_equals, __LINE__ );
116  test1.assert( !(Model1 == Model3), test_desc + test_false_equals, __LINE__ );
117 
118  return( test1.countFails() );
119 }
120 
121 
122 //------------------------------------------------------------
123 // Assert quality of class IonoModel operator !=
124 //------------------------------------------------------------
126 {
127  TestUtil test2( "IonoModel", "operator !=", __FILE__, __LINE__ );
128  std::string test_desc = "IonoModel objects are created and compared to test operator != precision";
129  std::string test_fail_notequal = "These should be [not equal] but they are not [not equal].";
130  std::string test_false_notequal = "These should NOT be [not equal] but they are [not equal].";
131 
132  //Create many alpha and beta arrays which define the Ionospheric model
133  double a[4] = {1.,2.,3.,4.};
134  double b[4] = {4.,3.,2.,1.};
135  double c[4] = {1.,2.,3.,4.};
136  double d[4] = {4.,3.,2.,1.};
137  double e[4] = {0.,0.,0.,0.};
138  gnsstk::IonoModel Model1(a,b);
139  gnsstk::IonoModel Model2(c,d);
140  gnsstk::IonoModel Model3(a,e);
141 
142  test2.assert( ( Model1 != Model2 )==false, test_desc + test_fail_notequal, __LINE__ );
143  test2.assert( ( Model1 != Model3 )==true, test_desc + test_false_notequal, __LINE__ );
144 
145  return( test2.countFails() );
146 }
147 
148 
149 //------------------------------------------------------------
150 // Assert quality of class IonoModel method isValid()
151 //------------------------------------------------------------
153 {
154  TestUtil test3( "IonoModel", "isValid", __FILE__, __LINE__ );
155  std::string test_desc = "";
156  std::string test_fail = "";
157 
158  //Instantiate a blank almanac
159  gnsstk::EngAlmanac blankAlmanac;
160 
161  //Create an alpha and a beta array which define the Ionospheric model
162  double a[4] = {1.,2.,3.,4.};
163  double b[4] = {4.,3.,2.,1.};
164 
165  //---------------------------------
166  //Test to see if various IonoModel instantiations are valid
167  //---------------------------------
168 
169  // Construct with no inputs
170  test_desc = "IonoModel object created with no input parameters";
171  test_fail = "should result in an invalid model but did not";
172  gnsstk::IonoModel model_withNoParam;
173  test3.assert( !model_withNoParam.isValid(), test_desc + test_fail, __LINE__ );
174 
175  // Construct with multiple inputs
176  test_desc = "IonoModel object created with multiple inputs";
177  test_fail = "should result in a valid model but did not";
178  gnsstk::IonoModel model_withArray(a,b);
179  test3.assert( model_withArray.isValid(), test_desc + test_fail, __LINE__ );
180 
181  // Construct with blank Alamanac as input
182  test_desc = "IonoModel object created with a blank EngAlamanac";
183  test_fail = "should result in an invalid model but did no";
184  gnsstk::IonoModel model_withblankAlmanac( blankAlmanac );
185  test3.assert( !model_withblankAlmanac.isValid(), test_desc + test_fail, __LINE__ );
186 
187  return( test3.countFails() );
188 }
189 
190 
191 //------------------------------------------------------------
192 // Test class Ionomodel, verify exceptions are thrown as expected
193 //------------------------------------------------------------
194 // Please note: As of June 29,2006 I have not found a way to get the blankAlmanac
195 // exception to throw the way I wanted it to. I have set it to assert fail so I can
196 // come back at a later date to fix it.
197 //------------------------------------------------------------
199 {
200  TestUtil test4( "IonoModel", "exception", __FILE__, __LINE__ );
201  std::string test_desc = "";
202  std::string test_fail = "";
203  std::string assert_message = "";
204 
205  //Default constructer for Almanac will give a blank almanac
206  gnsstk::EngAlmanac blankAlmanac;
207 
208  //Set DayTime to the current system time
209  gnsstk::CommonTime commonTime;
210 
211  //Use the default Geodetic constructer
212  gnsstk::Position rxgeo;
213 
214  //Set el and az to 0 for ease of testing
215  double svel = 0;
216  double svaz = 0;
217 
218  //Easy alpha and beta for Ionospheric testing
219  double a[4] = {1.,2.,3.,4.};
220  double b[4] = {4.,3.,2.,1.};
221  gnsstk::IonoModel Model(blankAlmanac);
222  gnsstk::IonoModel goodModel(a,b);
223 
224  //----------------------------------------
225  // getIon() exception handling test
226  //----------------------------------------
227  try
228  {
229  blankAlmanac.getIon(a,b);
230  assert_message = "blankAlmanac.getIon(), This test should have thrown an InvalidRequest exception";
231  test4.assert( false, assert_message, __LINE__ );
232  }
233  catch( gnsstk::InvalidRequest& exception_invalid )
234  {
235  assert_message = "blankAlmanac.getIon(), This test threw an InvalidRequest exception as expected";
236  test4.assert( true, assert_message , __LINE__ );
237  }
238  catch(...)
239  {
240  assert_message = "blankAlmanac.getIon(), This test should have thrown an InvalidRequest but threw a different type of exception";
241  test4.assert( false, assert_message , __LINE__ );
242  }
243 
244 
245  // //----------------------------------------
246  // // What is this? Commenting it out until someone else figures it out.
247  // //----------------------------------------
248  //
249  // try
250  // {
251  // //Questioning why this isnt failing auto fail for now
252  // CPPUNIT_ASSERT_ASSERTION_FAIL( CPPUNIT_ASSERT_THROW(gnsstk::IonoModel Model(blankAlmanac), gnsstk::Exception) );
253  // }
254  // catch( gnsstk::Exception& e )
255  // {
256  //
257  // }
258 
259  //----------------------------------------
260  try
261  {
262  Model.getCorrection( commonTime, rxgeo,svel, svaz, CarrierBand::L1 );
263  assert_message = "getCorrection(), This test should have thrown an InvalidIonoModel exception";
264  test4.assert( false, assert_message, __LINE__ );
265  }
266  catch( gnsstk::IonoModel::InvalidIonoModel& exception_invalid )
267  {
268  assert_message = "getCorrection(), This test threw an InvalidIonoModel exception as expected";
269  test4.assert( true, assert_message, __LINE__ );
270  }
271  catch(...)
272  {
273  assert_message = "getCorrection(), This test should have thrown an InvalidRequest but threw a different type of exception";
274  test4.assert( false, assert_message, __LINE__ );
275  }
276 
277  //----------------------------------------
278  try
279  {
280  goodModel.getCorrection( commonTime, rxgeo, svel, svaz, CarrierBand::L1 );
281  assert_message = "getCorrection( L1 ), This test should NOT throw an exception";
282  test4.assert( true, assert_message, __LINE__ );
283  }
284  catch(gnsstk::Exception& e)
285  {
286  assert_message = "getCorrection( L1 ), This test should NOT have thrown any exceptions but threw gnsstk::Exception";
287  test4.assert( false, assert_message, __LINE__ );
288  }
289  catch(...)
290  {
291  assert_message = "getCorrection( L1 ), This test should NOT have thrown any exceptions but threw one anyway";
292  test4.assert( false, assert_message, __LINE__ );
293  }
294 
295 
296  //----------------------------------------
297  try
298  {
299  goodModel.getCorrection( commonTime, rxgeo, svel, svaz, CarrierBand::L2 );
300  assert_message = "getCorrection( L2 ), This test should NOT throw an exception";
301  test4.assert( true, assert_message, __LINE__ );
302  }
303  catch( gnsstk::Exception& e )
304  {
305  assert_message = "getCorrection( L2 ), This test should NOT have thrown any exceptions but threw gnsstk::Exception";
306  test4.assert( false, assert_message, __LINE__ );
307  }
308  catch(...)
309  {
310  assert_message = "getCorrection( L2 ), This test should NOT have thrown any exceptions but threw one anyway";
311  test4.assert( false, assert_message, __LINE__ );
312  }
313 
314 
315  //----------------------------------------
316  try
317  {
318  goodModel.getCorrection( commonTime, rxgeo, 72., 45., CarrierBand::L1 );
319  assert_message = "getCorrection( commonTime,rxgeo,72.,45.,Model.L1 ), This test should NOT throw an exception";
320  test4.assert( true, assert_message, __LINE__ );
321  }
322  catch( gnsstk::Exception& e )
323  {
324  assert_message = "getCorrection( commonTime,rxgeo,72.,45.,Model.L1 ), This test should NOT have thrown any exceptions but threw gnsstk::Exception";
325  test4.assert( false, assert_message, __LINE__ );
326  }
327  catch(...)
328  {
329  assert_message = "getCorrection( commonTime,rxgeo,72.,45.,Model.L1 ), This test should NOT have thrown any exceptions but threw one anyway";
330  test4.assert( false, assert_message, __LINE__ );
331  }
332 
333  return( test4.countFails() );
334 }
335 
336 
337 //------------------------------------------------------------
338 // main()
339 //------------------------------------------------------------
340 int main( void )
341 {
342  int check, errorCounter = 0;
343  IonoModel_T testClass;
344 
345  check = testClass.getSetTest();
346  errorCounter += check;
347 
348  check = testClass.equalityTest();
349  errorCounter += check;
350 
351  check = testClass.nonEqualityTest();
352  errorCounter += check;
353 
354  check = testClass.validTest();
355  errorCounter += check;
356 
357  check = testClass.exceptionTest();
358  errorCounter += check;
359 
360  std::cout << "Total Failures for " << __FILE__ << ": " << errorCounter << std::endl;
361 
362  return( errorCounter );
363 }
IonoModel_T
Definition: IonoModel_T.cpp:45
gnsstk::TestUtil::countFails
int countFails(void)
Definition: TestUtil.hpp:771
IonoModel_T::nonEqualityTest
int nonEqualityTest(void)
Definition: IonoModel_T.cpp:125
gnsstk::TestUtil::assert
void assert(bool testExpression, const std::string &testMsg, const int lineNumber)
Definition: TestUtil.hpp:607
main
int main(void)
Definition: IonoModel_T.cpp:340
gnsstk::IonoModel::setModel
void setModel(const double a[4], const double b[4], const bool semicircle_units=true) noexcept
Definition: IonoModel.cpp:73
IonoModel_T::exceptionTest
int exceptionTest(void)
Definition: IonoModel_T.cpp:198
IonoModel_T::validTest
int validTest(void)
Definition: IonoModel_T.cpp:152
IonoModel_T::~IonoModel_T
~IonoModel_T()
Definition: IonoModel_T.cpp:49
IonoModel.hpp
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::CarrierBand::L2
@ L2
GPS L2, QZSS L2.
gnsstk::Exception
Definition: Exception.hpp:151
TUASSERT
#define TUASSERT(EXPR)
Definition: TestUtil.hpp:63
TestUtil.hpp
IonoModel_T::IonoModel_T
IonoModel_T()
Definition: IonoModel_T.cpp:48
gnsstk::EngAlmanac
Definition: EngAlmanac.hpp:71
TURETURN
#define TURETURN()
Definition: TestUtil.hpp:232
gnsstk::IonoModel::getCorrection
double getCorrection(const CommonTime &time, const Position &rxgeo, double svel, double svaz, CarrierBand band=CarrierBand::L1) const
Definition: IonoModel.cpp:96
IonoModel_T::equalityTest
int equalityTest(void)
Definition: IonoModel_T.cpp:98
gnsstk::CommonTime
Definition: CommonTime.hpp:84
gnsstk::EngAlmanac::getIon
void getIon(double a[4], double b[4]) const
Definition: EngAlmanac.cpp:360
gnsstk::CarrierBand::L1
@ L1
GPS L1, Galileo E1, SBAS L1, QZSS L1, BeiDou L1.
TUDEF
#define TUDEF(CLASS, METHOD)
Definition: TestUtil.hpp:56
gnsstk::IonoModel::isValid
bool isValid() const noexcept
Definition: IonoModel.hpp:118
gnsstk::IonoModel
Definition: IonoModel.hpp:70
std
Definition: Angle.hpp:142
gnsstk::Position
Definition: Position.hpp:136
IonoModel_T::getSetTest
int getSetTest(void)
Definition: IonoModel_T.cpp:62
gnsstk::IonoModel::getModel
bool getModel(double a[4], double b[4]) const noexcept
Definition: IonoModel.cpp:194
gnsstk::TestUtil
Definition: TestUtil.hpp:265


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:39