GPSZcount_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 "GPSZcount.hpp"
40 #include "TimeTag.hpp"
41 #include "TestUtil.hpp"
42 #include <iostream>
43 #include <fstream>
44 #include <string>
45 #include <iomanip>
46 #include <sstream>
47 
49 {
50 public:
51  GPSZcount_T() {eps = 1E-12;}
53 //=============================================================================
54 // initializationTest ensures the constructors set the values properly
55 //=============================================================================
57  {
58  gnsstk::TestUtil testFramework( "GPSZcount", "ConstructorExplicit2Inputs", __FILE__, __LINE__ );
59 
60  //--------------------------------------------------------------------
61  // Were the values set to expectation using the explicit
62  // constructor with week and zcount inputs?
63  //--------------------------------------------------------------------
64  // Initialize a valid GPSZcount object
65  try
66  {
67  gnsstk::GPSZcount validObject(10, 35);
68  testFramework.assert(true, "Valid object constructed", __LINE__);
69  testFramework.assert(validObject.getWeek() == 10 , "Explicit constructor could not set week properly" , __LINE__);
70  testFramework.assert(validObject.getZcount() == 35, "Explicit constructor could not set zcount properly", __LINE__);
71  testFramework.assert(validObject.getFullZcount() == 5242915 , "getFullZcount did not return the expected value" , __LINE__);
72  testFramework.assert(validObject.getTotalZcounts() == 4032035, "getTotalZcount did not return the expected value", __LINE__);
73  }
74  catch(...){testFramework.assert(false, "Valid object could not be constructed", __LINE__);}
75 
76  // Try to create an invalid week object (week < 0)
77  try
78  {
79  gnsstk::GPSZcount invalidWeek(-10, 35);
80  testFramework.assert(false, "Invalid week object could be constructed", __LINE__);
81  }
82  catch(gnsstk::InvalidParameter e){testFramework.assert(true, "Expected exception caught", __LINE__);}
83  catch(...){testFramework.assert(false, "Unexpected exception caught for creation of invalid week GPSZcount", __LINE__);}
84 
85  // Try to create an invalid zcount object with too high of a value (zcount > 403200)
86  try
87  {
88  gnsstk::GPSZcount invalidZcountHigh(10, 999999);
89  testFramework.assert(false, "Invalid zcount object could be constructed", __LINE__);
90  }
91  catch(gnsstk::InvalidParameter e){testFramework.assert(true, "Expected exception caught", __LINE__);}
92  catch(...){testFramework.assert(false, "Unexpected exception caught for creation of invalid zcount GPSZcount", __LINE__);}
93 
94 
95  // Try to create an invalid zcount object with too low of a value (zcount < 0)
96  try
97  {
98  gnsstk::GPSZcount invalidZcountHigh(10, -999999);
99  testFramework.assert(false, "Invalid zcount object could be constructed", __LINE__);
100  }
101  catch(gnsstk::InvalidParameter e){testFramework.assert(true, "Expected exception caught", __LINE__);}
102  catch(...){testFramework.assert(false, "Unexpected exception caught for creation of invalid zcount GPSZcount", __LINE__);}
103 
104 
105 
106  //--------------------------------------------------------------------
107  // Were the values set to expectation using the explicit
108  // constructor with FullZcount input?
109  //--------------------------------------------------------------------
110  testFramework.changeSourceMethod("ConstructorExplicit1Input");
111  // Initialize a valid GPSZcount object
112  try
113  {
114  int inputFullZcount = 1211600; // = 403200*3+2000 = 3 weeks 2000 zcount
115  gnsstk::GPSZcount validObject(inputFullZcount);
116  testFramework.assert(true, "Valid object constructed", __LINE__);
117  testFramework.assert(validObject.getWeek() == 2 , "Explicit constructor could not set week properly" , __LINE__);
118  testFramework.assert(validObject.getZcount() == 163024, "Explicit constructor could not set zcount properly", __LINE__);
119  testFramework.assert(validObject.getFullZcount() == 1211600 , "getFullZcount did not return the expected value" , __LINE__);
120  testFramework.assert(validObject.getTotalZcounts() == 969424, "getTotalZcount did not return the expected value", __LINE__);
121  }
122  catch(...){testFramework.assert(false, "Valid object could not be constructed", __LINE__);}
123 
124  // Try to create an invalid zcount object with too high of a value (403200+n*2^(20) <= FullZCount <= 524287+n*2^(20) for all non-negative integers n)
125  try
126  {
127  gnsstk::GPSZcount invalidZcountHigh(3548928);
128  testFramework.assert(false, "Invalid FullZCount object could be constructed", __LINE__);
129  }
130  catch(gnsstk::InvalidParameter e){testFramework.assert(true, "Expected exception caught", __LINE__);}
131  catch(...){testFramework.assert(false, "Unexpected exception caught for creation of invalid FullZCount GPSZcount", __LINE__);}
132 
133 
134  //--------------------------------------------------------------------
135  // Were the values set to expectation using the copy constructor?
136  //--------------------------------------------------------------------
137  testFramework.changeSourceMethod("ConstructorCopy");
138  // Initialize a valid GPSZcount object
139  try
140  {
141  gnsstk::GPSZcount validObject(10, 35);
142  gnsstk::GPSZcount Copy(validObject);
143  testFramework.assert(true, "Valid object constructed", __LINE__);
144  testFramework.assert(Copy.getWeek() == 10 , "Copy constructor could not set week properly" , __LINE__);
145  testFramework.assert(Copy.getZcount() == 35, "Copy constructor could not set zcount properly", __LINE__);
146  }
147  catch(...){testFramework.assert(false, "Copy constructor could not copy a valid GPSZcount object", __LINE__);}
148 
149  //--------------------------------------------------------------------
150  // Were the values set to expectation using the set operator?
151  //--------------------------------------------------------------------
152  testFramework.changeSourceMethod("OperatorSet");
153  // Initialize a valid GPSZcount object
154  try
155  {
156  gnsstk::GPSZcount validObject(10, 35);
157  gnsstk::GPSZcount Copy(11,25);
158  Copy = validObject;
159  testFramework.assert(true, "Valid object constructed", __LINE__);
160  testFramework.assert(Copy.getWeek() == 10 , "Set Operator could not set week properly" , __LINE__);
161  testFramework.assert(Copy.getZcount() == 35, "Set Operator could not set zcount properly", __LINE__);
162  }
163  catch(...){testFramework.assert(false, "Set Operator could not copy a valid GPSZcount object", __LINE__);}
164 
165 
166  //--------------------------------------------------------------------
167  // Were the values set to expectation using the set methods?
168  //--------------------------------------------------------------------
169  testFramework.changeSourceMethod("set");
170  // Initialize a valid GPSZcount object
171 
172  gnsstk::GPSZcount validObject(10, 35);
173  validObject.setWeek(9);
174  validObject.setZcount(1000);
175 
176  testFramework.assert(validObject.getWeek() == 9 , "setWeek() did not set week properly" , __LINE__);
177  testFramework.assert(validObject.getZcount() == 1000, "setZcount did not set zcount properly", __LINE__);
178 
179  try{validObject.setWeek(-100); testFramework.assert(false, "setWeek allowed an invalid week to be set", __LINE__);}
180  catch(gnsstk::InvalidParameter e){testFramework.assert(true, "Expected exception thrown", __LINE__);}
181  catch(...){testFramework.assert(false, "Unexpected exception thrown", __LINE__);}
182 
183  try{validObject.setZcount(-100); testFramework.assert(false, "setZcount allowed an invalid zcount to be set", __LINE__);}
184  catch(gnsstk::InvalidParameter e){testFramework.assert(true, "Expected exception thrown", __LINE__);}
185  catch(...){testFramework.assert(false, "Unexpected exception thrown", __LINE__);}
186 
187  try{validObject.setZcount(999999); testFramework.assert(false, "setZcount allowed an invalid zcount to be set", __LINE__);}
188  catch(gnsstk::InvalidParameter e){testFramework.assert(true, "Expected exception thrown", __LINE__);}
189  catch(...){testFramework.assert(false, "Unexpected exception thrown", __LINE__);}
190 
191  return testFramework.countFails();
192  }
193 
194 
195 
196 //=============================================================================
197 // addWeeksTest ensures the functionality of addWeeks
198 //=============================================================================
199  int addWeeksTest(void)
200  {
201  gnsstk::TestUtil testFramework( "GPSZcount", "addWeeks", __FILE__, __LINE__ );
202 
203  //--------------------------------------------------------------------
204  // Were the values set to expectation using the addWeeks?
205  //--------------------------------------------------------------------
206  // Increment the week
207  gnsstk::GPSZcount incWeek(10, 35);
208  incWeek.addWeeks(2);
209  testFramework.assert(incWeek.getWeek() == 12, "addWeeks() did not set week properly" , __LINE__);
210 
211  // Decrement the week
212  gnsstk::GPSZcount decWeek(10, 35);
213  decWeek.addWeeks(-2);
214  testFramework.assert(decWeek.getWeek() == 8, "addWeeks() did not set week properly" , __LINE__);
215 
216  // Try to make the week negative
217  try
218  {
219  gnsstk::GPSZcount invalidWeek(10, 35);
220  invalidWeek.addWeeks(-12);
221  testFramework.assert(false, "addWeeks() allowed for change to an invalid week" , __LINE__);
222  }
223  catch(gnsstk::InvalidRequest e){testFramework.assert(true, "Expected exception thrown", __LINE__);}
224  catch(...){testFramework.assert(false, "Unexpected exception thrown", __LINE__);}
225 
226  return testFramework.countFails();
227  }
228 
229 
230 
231 //=============================================================================
232 // addZcountsTest ensures the functionality of addZcounts
233 //=============================================================================
234  int addZcountsTest(void)
235  {
236  gnsstk::TestUtil testFramework( "GPSZcount", "addZcounts", __FILE__, __LINE__ );
237  //--------------------------------------------------------------------
238  // Were the values set to expectation using the addZcounts?
239  //--------------------------------------------------------------------
240  // Increment the zcount
241  gnsstk::GPSZcount incZcount(10, 35);
242  incZcount.addZcounts(2L);
243  testFramework.assert(incZcount.getZcount() == 37, "addZcounts() did not set zcount properly" , __LINE__);
244 
245  // Decrement the zcount
246  gnsstk::GPSZcount decZcount(10, 35);
247  decZcount.addZcounts(-2L);
248  testFramework.assert(decZcount.getZcount() == 33, "addZcounts() did not set zcount properly" , __LINE__);
249 
250  // Roll the week forward
251  gnsstk::GPSZcount rollWeekF(10, 403198);
252  rollWeekF.addZcounts(4L);
253  testFramework.assert(rollWeekF.getWeek() == 11 , "addZcounts() did not roll week forward properly", __LINE__);
254  testFramework.assert(rollWeekF.getZcount() == 2, "addZcounts() did not set zcount properly" , __LINE__);
255 
256  // Roll the week backward
257  gnsstk::GPSZcount rollWeekB(10, 0);
258  rollWeekB.addZcounts(-2L);
259  testFramework.assert(rollWeekB.getWeek() == 9 , "addZcounts() did not roll week backward properly", __LINE__);
260  testFramework.assert(rollWeekB.getZcount() == 403198, "addZcounts() did not set zcount properly" , __LINE__);
261 
262  // Try to make the week negative
263  try
264  {
265  gnsstk::GPSZcount invalidWeek(0, 35);
266  invalidWeek.addZcounts(-42);
267  testFramework.assert(false, "addZcounts() allowed for change to an invalid week" , __LINE__);
268  }
269  catch(gnsstk::InvalidRequest e){testFramework.assert(true, "Expected exception thrown", __LINE__);}
270  catch(...){testFramework.assert(false, "Unexpected exception thrown", __LINE__);}
271 
272  return testFramework.countFails();
273  }
274 
275 
276 
277 //=============================================================================
278 // incrementTest ensures the functionality of addWeeks
279 //=============================================================================
280  int incrementTest(void)
281  {
282  gnsstk::TestUtil testFramework( "GPSZcount", "OperatorIncrement", __FILE__, __LINE__ );
283 
284  // Increment the zcount
285  gnsstk::GPSZcount arbitraryObject(10, 35);
286  arbitraryObject++;
287  testFramework.assert(arbitraryObject.getZcount() == 36, "Postfix Increment operator did not set zcount properly" , __LINE__);
288  ++arbitraryObject;
289  testFramework.assert(arbitraryObject.getZcount() == 37, "Prefix Increment operator did not set zcount properly" , __LINE__);
290 
291  // Roll the week forward
292  gnsstk::GPSZcount rollWeekF(10, 403199);
293  rollWeekF++;
294  testFramework.assert(rollWeekF.getWeek() == 11 , "Postfix Increment operator did not roll week forward properly", __LINE__);
295  testFramework.assert(rollWeekF.getZcount() == 0, "Postfix Increment operator did not set zcount properly" , __LINE__);
296 
297  // Roll the week forward
298  gnsstk::GPSZcount rollWeekF2(10, 403199);
299  ++rollWeekF2;
300  testFramework.assert(rollWeekF2.getWeek() == 11 , "Postfix Increment operator did not roll week forward properly", __LINE__);
301  testFramework.assert(rollWeekF2.getZcount() == 0, "Postfix Increment operator did not set zcount properly" , __LINE__);
302 
303  return testFramework.countFails();
304  }
305 
306 
307 //=============================================================================
308 // decrementTest ensures the functionality of addWeeks
309 //=============================================================================
310  int decrementTest(void)
311  {
312  gnsstk::TestUtil testFramework( "GPSZcount", "OperatorDecrement", __FILE__, __LINE__ );
313 
314  // Decrement the zcount
315  gnsstk::GPSZcount arbitraryObject(10, 35);
316  arbitraryObject--;
317  testFramework.assert(arbitraryObject.getZcount() == 34, "Postfix Decrement operator did not set zcount properly" , __LINE__);
318  --arbitraryObject;
319  testFramework.assert(arbitraryObject.getZcount() == 33, "Prefix Decrement operator did not set zcount properly" , __LINE__);
320 
321  // Roll the week backward
322  gnsstk::GPSZcount rollWeekB(10, 0);
323  rollWeekB--;
324  testFramework.assert(rollWeekB.getWeek() == 9 , "Postfix Decrement operator did not roll week forward properly", __LINE__);
325  testFramework.assert(rollWeekB.getZcount() == 403199, "Postfix Decrement operator did not set zcount properly" , __LINE__);
326 
327  // Roll the week backward
328  gnsstk::GPSZcount rollWeekB2(10, 0);
329  --rollWeekB2;
330  testFramework.assert(rollWeekB2.getWeek() == 9 , "Postfix Decrement operator did not roll week forward properly", __LINE__);
331  testFramework.assert(rollWeekB2.getZcount() == 403199, "Postfix Decrement operator did not set zcount properly" , __LINE__);
332 
333  return testFramework.countFails();
334  }
335 
336 
337 
338 //=============================================================================
339 // additionTest ensures the functionality of the addition operators
340 //=============================================================================
341  int additionTest(void)
342  {
343  gnsstk::TestUtil testFramework( "GPSZcount", "OperatorAddition", __FILE__, __LINE__ );
344  // Add to the zcount
345  gnsstk::GPSZcount justAddition(10, 35);
346  gnsstk::GPSZcount additionAssign(15, 1000);
347  justAddition = justAddition + 35;
348  additionAssign += 4000;
349 
350  testFramework.assert(justAddition.getZcount() == 70, "Addition operator did not set zcount properly" , __LINE__);
351  testFramework.assert(additionAssign.getZcount() == 5000, "Add and assign operator did not set zcount properly" , __LINE__);
352 
353 
354  // Roll the week forward
355  gnsstk::GPSZcount justAdditionRollWeekF(10, 403199);
356  justAdditionRollWeekF = justAdditionRollWeekF + 1000;
357  testFramework.assert(justAdditionRollWeekF.getWeek() == 11 , "Addition operator did not roll week forward properly", __LINE__);
358  testFramework.assert(justAdditionRollWeekF.getZcount() == 999, "Addition operator did not set zcount properly" , __LINE__);
359 
360  gnsstk::GPSZcount additionAssignRollWeekF(4, 403199);
361  additionAssignRollWeekF += 2000;
362  testFramework.assert(additionAssignRollWeekF.getWeek() == 5 , "Add and assign operator did not roll week forward properly", __LINE__);
363  testFramework.assert(additionAssignRollWeekF.getZcount() == 1999, "Add and assign operator did not set zcount properly" , __LINE__);
364 
365 
366  return testFramework.countFails();
367  }
368 
369 
370 //=============================================================================
371 // subtractionTest ensures the functionality of the Subtraction operators
372 //=============================================================================
373  int subtractionTest(void)
374  {
375  gnsstk::TestUtil testFramework( "GPSZcount", "OperatorSubtraction", __FILE__, __LINE__ );
376  // Subtract from the zcount
377  gnsstk::GPSZcount justSubtraction(10, 35);
378  gnsstk::GPSZcount subtractionAssign(15, 1000);
379  justSubtraction = justSubtraction - 15;
380  subtractionAssign -= 500;
381 
382  testFramework.assert(justSubtraction.getZcount() == 20, "Subtraction operator did not set zcount properly" , __LINE__);
383  testFramework.assert(subtractionAssign.getZcount() == 500, "Subtract and assign operator did not set zcount properly" , __LINE__);
384 
385  // Roll the week backward
386  gnsstk::GPSZcount justSubtractionRollWeekB(10, 0);
387  justSubtractionRollWeekB = justSubtractionRollWeekB - 100;
388  testFramework.assert(justSubtractionRollWeekB.getWeek() == 9 , "Subtraction operator did not roll week forward properly", __LINE__);
389  testFramework.assert(justSubtractionRollWeekB.getZcount() == 403100, "Subtraction operator did not set zcount properly" , __LINE__);
390 
391  // Roll the week backward
392  gnsstk::GPSZcount subtractionAssignRollWeekB(2, 0);
393  subtractionAssignRollWeekB -= 200;
394  testFramework.assert(subtractionAssignRollWeekB.getWeek() == 1 , "Subtract and assign operator did not roll week forward properly", __LINE__);
395  testFramework.assert(subtractionAssignRollWeekB.getZcount() == 403000, "Subtract and assign operator did not set zcount properly" , __LINE__);
396 
397 
398  return testFramework.countFails();
399  }
400 
401 
402 
403 //=============================================================================
404 // differenceTest ensures the functionality of the Subtraction
405 // operator between two GPSZcount objects
406 //=============================================================================
407  int differenceTest(void)
408  {
409  gnsstk::TestUtil testFramework( "GPSZcount", "OperatorDifference", __FILE__, __LINE__ );
410 
411  // Find the zcount difference between the two objects
412  double diffLessThan, diffMoreThan, diffSame;
413 
414  gnsstk::GPSZcount object(10, 35);
415  gnsstk::GPSZcount lessThanObject(4, 13);
416  gnsstk::GPSZcount objectCopy(object);
417  gnsstk::GPSZcount moreThanObject(15, 1000);
418 
419  diffLessThan = object - lessThanObject;
420  diffMoreThan = object - moreThanObject;
421  diffSame = object - objectCopy;
422 
423  testFramework.assert(diffLessThan == 2419222, "Difference operator did not obtain the correct result" , __LINE__);
424  testFramework.assert(diffMoreThan == -2016965, "Difference operator did not obtain the correct result" , __LINE__);
425  testFramework.assert(diffSame == 0, "Difference operator did not obtain the correct result" , __LINE__);
426 
427 
428  return testFramework.countFails();
429  }
430 
431 
432 //=============================================================================
433 // remainderTest ensures the functionality of the remainder operator
434 //=============================================================================
435  int remainderTest(void)
436  {
437  gnsstk::TestUtil testFramework( "GPSZcount", "OperatorRemainder", __FILE__, __LINE__ );
438 
439  // Find the zcount remainder between the object and some test values
440  long remaiderWeek, remainderValue;
441 
442  gnsstk::GPSZcount object(10, 25);
443 
444  remaiderWeek = object % 403200;
445  remainderValue = object % 25;
446 
447  testFramework.assert(remaiderWeek == 25, "Remainder operator did not obtain the correct result" , __LINE__);
448  testFramework.assert(remainderValue == 0, "Remainder operator did not obtain the correct result" , __LINE__);
449 
450 
451  return testFramework.countFails();
452  }
453 
454 
455 //=============================================================================
456 // comparisonTest ensures the functionality of the comparison operators
457 //=============================================================================
458  int comparisonTest(void)
459  {
460  gnsstk::TestUtil testFramework( "GPSZcount", "OperatorEquivalence", __FILE__, __LINE__ );
461 
462  gnsstk::GPSZcount Compare(10, 25);
463  gnsstk::GPSZcount LessThanWeek(9,25);
464  gnsstk::GPSZcount LessThanZcount(10,12);
465  gnsstk::GPSZcount CompareCopy(Compare);
466 
467  //--------------------------------------------------------------------
468  // Does the == Operator function?
469  //--------------------------------------------------------------------
470  testFramework.assert( Compare == CompareCopy, "Equivalence operator found equivalent objects to be not equivalent", __LINE__);
471  testFramework.assert(!(Compare == LessThanWeek), "Equivalence operator found different week objects to be equivalent", __LINE__);
472  testFramework.assert(!(Compare == LessThanZcount), "Equivalence operator found different zcount objects to be equivalent", __LINE__);
473 
474 
475  testFramework.changeSourceMethod("OperatorNotEquivalent");
476  //--------------------------------------------------------------------
477  // Does the != Operator function?
478  //--------------------------------------------------------------------
479  testFramework.assert( Compare != LessThanWeek, "Not-equal operator found different week objects to be equivalent", __LINE__);
480  testFramework.assert( Compare != LessThanZcount, "Not-equal operator found different zcount objects to be equivalent", __LINE__);
481  testFramework.assert(!(Compare != Compare), "Not-equal operator found equivalent objects to not be equivalent", __LINE__);
482 
483 
484  testFramework.changeSourceMethod("OperatorLessThan");
485  //--------------------------------------------------------------------
486  // Does the < Operator function?
487  //--------------------------------------------------------------------
488  testFramework.assert( LessThanWeek < Compare, "Less-than operator found less-than week object to not be less than", __LINE__);
489  testFramework.assert( LessThanZcount < Compare, "Less-than operator found less-than zcount object to not be less than", __LINE__);
490  testFramework.assert(!(Compare < LessThanWeek), "Less-than operator found greater-than week object to be less than", __LINE__);
491  testFramework.assert(!(Compare < LessThanZcount), "Less-than operator found greater-than zcount object to be less than", __LINE__);
492  testFramework.assert(!(Compare < CompareCopy), "Less-than operator found equivalent object to be less than", __LINE__);
493 
494  testFramework.changeSourceMethod("OperatorGreaterThan");
495  //--------------------------------------------------------------------
496  // Does the > Operator function?
497  //--------------------------------------------------------------------
498  testFramework.assert(!(LessThanWeek > Compare), "Greater-than operator found less-than week object to be greater than", __LINE__);
499  testFramework.assert(!(LessThanZcount > Compare), "Greater-than operator found less-than zcount object to be greater than", __LINE__);
500  testFramework.assert( Compare > LessThanWeek, "Greater-than operator found greater-than week object to not be greater than", __LINE__);
501  testFramework.assert( Compare > LessThanZcount, "Greater-than operator found greater-than zcount object to not be greater than", __LINE__);
502  testFramework.assert(!(Compare > CompareCopy), "Greater-than operator found equivalent object to be greater than", __LINE__);
503 
504 
505  testFramework.changeSourceMethod("OperatorLessThanOrEqualTo");
506  //--------------------------------------------------------------------
507  // Does the <= Operator function?
508  //--------------------------------------------------------------------
509  testFramework.assert( LessThanWeek <= Compare, "Less-than operator found less-than week object to not be less-than-or-equal-to", __LINE__);
510  testFramework.assert( LessThanZcount <= Compare, "Less-than operator found less-than zcount object to not be less-than-or-equal-to", __LINE__);
511  testFramework.assert(!(Compare <= LessThanWeek), "Less-than operator found greater-than week object to be less-than-or-equal-to", __LINE__);
512  testFramework.assert(!(Compare <= LessThanZcount), "Less-than operator found greater-than zcount object to be less-than-or-equal-to", __LINE__);
513  testFramework.assert( Compare <= CompareCopy, "Less-than operator found equivalent object to not be less-than-or-equal-to", __LINE__);
514 
515 
516  testFramework.changeSourceMethod("OperatorGreaterThanOrEqualTo");
517  //--------------------------------------------------------------------
518  // Does the >= Operator function?
519  //--------------------------------------------------------------------
520  testFramework.assert(!(LessThanWeek >= Compare), "Greater-than-or-equal-to operator found less-than week object to be greater-than-or-equal-to", __LINE__);
521  testFramework.assert(!(LessThanZcount >= Compare), "Greater-than-or-equal-to operator found less-than zcount object to be greater-than-or-equal-to", __LINE__);
522  testFramework.assert( Compare >= LessThanWeek, "Greater-than-or-equal-to operator found greater-than week object to not be greater-than-or-equal-to", __LINE__);
523  testFramework.assert( Compare >= LessThanZcount, "Greater-than-or-equal-to operator found greater-than zcount object to not be greater-than-or-equal-to", __LINE__);
524  testFramework.assert( Compare >= CompareCopy, "Greater-than-or-equal-to operator found equivalent object to not be greater-than-or-equal-to", __LINE__);
525 
526 
527  return testFramework.countFails();
528  }
529 
530 
531 //=============================================================================
532 // stringTest ensures the functionality of the string operator
533 //=============================================================================
534  int stringTest(void)
535  {
536  gnsstk::TestUtil testFramework( "GPSZcount", "OperatorString", __FILE__, __LINE__ );
537 
538  std::string expectedResult = "1234w56789z";
539  gnsstk::GPSZcount object(1234, 56789);
540  std::string obtainedResult = std::string(object);
541 
542  testFramework.assert(obtainedResult == expectedResult, "string operator did not obtain the expected result", __LINE__);
543 
544  return testFramework.countFails();
545  }
546 
547 
548 //=============================================================================
549 // dumpTest ensures the functionality of the dump method
550 //=============================================================================
551  int dumpTest(void)
552  {
553  gnsstk::TestUtil testFramework( "GPSZcount", "dump", __FILE__, __LINE__ );
554 
555  std::stringstream obtainedOutputStreamLevel0;
556  std::stringstream obtainedOutputStreamLevel1;
557  std::stringstream expectedOutputStreamLevel0;
558  std::stringstream expectedOutputStreamLevel1;
559 
560  expectedOutputStreamLevel0 << "1234w56789z";
561  expectedOutputStreamLevel1 << "GPS Full Week: " << std::setw(6) << 1234 << std::endl
562  << "GPS Z-count: " << std::setw(6) << 56789 << std::endl;
563 
564  gnsstk::GPSZcount object(1234, 56789);
565  object.dump(obtainedOutputStreamLevel0, 0);
566  object.dump(obtainedOutputStreamLevel1, 1);
567 
568 
569  std::string testMessage = " did not obtain the expected result";
570  testFramework.assert(obtainedOutputStreamLevel0.str() == expectedOutputStreamLevel0.str(), "dump did not obtain the expected result", __LINE__);
571  testFramework.assert(obtainedOutputStreamLevel1.str() == expectedOutputStreamLevel1.str(), "dump did not obtain the expected result", __LINE__);
572  return testFramework.countFails();
573  }
574 
575 
576 //=============================================================================
577 // inSameTimeBlockTest ensures the functionality of the
578 // inSameTimeBlock method
579 //=============================================================================
581  {
582  gnsstk::TestUtil testFramework( "GPSZcount", "inSameTimeBlock", __FILE__, __LINE__ );
583 
584  gnsstk::GPSZcount compare(10,0);
585  gnsstk::GPSZcount oneWeekMinus1(10,403199);
586  gnsstk::GPSZcount compareOffset(10,20);
587  gnsstk::GPSZcount withinWeek(10, 1000);
588  gnsstk::GPSZcount oneWeek(11,0);
589  gnsstk::GPSZcount oneWeekOffset(11,10);
590  gnsstk::GPSZcount moreThanWeek(12,0);
591  gnsstk::GPSZcount withinMinuteOffset(10,50);
592 
593  bool isWithinMinute = compare.inSameTimeBlock(compareOffset, gnsstk::GPSZcount::ZCOUNT_MINUTE , 0);
594  bool isNotWithinMinute = !compare.inSameTimeBlock(withinWeek , gnsstk::GPSZcount::ZCOUNT_MINUTE , 0);
595  bool isWithinWeek = compare.inSameTimeBlock(withinWeek , gnsstk::GPSZcount::ZCOUNT_WEEK , 0);
596  bool isNotWithinWeek = !compare.inSameTimeBlock(oneWeekOffset, gnsstk::GPSZcount::ZCOUNT_WEEK , 0);
597 
598  // For times at 1 week, the comparison is done assuming close
599  // to week = 0, which is not any of these
600 
601  // Originally this was expected to be true, but it really
602  // shouldn't be. Week 11 is not in the same week as week 10.
604  bool isNearWeek = compare.inSameTimeBlock(oneWeekMinus1, gnsstk::GPSZcount::ZCOUNT_WEEK, gnsstk::GPSZcount::ZCOUNT_WEEK*10);
605  bool isWithin3Weeks = compare.inSameTimeBlock(moreThanWeek, gnsstk::GPSZcount::ZCOUNT_WEEK*3, gnsstk::GPSZcount::ZCOUNT_WEEK*10);
606 
607  bool isWithinMinuteOffset = compareOffset.inSameTimeBlock(withinMinuteOffset, gnsstk::GPSZcount::ZCOUNT_MINUTE , 20);
608  bool isWithinWeekOffset = compareOffset.inSameTimeBlock(oneWeekOffset , gnsstk::GPSZcount::ZCOUNT_WEEK , 20);
609 
610 
611  testFramework.assert(isWithinMinute , "Returned false when object difference is 20 and timeblock is 40" , __LINE__);
612  testFramework.assert(isNotWithinMinute , "Returned true when object difference is 1000 and timeblock is 40" , __LINE__);
613  testFramework.assert(isWithinWeek , "Returned false when object difference is 1000 and timeblock is 403200" , __LINE__);
614  testFramework.assert(!isAtWeek , "Returned true when object difference is 403200 and timeblock is 403200" , __LINE__);
615  testFramework.assert(isNearWeek , "Returned false when object difference is 403199 and timeblock is 403200" , __LINE__);
616  testFramework.assert(isNotWithinWeek , "Returned true when object difference is 403210 and timeblock is 403200" , __LINE__);
617  testFramework.assert(isWithin3Weeks , "Returned false when object difference is 806400 and timeblock is 1209600" , __LINE__);
618  testFramework.assert(isWithinMinuteOffset, "Returned false when object difference is 30 and shifted timeblock is 40" , __LINE__);
619  testFramework.assert(isWithinWeekOffset , "Returned false when object difference is 403190 and shifted timeblock is 403200", __LINE__);
620 
621 
622  return testFramework.countFails();
623  }
624 private:
625  double eps;
626 };
627 
628 int main() // Main function to initialize and run all tests above
629 {
630  int check, errorCounter = 0;
631  GPSZcount_T testClass;
632 
633  check = testClass.initializationTest();
634  errorCounter += check;
635 
636  check = testClass.addWeeksTest();
637  errorCounter += check;
638 
639  check = testClass.addZcountsTest();
640  errorCounter += check;
641 
642  check = testClass.incrementTest();
643  errorCounter += check;
644 
645  check = testClass.decrementTest();
646  errorCounter += check;
647 
648  check = testClass.additionTest();
649  errorCounter += check;
650 
651  check = testClass.subtractionTest();
652  errorCounter += check;
653 
654  check = testClass.differenceTest();
655  errorCounter += check;
656 
657  check = testClass.remainderTest();
658  errorCounter += check;
659 
660  check = testClass.comparisonTest();
661  errorCounter += check;
662 
663  check = testClass.inSameTimeBlockTest();
664  errorCounter += check;
665 
666  std::cout << "Total Failures for " << __FILE__ << ": " << errorCounter << std::endl;
667 
668  return errorCounter; // Return the total number of errors
669 }
gnsstk::TestUtil::countFails
int countFails(void)
Definition: TestUtil.hpp:771
gnsstk::TestUtil::assert
void assert(bool testExpression, const std::string &testMsg, const int lineNumber)
Definition: TestUtil.hpp:607
GPSZcount_T::differenceTest
int differenceTest(void)
Definition: GPSZcount_T.cpp:407
gnsstk::GPSZcount::addZcounts
GPSZcount & addZcounts(long inZcounts)
Definition: GPSZcount.cpp:153
gnsstk::GPSZcount::setZcount
GPSZcount & setZcount(long inZcount)
Definition: GPSZcount.cpp:102
gnsstk::GPSZcount::inSameTimeBlock
bool inSameTimeBlock(const GPSZcount &other, unsigned long inZcountBlock, unsigned long inZcountOffset=0)
Definition: GPSZcount.cpp:324
gnsstk::GPSZcount::getZcount
long getZcount() const
GPS Z-count accessor.
Definition: GPSZcount.hpp:117
GPSZcount.hpp
GPSZcount_T::remainderTest
int remainderTest(void)
Definition: GPSZcount_T.cpp:435
GPSZcount_T
Definition: GPSZcount_T.cpp:48
GPSZcount_T::subtractionTest
int subtractionTest(void)
Definition: GPSZcount_T.cpp:373
GPSZcount_T::addWeeksTest
int addWeeksTest(void)
Definition: GPSZcount_T.cpp:199
GPSZcount_T::decrementTest
int decrementTest(void)
Definition: GPSZcount_T.cpp:310
gnsstk::GPSZcount::ZCOUNT_WEEK
static const GNSSTK_EXPORT long ZCOUNT_WEEK
Z-counts per whole GPS week. (403200)
Definition: GPSZcount.hpp:85
gnsstk::TestUtil::changeSourceMethod
void changeSourceMethod(const std::string &newMethod)
Definition: TestUtil.hpp:785
TestUtil.hpp
gnsstk::GPSZcount
Definition: GPSZcount.hpp:75
gnsstk::GPSZcount::getWeek
short getWeek() const
GPS week accessor.
Definition: GPSZcount.hpp:113
GPSZcount_T::inSameTimeBlockTest
int inSameTimeBlockTest(void)
Definition: GPSZcount_T.cpp:580
gnsstk::GPSZcount::getFullZcount
long getFullZcount() const
Definition: GPSZcount.hpp:125
gnsstk::GPSZcount::setWeek
GPSZcount & setWeek(short inWeek)
Definition: GPSZcount.cpp:90
TimeTag.hpp
gnsstk::GPSZcount::getTotalZcounts
double getTotalZcounts() const
Definition: GPSZcount.hpp:131
GPSZcount_T::eps
double eps
Definition: GPSZcount_T.cpp:625
gnsstk::GPSZcount::ZCOUNT_MINUTE
static const GNSSTK_EXPORT long ZCOUNT_MINUTE
Z-counts per minute (40)
Definition: GPSZcount.hpp:79
gnsstk::GPSZcount::addWeeks
GPSZcount & addWeeks(short inWeeks)
Definition: GPSZcount.cpp:133
GPSZcount_T::incrementTest
int incrementTest(void)
Definition: GPSZcount_T.cpp:280
GPSZcount_T::comparisonTest
int comparisonTest(void)
Definition: GPSZcount_T.cpp:458
GPSZcount_T::initializationTest
int initializationTest(void)
Definition: GPSZcount_T.cpp:56
GPSZcount_T::dumpTest
int dumpTest(void)
Definition: GPSZcount_T.cpp:551
main
int main()
Definition: GPSZcount_T.cpp:628
GPSZcount_T::addZcountsTest
int addZcountsTest(void)
Definition: GPSZcount_T.cpp:234
gnsstk::TestUtil
Definition: TestUtil.hpp:265
GPSZcount_T::GPSZcount_T
GPSZcount_T()
Definition: GPSZcount_T.cpp:51
GPSZcount_T::stringTest
int stringTest(void)
Definition: GPSZcount_T.cpp:534
GPSZcount_T::additionTest
int additionTest(void)
Definition: GPSZcount_T.cpp:341
GPSZcount_T::~GPSZcount_T
~GPSZcount_T()
Definition: GPSZcount_T.cpp:52


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