IonoModelStore_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 "IonoModelStore.hpp"
41 #include "YDSTime.hpp"
42 #include <iostream>
43 
46 {
47 public:
48 
51 
54  { delete store; }
55 
57  int testAdd();
58  int testGet();
59  int testEdit();
60  int testClear();
61 
62 protected:
63 
68 
69  const double a[4] = {1.,2.,3.,4.};
70  const double b[4] = {5.,6.,7.,8.};
71 
73 };
74 
75 
77  : t1(2021, 123, 0.0),
78  t2(2021, 123, 300.0),
79  t3(2021, 123, 900.0),
80  t4(2021, 124, 0.0)
81 {
82 }
83 
84 
86 {
87  TUDEF( "IonoModelStore", "constructor/destructor" );
88 
90 
91  TUASSERTE( size_t, 0, store->size() );
92  TUASSERT( true == store->empty() );
93 
94  TUCATCH( delete store );
95 
96  TURETURN( );
97 }
98 
99 
101 {
102  TUDEF( "IonoModelStore", "addIonoModel" );
103 
105 
106  const gnsstk::IonoModel emptyModel;
107  const gnsstk::IonoModel validModel1(a, b);
108  const gnsstk::IonoModel validModel2(b, a);
109 
110  // Attempt to add an invalid IonoModel - should fail
111  TUASSERT( false == store->addIonoModel(t1, emptyModel) );
112  TUASSERTE( size_t, 0, store->size() );
115  // Post: { }
116 
117  // Add an initial, valid IonoModel - should succeed
118  TUASSERT( true == store->addIonoModel(t1, validModel1) );
119  TUASSERTE( size_t, 1, store->size() );
120  TUASSERT( t1 == store->getInitialTime() );
121  TUASSERT( t1 == store->getFinalTime() );
122  // Post: { (t1,m1) }
123 
124  // Add another, unique, valid IonoModel - should succeed
125  TUASSERT( true == store->addIonoModel(t3, validModel2) );
126  TUASSERTE( size_t, 2, store->size() );
127  TUASSERT( t1 == store->getInitialTime() );
128  TUASSERT( t3 == store->getFinalTime() );
129  // Post: { (t1,m1), (t3,m2) }
130 
131  // Attempt to add a non-unique IonoModel - should fail
132  TUASSERT( false == store->addIonoModel(t2, validModel1) );
133  TUASSERTE( size_t, 2, store->size() );
134  TUASSERT( t1 == store->getInitialTime() );
135  TUASSERT( t3 == store->getFinalTime() );
136  // Post: { (t1,m1), (t3,m2) }
137 
138  // Attempt to add another non-unique IonoModel - should fail
139  TUASSERT( false == store->addIonoModel(t4, validModel2) );
140  TUASSERTE( size_t, 2, store->size() );
141  TUASSERT( t1 == store->getInitialTime() );
142  TUASSERT( t3 == store->getFinalTime() );
143  // Post: { (t1,m1), (t3,m2) }
144 
145  // Add another, unique, valid IonoModel - should succeed
146  TUASSERT( true == store->addIonoModel(t2, validModel2) );
147  TUASSERTE( size_t, 3, store->size() );
148  TUASSERT( t1 == store->getInitialTime() );
149  TUASSERT( t3 == store->getFinalTime() );
150  // Post: { (t1,m1), (t2,m2), (t3,m2) }
151 
152  // Add another, unique, valid IonoModel - should succeed
153  TUASSERT( true == store->addIonoModel(t4, validModel1) );
154  TUASSERTE( size_t, 4, store->size() );
155  TUASSERT( t1 == store->getInitialTime() );
156  TUASSERT( t4 == store->getFinalTime() );
157  // Post: { (t1,m1), (t2,m2), (t3,m2), (t4,m1) }
158 
159  // Replace an existing model at t3 - should succeed
160  TUASSERT( true == store->addIonoModel(t3, validModel1) );
161  TUASSERTE( size_t, 4, store->size() );
162  TUASSERT( t1 == store->getInitialTime() );
163  TUASSERT( t4 == store->getFinalTime() );
164  // Post: { (t1,m1), (t2,m2), (t3,m1), (t4,m1) }
165 
166  // Replace an existing model at t3 - should succeed
167  TUASSERT( true == store->addIonoModel(t3, validModel2) );
168  TUASSERTE( size_t, 4, store->size() );
169  TUASSERT( t1 == store->getInitialTime() );
170  TUASSERT( t4 == store->getFinalTime() );
171  // Post: { (t1,m1), (t2,m2), (t3,m2), (t4,m1) }
172 
173  store->dump();
174 
175  TURETURN( );
176 }
177 
178 
180 {
181  TUDEF( "IonoModelStore", "getCorrection" );
182 
183  // This depends on successful execution of testAdd() above
184  // to populate store.
185  //
186  // Pre: { (t1,m1), (t2,m2), (t3,m2), (t4,m1) }
187 
188  const gnsstk::Position pos(-740290.0, -5457071.7, 3207245.6);
189 
190  double az = 123.0;
191  double el = 45.0;
192 
193  double correction;
194 
196 
197  // Attempt to get a correction before any data exists - should throw.
198  t -= 900.0;
199  TUTHROW( correction = store->getCorrection(t, pos, el, az) );
200 
201  // Get a correction at the first available time - should succeed.
202  t = t1;
203  TUCATCH( correction = store->getCorrection(t, pos, el, az) );
204 
205  // Get a correction at another valid time - should succeed.
206  t += 30.0;
207  TUCATCH( correction = store->getCorrection(t, pos, el, az) );
208 
209  // Get a correction at another valid time - should succeed.
210  t = t3;
211  TUCATCH( correction = store->getCorrection(t, pos, el, az) );
212 
213  // Get a correction past the last stored time - should succeed.
214  t = t4;
215  t += 900.0;
216  TUCATCH( correction = store->getCorrection(t, pos, el, az) );
217 
218  // Get a correction with unusual elevation - should succeed.
219  el = -87.6;
220  TUCATCH( correction = store->getCorrection(t, pos, el, az) );
221 
222  // Get a correction with unusual azimuth- should succeed.
223  el = 45.0;
224  az = -456.7;
225  TUCATCH( correction = store->getCorrection(t, pos, el, az) );
226 
227  TURETURN( );
228 }
229 
230 
232 {
233  TUDEF( "IonoModelStore", "edit" );
234 
235  // This depends on successful execution of testAdd() above
236  // to populate store.
237  //
238  // Pre: { (t1,m1), (t2,m2), (t3,m2), (t4,m1) }
239 
240  gnsstk::CommonTime first = t1;
241  gnsstk::CommonTime last = t4;
242 
243  // Call edit with a range encompassing all data - nothing should be removed.
244  first -= 900.0;
245  last += 900.0;
246  TUCATCH( store->edit(first, last) );
247  TUASSERTE( size_t, 4, store->size() );
248  TUASSERT( t1 == store->getInitialTime() );
249  TUASSERT( t4 == store->getFinalTime() );
250 
251  // Call edit with a range whose lower bound is between t1 and t2 - nothing should be removed.
252  first += 930.0;
253  TUCATCH( store->edit(first, last) );
254  TUASSERTE( size_t, 4, store->size() );
255  TUASSERT( t1 == store->getInitialTime() );
256  TUASSERT( t4 == store->getFinalTime() );
257  // Post: { (t1,m1), (t2,m2), (t3,m2), (t4,m1) }
258 
259  // Call edit with a range whose lower bound is exactly t2 - the first model should be removed.
260  first = t2;
261  TUCATCH( store->edit(first, last) );
262  TUASSERTE( size_t, 3, store->size() );
263  TUASSERT( t2 == store->getInitialTime() );
264  TUASSERT( t4 == store->getFinalTime() );
265  // Post: { (t2,m2), (t3,m2), (t4,m1) }
266 
267  // Call edit with a range whose upper bound is exactly t4 - nothing should be removed.
268  last = t4;
269  TUCATCH( store->edit(first, last) );
270  TUASSERTE( size_t, 3, store->size() );
271  TUASSERT( t2 == store->getInitialTime() );
272  TUASSERT( t4 == store->getFinalTime() );
273  // Post: { (t2,m2), (t3,m2), (t4,m1) }
274 
275  // Call edit with a range whose upper bound is just before t4 - the last model should be removed.
276  last -= 1.0;
277  TUCATCH( store->edit(first, last) );
278  TUASSERTE( size_t, 2, store->size() );
279  TUASSERT( t2 == store->getInitialTime() );
280  TUASSERT( t3 == store->getFinalTime() );
281  // Post: { (t2,m2), (t3,m2) }
282 
283  TURETURN( );
284 }
285 
287 {
288  TUDEF( "IonoModelStore", "clear" );
289 
290  // This depends on successful execution of testEdit() above
291  // to populate store.
292  //
293  // Pre: { (t2,m2), (t3,m2) }
294 
295  TUASSERT( false == store->empty() );
296  TUCATCH( store->clear() );
297  TUASSERTE( size_t, 0, store->size() );
298  TUASSERT( true == store->empty() );
301  // Post: { }
302 
303  TURETURN( );
304 }
305 
306 
308 int main()
309 {
310  IonoModelStoreTest tester;
311 
312  int errorCount = 0; // Total number of errors
313 
314  errorCount += tester.testConstructDestruct();
315  errorCount += tester.testAdd();
316  errorCount += tester.testGet();
317  errorCount += tester.testEdit();
318  errorCount += tester.testClear();
319 
320  std::cout << "Total Failures for " << __FILE__ << ": "
321  << errorCount << std::endl;
322 
323  return errorCount;
324 }
YDSTime.hpp
IonoModelStoreTest::testEdit
int testEdit()
Definition: IonoModelStore_T.cpp:231
TUCATCH
#define TUCATCH(STATEMENT)
Definition: TestUtil.hpp:193
gnsstk::YDSTime
Definition: YDSTime.hpp:58
TUASSERTE
#define TUASSERTE(TYPE, EXP, GOT)
Definition: TestUtil.hpp:81
gnsstk::IonoModelStore::dump
virtual void dump(std::ostream &s=std::cout) const
Definition: IonoModelStore.cpp:157
gnsstk::CommonTime::BEGINNING_OF_TIME
static const GNSSTK_EXPORT CommonTime BEGINNING_OF_TIME
earliest representable CommonTime
Definition: CommonTime.hpp:102
IonoModelStoreTest::t1
const gnsstk::YDSTime t1
Definition: IonoModelStore_T.cpp:64
IonoModelStoreTest::~IonoModelStoreTest
~IonoModelStoreTest()
Default Destructor.
Definition: IonoModelStore_T.cpp:53
IonoModelStore.hpp
TUTHROW
#define TUTHROW(STATEMENT)
Definition: TestUtil.hpp:211
IonoModelStoreTest::testClear
int testClear()
Definition: IonoModelStore_T.cpp:286
gnsstk::IonoModelStore::clear
void clear()
Definition: IonoModelStore.hpp:113
gnsstk::CommonTime::END_OF_TIME
static const GNSSTK_EXPORT CommonTime END_OF_TIME
latest representable CommonTime
Definition: CommonTime.hpp:104
gnsstk::IonoModelStore::getInitialTime
virtual CommonTime getInitialTime() const
Definition: IonoModelStore.cpp:145
TUASSERT
#define TUASSERT(EXPR)
Definition: TestUtil.hpp:63
TestUtil.hpp
main
int main()
Main function to initialize and run the program.
Definition: IonoModelStore_T.cpp:308
gnsstk::IonoModelStore
Definition: IonoModelStore.hpp:62
IonoModelStoreTest
Test the IonoModelStore class.
Definition: IonoModelStore_T.cpp:45
TURETURN
#define TURETURN()
Definition: TestUtil.hpp:232
gnsstk::IonoModelStore::addIonoModel
bool addIonoModel(const CommonTime &mt, const IonoModel &im) noexcept
Definition: IonoModelStore.cpp:88
gnsstk::IonoModelStore::edit
void edit(const CommonTime &tmin, const CommonTime &tmax=CommonTime::END_OF_TIME)
Definition: IonoModelStore.cpp:117
gnsstk::CommonTime
Definition: CommonTime.hpp:84
gnsstk::IonoModelStore::getFinalTime
virtual CommonTime getFinalTime() const
Definition: IonoModelStore.cpp:151
IonoModelStoreTest::IonoModelStoreTest
IonoModelStoreTest()
Default Constructor.
Definition: IonoModelStore_T.cpp:76
gnsstk::IonoModelStore::size
virtual unsigned size() const
Definition: IonoModelStore.hpp:131
TUDEF
#define TUDEF(CLASS, METHOD)
Definition: TestUtil.hpp:56
example4.pos
pos
Definition: example4.py:125
IonoModelStoreTest::a
const double a[4]
Definition: IonoModelStore_T.cpp:69
IonoModelStoreTest::t2
const gnsstk::YDSTime t2
Definition: IonoModelStore_T.cpp:65
IonoModelStoreTest::testConstructDestruct
int testConstructDestruct()
Definition: IonoModelStore_T.cpp:85
gnsstk::IonoModel
Definition: IonoModel.hpp:70
IonoModelStoreTest::testGet
int testGet()
Definition: IonoModelStore_T.cpp:179
gnsstk::Position
Definition: Position.hpp:136
IonoModelStoreTest::t3
const gnsstk::YDSTime t3
Definition: IonoModelStore_T.cpp:66
IonoModelStoreTest::b
const double b[4]
Definition: IonoModelStore_T.cpp:70
IonoModelStoreTest::t4
const gnsstk::YDSTime t4
Definition: IonoModelStore_T.cpp:67
gnsstk::IonoModelStore::getCorrection
virtual double getCorrection(const CommonTime &time, const Position &rxgeo, double svel, double svaz, CarrierBand band=CarrierBand::L1) const
Definition: IonoModelStore.cpp:61
gnsstk::IonoModelStore::empty
virtual bool empty() const
Definition: IonoModelStore.hpp:137
IonoModelStoreTest::store
gnsstk::IonoModelStore * store
Definition: IonoModelStore_T.cpp:72
IonoModelStoreTest::testAdd
int testAdd()
Definition: IonoModelStore_T.cpp:100


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