IRNWeekSecond_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 "IRNWeekSecond.hpp"
40 #include "TimeTag.hpp"
41 #include "TestUtil.hpp"
42 #include "StringUtils.hpp"
43 #include <iostream>
44 #include <fstream>
45 #include <cmath>
46 using namespace gnsstk;
47 using namespace std;
48 
49 
51 {
52 public:
55 
56  // initializationTest ensures the constructors set the values properly
57  unsigned initializationTest()
58  {
59  TUDEF("IRNWeekSecond", "Constructor");
60 
61  IRNWeekSecond compare(1300,13500.,TimeSystem::IRN); //Initialize an object
62  //--------------------------------------------------------------------
63  //Were the attributes set to expectation with the explicit
64  //constructor?
65  //--------------------------------------------------------------------
66  TUASSERTE(int, 1300, compare.week);
67  TUASSERTFE(13500, compare.sow);
69 
70 
71  testFramework.changeSourceMethod("ConstructorCopy");
72  IRNWeekSecond copy(compare); // Initialize with copy constructor
73  //--------------------------------------------------------------------
74  //Were the attributes set to expectation with the copy constructor?
75  //--------------------------------------------------------------------
76  TUASSERTE(int, 1300, copy.week);
77  TUASSERTFE(13500, copy.sow);
79 
80  testFramework.changeSourceMethod("operator=");
81  IRNWeekSecond assigned;
82  assigned = compare;
83  //--------------------------------------------------------------------
84  //Were the attributes set to expectation with the Set operator?
85  //--------------------------------------------------------------------
86  TUASSERTE(int, 1300, assigned.week);
87  TUASSERTFE(13500, assigned.sow);
89 
90  TURETURN();
91  }
92 
93 
94  // Test will check if IRNWeekSecond variable can be set from a map.
95  // Test also implicity tests whether the != operator functions.
96  unsigned setFromInfoTest()
97  {
98  TUDEF("IRNWeekSecond", "setFromInfo");
99 
100  IRNWeekSecond setFromInfo1;
101  IRNWeekSecond setFromInfo2;
102  IRNWeekSecond setFromInfo3;
104  id['O'] = "1300";
105  id['g'] = "13500";
106  id['P'] = "IRN";
107  IRNWeekSecond compare(1300,13500.,TimeSystem::IRN); //Initialize an object
108  //--------------------------------------------------------------------
109  //Does a proper setFromInfo work with all information provided?
110  //--------------------------------------------------------------------
111  TUASSERT(setFromInfo1.setFromInfo(id));
112  TUASSERTE(IRNWeekSecond, compare, setFromInfo1);
113 
114  id.erase('O');
115  IRNWeekSecond compare2(0,13500.,TimeSystem::IRN);
116  //--------------------------------------------------------------------
117  //Does a proper setFromInfo work with missing data?
118  //--------------------------------------------------------------------
119  TUASSERT(setFromInfo2.setFromInfo(id));
120  TUASSERTE(IRNWeekSecond, compare2, setFromInfo2);
121 
122  TURETURN();
123  }
124 
125 
126  // Test will check if the ways to initialize and set an
127  // IRNWeekSecond object. Test also tests whether the comparison
128  // operators and isValid method function.
129  unsigned operatorTest()
130  {
131  TUDEF("IRNWeekSecond", "operator==");
132 
133  IRNWeekSecond compare(1300,13500.);
134  IRNWeekSecond lessThanWeek(1299,13500.);
135  IRNWeekSecond lessThanSecond(1300,13400.);
136  IRNWeekSecond compareCopy(compare); // Initialize with copy constructor
137 
138  // TUASSERT is used below instead of TUASSERTE to make
139  // certain the right operator is being tested.
140 
141  //--------------------------------------------------------------------
142  //Does the == Operator function?
143  //--------------------------------------------------------------------
144  TUASSERT( compare == compareCopy);
145  TUASSERT(!(compare == lessThanWeek));
146  TUASSERT(!(compare == lessThanSecond));
147 
148  testFramework.changeSourceMethod("operator!=");
149  //--------------------------------------------------------------------
150  //Does the != Operator function?
151  //--------------------------------------------------------------------
152  TUASSERT( compare != lessThanWeek);
153  TUASSERT( compare != lessThanSecond);
154  TUASSERT(!(compare != compare));
155 
156  testFramework.changeSourceMethod("operator<");
157  //--------------------------------------------------------------------
158  //Does the < Operator function?
159  //--------------------------------------------------------------------
160  TUASSERT( lessThanWeek < compare);
161  TUASSERT( lessThanSecond < compare);
162  TUASSERT(!(compare < lessThanWeek));
163  TUASSERT(!(compare < lessThanSecond));
164  TUASSERT(!(compare < compareCopy));
165 
166  testFramework.changeSourceMethod("operator>");
167  //--------------------------------------------------------------------
168  //Does the > Operator function?
169  //--------------------------------------------------------------------
170  TUASSERT(!(lessThanWeek > compare));
171  TUASSERT(!(lessThanSecond > compare));
172  TUASSERT( compare > lessThanWeek);
173  TUASSERT( compare > lessThanSecond);
174  TUASSERT(!(compare > compareCopy));
175 
176  testFramework.changeSourceMethod("operator<=");
177  //--------------------------------------------------------------------
178  //Does the <= Operator function?
179  //--------------------------------------------------------------------
180  TUASSERT( lessThanWeek <= compare);
181  TUASSERT( lessThanSecond <= compare);
182  TUASSERT(!(compare <= lessThanWeek));
183  TUASSERT(!(compare <= lessThanSecond));
184  TUASSERT( compare <= compareCopy);
185 
186  testFramework.changeSourceMethod("operator>=");
187  //--------------------------------------------------------------------
188  //Does the >= Operator function?
189  //--------------------------------------------------------------------
190  TUASSERT(!(lessThanWeek >= compare));
191  TUASSERT(!(lessThanSecond >= compare));
192  TUASSERT( compare >= lessThanWeek);
193  TUASSERT( compare >= lessThanSecond);
194  TUASSERT( compare >= compareCopy);
195 
196  TURETURN();
197  }
198 
199 
200  // Test the reset method.
201  unsigned resetTest()
202  {
203  TUDEF("IRNWeekSecond", "reset");
204 
205  IRNWeekSecond compare(1300,13500.,TimeSystem::IRN); //Initialize an object
206  compare.reset(); // Reset it
207 
208  //--------------------------------------------------------------------
209  //Were the attributes reset to expectation?
210  //--------------------------------------------------------------------
211  TUASSERTE(int, 0, compare.week);
212  TUASSERTFE(0, compare.sow);
214 
215  TURETURN();
216  }
217 
218 
219  // Test will check converting to/from CommonTime.
221  {
222  TUDEF("IRNWeekSecond", "isValid");
223 
224  IRNWeekSecond compare(0,10.0,TimeSystem::IRN); //Initialize an object
225  CommonTime truth;
226  long truthDay, truthSOD;
227  double truthFSOD;
228  truth.set(2451412, 43210,0.0,TimeSystem::IRN);
229 
230  //--------------------------------------------------------------------
231  //Is the time after the BEGINNING_OF_TIME?
232  //--------------------------------------------------------------------
234 
235  //--------------------------------------------------------------------
236  //Is the set object valid?
237  //--------------------------------------------------------------------
238  TUASSERT(compare.isValid());
239 
240  CommonTime test = compare.convertToCommonTime(); //Convert to CommonTime
241  long testDay, testSOD;
242  double testFSOD;
243  test.get(testDay, testSOD, testFSOD);
244  truth.get(truthDay, truthSOD, truthFSOD);
245 
246  // Currently, IRNWeekSecond does not convert to proper CommonTime
247  // These tests will be valid and will be uncommented once issue_248 has been
248  // resolved and merged into master.
249  // TUASSERTE(long, truthDay, testDay);
250  // TUASSERTE(long, truthSOD, testSOD);
251  // TUASSERTFE(truthFSOD, testFSOD);
252 
253  IRNWeekSecond test2;
254  test2.convertFromCommonTime(test); //Convert From
255  testFramework.changeSourceMethod("CommonTimeConversion");
256  //--------------------------------------------------------------------
257  //Is the result of conversion the same?
258  //--------------------------------------------------------------------
259  TUASSERTE(TimeSystem, compare.getTimeSystem(), test2.getTimeSystem());
260  TUASSERTE(int, compare.week, test2.week);
261  TUASSERTFE(compare.sow, test2.sow);
262 
263  //TUASSERT(test2 == test);
264 
265  TURETURN();
266  }
267 
268 
269  // Test will check the TimeSystem comparisons when using the
270  // comparison operators.
271  unsigned timeSystemTest()
272  {
273  TUDEF("IRNWeekSecond", "OperatorEquivalentWithDifferingTimeSystem");
274 
275  IRNWeekSecond IRN1(1300,13500.,TimeSystem::IRN);
276  IRNWeekSecond IRN2(1200,13500.,TimeSystem::IRN);
277  IRNWeekSecond UTC1(1300,13500.,TimeSystem::QZS);
278  IRNWeekSecond UNKNOWN(1300,13500.,TimeSystem::Unknown);
279  IRNWeekSecond ANY(1300,13500.,TimeSystem::Any);
280  IRNWeekSecond ANY2(1200,13500.,TimeSystem::Any);
281 
282  //--------------------------------------------------------------------
283  //Verify differing TimeSystem sets equivalence operator to false
284  //Note that the operator test checks for == in ALL members
285  //--------------------------------------------------------------------
286  TUASSERT(!(IRN1 == UTC1));
287  TUASSERT(IRN1 == ANY);
288  TUASSERT(UTC1 == ANY);
289  TUASSERT(UNKNOWN == ANY);
290 
291  testFramework.changeSourceMethod(
292  "OperatorNotEquivalentWithDifferingTimeSystem");
293  //--------------------------------------------------------------------
294  //Verify different Time System but same time inequality
295  //--------------------------------------------------------------------
296  TUASSERT(IRN1 != UTC1);
297  TUASSERT(IRN1 != UNKNOWN);
298  TUASSERT(!(IRN1 != ANY));
299 
300  testFramework.changeSourceMethod(
301  "OperatorLessThanWithDifferingTimeSystem");
302  //--------------------------------------------------------------------
303  //Verify TimeSystem=ANY does not matter in other operator comparisons
304  //--------------------------------------------------------------------
305  TUASSERT(ANY2 < IRN1);
306  TUASSERT(IRN2 < ANY);
307 
308  testFramework.changeSourceMethod("setTimeSystem");
309  UNKNOWN.setTimeSystem(TimeSystem::IRN); //Set the Unknown TimeSystem
310  //--------------------------------------------------------------------
311  //Ensure resetting a Time System changes it
312  //--------------------------------------------------------------------
314 
315  TURETURN();
316  }
317 
318 
319  // Test for the formatted printing of IRNWeekSecond objects
320  unsigned printfTest()
321  {
322  TUDEF("IRNWeekSecond", "printf");
323 
324  IRNWeekSecond IRN1(1300,13500.,TimeSystem::IRN);
325  IRNWeekSecond UTC1(1300,13500.,TimeSystem::UTC);
326 
327  //--------------------------------------------------------------------
328  //Verify printed output matches expectation
329  //--------------------------------------------------------------------
330  TUASSERTE(string, "1300 13500.000000 IRN", IRN1.printf("%04O %05g %02P"));
331  TUASSERTE(string, "1300 13500.000000 UTC", UTC1.printf("%04O %05g %02P"));
332 
333  testFramework.changeSourceMethod("printError");
334 
335  //--------------------------------------------------------------------
336  //Verify printed error message matches expectation
337  //--------------------------------------------------------------------
338  TUASSERTE(string, "BadIRNepoch BadIRNmweek BadIRNdow BadIRNfweek BadIRNsow BadIRNsys", IRN1.printError("%X %o %w %04O %05g %02P"));
339  TUASSERTE(string, "BadIRNepoch BadIRNmweek BadIRNdow BadIRNfweek BadIRNsow BadIRNsys", UTC1.printError("%X %o %w %04O %05g %02P"));
340 
341  TURETURN();
342  }
343 };
344 
345 
346 int main() //Main function to initialize and run all tests above
347 {
348  unsigned errorTotal = 0;
349  IRNWeekSecond_T testClass;
350 
351  errorTotal += testClass.initializationTest();
352  errorTotal += testClass.operatorTest();
353  errorTotal += testClass.setFromInfoTest();
354  errorTotal += testClass.resetTest();
355  errorTotal += testClass.timeSystemTest();
356  errorTotal += testClass.toFromCommonTimeTest();
357  errorTotal += testClass.printfTest();
358 
359  cout << "Total Failures for " << __FILE__ << ": " << errorTotal << endl;
360 
361  return errorTotal; //Return the total number of errors
362 }
gnsstk::IRNWeekSecond::setFromInfo
bool setFromInfo(const IdToValue &info)
Definition: IRNWeekSecond.hpp:170
gnsstk::WeekSecond::convertToCommonTime
virtual CommonTime convertToCommonTime() const
Definition: WeekSecond.cpp:55
gnsstk::TimeTag::setTimeSystem
void setTimeSystem(const TimeSystem &timeSys)
Set method for internal variable timeSystem (enum).
Definition: TimeTag.hpp:165
gnsstk::TimeTag::IdToValue
std::map< char, std::string > IdToValue
Definition: TimeTag.hpp:103
StringUtils.hpp
IRNWeekSecond.hpp
gnsstk::WeekSecond::convertFromCommonTime
virtual void convertFromCommonTime(const CommonTime &ct)
Definition: WeekSecond.cpp:78
TUASSERTE
#define TUASSERTE(TYPE, EXP, GOT)
Definition: TestUtil.hpp:81
gnsstk::TimeSystem::Any
@ Any
wildcard; allows comparison with any other type
IRNWeekSecond_T::toFromCommonTimeTest
unsigned toFromCommonTimeTest()
Definition: IRNWeekSecond_T.cpp:220
gnsstk::CommonTime::BEGINNING_OF_TIME
static const GNSSTK_EXPORT CommonTime BEGINNING_OF_TIME
earliest representable CommonTime
Definition: CommonTime.hpp:102
gnsstk::TimeSystem::Unknown
@ Unknown
unknown time frame; for legacy code compatibility
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::WeekSecond::reset
virtual void reset()
Reset this object to the default state.
Definition: WeekSecond.cpp:105
gnsstk::WeekSecond::isValid
virtual bool isValid() const
Returns true if this object's members are valid, false otherwise.
Definition: WeekSecond.cpp:99
TUASSERT
#define TUASSERT(EXPR)
Definition: TestUtil.hpp:63
TestUtil.hpp
TURETURN
#define TURETURN()
Definition: TestUtil.hpp:232
gnsstk::TimeSystem::IRN
@ IRN
IRNSS system Time.
gnsstk::TimeSystem::QZS
@ QZS
QZSS system Time.
IRNWeekSecond_T::operatorTest
unsigned operatorTest()
Definition: IRNWeekSecond_T.cpp:129
gnsstk::CommonTime
Definition: CommonTime.hpp:84
gnsstk::WeekSecond::sow
double sow
Definition: WeekSecond.hpp:155
IRNWeekSecond_T::resetTest
unsigned resetTest()
Definition: IRNWeekSecond_T.cpp:201
gnsstk::IRNWeekSecond
Definition: IRNWeekSecond.hpp:56
gnsstk::TimeSystem
TimeSystem
Definition of various time systems.
Definition: TimeSystem.hpp:51
gnsstk::CommonTime::get
void get(long &day, long &sod, double &fsod, TimeSystem &timeSystem) const
Definition: CommonTime.cpp:213
gnsstk::Week::week
int week
Full week number.
Definition: Week.hpp:267
TimeTag.hpp
TUDEF
#define TUDEF(CLASS, METHOD)
Definition: TestUtil.hpp:56
gnsstk::TimeSystem::UTC
@ UTC
Coordinated Universal Time (e.g., from NTP)
IRNWeekSecond_T::printfTest
unsigned printfTest()
Definition: IRNWeekSecond_T.cpp:320
std
Definition: Angle.hpp:142
TUASSERTFE
#define TUASSERTFE(EXP, GOT)
Definition: TestUtil.hpp:103
IRNWeekSecond_T
Definition: IRNWeekSecond_T.cpp:50
IRNWeekSecond_T::initializationTest
unsigned initializationTest()
Definition: IRNWeekSecond_T.cpp:57
gnsstk::IRNWeekSecond::printf
virtual std::string printf(const std::string &fmt) const
Definition: IRNWeekSecond.hpp:115
IRNWeekSecond_T::setFromInfoTest
unsigned setFromInfoTest()
Definition: IRNWeekSecond_T.cpp:96
gnsstk::TimeTag::getTimeSystem
TimeSystem getTimeSystem() const
Obtain time system info (enum).
Definition: TimeTag.hpp:169
IRNWeekSecond_T::~IRNWeekSecond_T
~IRNWeekSecond_T()
Definition: IRNWeekSecond_T.cpp:54
main
int main()
Definition: IRNWeekSecond_T.cpp:346
gnsstk::IRNWeekSecond::printError
virtual std::string printError(const std::string &fmt) const
Definition: IRNWeekSecond.hpp:141
IRNWeekSecond_T::timeSystemTest
unsigned timeSystemTest()
Definition: IRNWeekSecond_T.cpp:271
IRNWeekSecond_T::IRNWeekSecond_T
IRNWeekSecond_T()
Definition: IRNWeekSecond_T.cpp:53
gnsstk::CommonTime::set
CommonTime & set(long day, long sod, double fsod=0.0, TimeSystem timeSystem=TimeSystem::Unknown)
Definition: CommonTime.cpp:87


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