TimeRange_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 <iostream>
40 #include <sstream>
41 #include <string>
42 #include <stdexcept>
43 #include "TestUtil.hpp"
44 #include "CivilTime.hpp"
45 #include "YDSTime.hpp"
46 #include "GPSWeekZcount.hpp"
47 #include "BasicFramework.hpp"
48 #include "TimeRange.hpp"
49 #include "CommonTime.hpp"
50 #include "Exception.hpp"
51 using namespace std;
52 using namespace gnsstk;
53 
54 
56 {
57 public:
59  {
60  eps = 1E-12;
61  }
63 
64  //=======================================================================
65  // Test for the TimeRange constructors
66  //=======================================================================
67  int constructorTest ( void )
68  {
69  TUDEF( "TimeRange", "Constructor" );
70  std::string outputFormat = CivilTime().getDefaultFormat();
71 
72 
73  //--------------------------------------------------------------------
74  // Verify default constructor does not throw errors and
75  // creates the expected object
76  //--------------------------------------------------------------------
77  try
78  {
79  TimeRange emptyConstructed;
80  testFramework.assert(true, "Construction of empty TimeRange object worked",
81  __LINE__);
82  }
83  catch (...)
84  {
85  testFramework.assert(false, "Construction of empty TimeRange object failed",
86  __LINE__);
87  }
88 
89  TimeRange emptyConstructed;
90  // Verify default constructor sets the proper values (This is
91  // important to verify the values in the copy constructor
92  // below.)
93  testFramework.assert(emptyConstructed.getStart() ==
95  "Start value for empty TimeRange is not the expected value", __LINE__);
96  testFramework.assert(emptyConstructed.getEnd() ==
98  "End value for empty TimeRange is not the expected value" , __LINE__);
99 
100 
101  //--------------------------------------------------------------------
102  // Verify copy constructor does not throw errors and creates
103  // the expected object
104  //--------------------------------------------------------------------
105  try
106  {
107  TimeRange copyConstructed(emptyConstructed);
108  testFramework.assert(true,
109  "Construction using TimeRange copy constructor worked", __LINE__);
110  }
111  catch (...)
112  {
113  testFramework.assert(false,
114  "Construction using TimeRange copy constructor failed", __LINE__);
115  }
116 
117  TimeRange copyConstructed(emptyConstructed);
118  testFramework.assert(emptyConstructed.getStart() ==
120  "Start value for copy constructed TimeRange is not the expected value",
121  __LINE__);
122  testFramework.assert(emptyConstructed.getEnd() ==
124  "End value for copy constructed TimeRange is not the expected value" ,
125  __LINE__);
126 
127 
128 
129 
130 
131  //--------------------------------------------------------------------
132  // Verify CommonTime constructor does throws expected errors
133  // and creates the expected object
134  //--------------------------------------------------------------------
135  CommonTime startEndpoint = gnsstk::CivilTime(2011,1, 1, 0, 0,
136  0.0).convertToCommonTime();
137  CommonTime endEndpoint = gnsstk::CivilTime(2011,1,31,23,59,
138  59.59).convertToCommonTime();
139  bool beginningIncluded = true;
140  bool endIncluded = false;
141 
142  // Verify CommonTime constructor does throw an error endpoint
143  // when times are inverted
144  try
145  {
146  TimeRange fourInputConstructed(endEndpoint,startEndpoint,beginningIncluded,
147  endIncluded);
148  testFramework.assert(false,
149  "CommonTime constructor allowed for the end time to be earlier than the start time",
150  __LINE__);
151  }
152  catch (Exception& e)
153  {
154  testFramework.assert(true, "CommonTime constructor threw the expected error",
155  __LINE__);
156  }
157  catch (...)
158  {
159  testFramework.assert(false,
160  "CommonTime constructor threw an unexpected error for when the end time is earlier than the start time",
161  __LINE__);
162  }
163 
164  // Verify CommonTime constructor does not throw errors when
165  // times are ok
166  try
167  {
168  TimeRange fourInputConstructed(startEndpoint,endEndpoint,beginningIncluded,
169  endIncluded);
170  testFramework.assert(true,
171  "CommonTime constructor for valid data functioned properly", __LINE__);
172  }
173  catch (...)
174  {
175  testFramework.assert(false,
176  "CommonTime constructor for valid data functioned threw an error", __LINE__);
177  }
178 
179  // Verify CommonTime constructor sets the proper values
180  // (Implies that CommonTime == comparisons work)
181  TimeRange fourInputConstructed(startEndpoint,endEndpoint,beginningIncluded,
182  endIncluded);
183  testFramework.assert(fourInputConstructed.getStart() == startEndpoint,
184  "CommonTime constructor did not set the start time properly", __LINE__);
185  testFramework.assert(fourInputConstructed.getEnd() == endEndpoint ,
186  "CommonTime constructor did not set the end time properly" , __LINE__);
187 
188 
189  //--------------------------------------------------------------------
190  // Verify CommonTime constructor does throws expected errors
191  // and creates the expected object
192  //--------------------------------------------------------------------
193  gnsstk::TimeRange::DTPair inputPair, invertedPair;
194  inputPair = std::make_pair(startEndpoint,endEndpoint);
195  invertedPair = std::make_pair(endEndpoint,startEndpoint);
196 
197  // Verify DTpair constructor does throw an error when
198  // endpoint times are inverted
199  try
200  {
201  TimeRange threeInputConstructed(invertedPair,beginningIncluded, endIncluded);
202  testFramework.assert(false,
203  "DTPair constructor allowed for the end time to be earlier than the start time",
204  __LINE__);
205  }
206  catch (Exception& e)
207  {
208  testFramework.assert(true, "DTPair constructor threw the expected error",
209  __LINE__);
210  }
211  catch (...)
212  {
213  testFramework.assert(false,
214  "DTPair constructor threw an unexpected error for when the end time is earlier than the start time",
215  __LINE__);
216  }
217 
218  // Verify DTpair constructor does not throw errors with
219  // proper inputs
220  try
221  {
222  TimeRange threeInputConstructed(inputPair,beginningIncluded, endIncluded);
223  testFramework.assert(true,
224  "DTPair constructor for valid data functioned properly", __LINE__);
225  }
226  catch (...)
227  {
228  testFramework.assert(false,
229  "DTPair constructor for valid data functioned threw an error", __LINE__);
230  }
231 
232  // Verify DTpair constructor sets the proper values (Implies
233  // that CommonTime == comparisons work)
234  TimeRange threeInputConstructed(inputPair,beginningIncluded, endIncluded);
235  testFramework.assert(threeInputConstructed.getStart() == startEndpoint,
236  "CommonTime constructor did not set the start time properly", __LINE__);
237  testFramework.assert(threeInputConstructed.getEnd() == endEndpoint ,
238  "CommonTime constructor did not set the end time properly" , __LINE__);
239 
240 
241  return testFramework.countFails();
242  }
243 
244 //=============================================================================
245 // Test for the inRange method
246 // If the target time occurs in the range, the method returns true.
247 // Additonal tests to ensure the endpoints respond properly depending
248 // on whether they are to be included in the range
249 //=============================================================================
250  int inRangeTest ( void )
251  {
252  TUDEF( "TimeRange", "inRange" );
253 
254 
255  CommonTime earlierThanRange = gnsstk::CivilTime(2010,12,20, 0, 0,
256  0.0 ).convertToCommonTime();
257  CommonTime startEndpoint = gnsstk::CivilTime(2011, 1, 1, 0, 0,
258  0.0 ).convertToCommonTime();
259  CommonTime timeInRange = gnsstk::CivilTime(2011, 1,20, 0, 0,
260  0.0 ).convertToCommonTime();
261  CommonTime endEndpoint = gnsstk::CivilTime(2011, 1,31,23,59,
262  59.59).convertToCommonTime();
263  CommonTime laterThanRange = gnsstk::CivilTime(2011, 2,20, 0, 0,
264  0.0 ).convertToCommonTime();
265 
266  //Create a TimeRange where both ends are included
267  bool beginningIncluded = true;
268  bool endIncluded = true;
269  TimeRange bothEndsIncluded(startEndpoint, endEndpoint, beginningIncluded,
270  endIncluded);
271 
272  //Create a TimeRange where both ends are excluded
273  beginningIncluded = false;
274  endIncluded = false;
275  TimeRange bothEndsExcluded(startEndpoint, endEndpoint, beginningIncluded,
276  endIncluded);
277 
278  //--------------------------------------------------------------------
279  //Verify inRange for a TimeRange with both ends included
280  //--------------------------------------------------------------------
281  testFramework.assert(!bothEndsIncluded.inRange(earlierThanRange),
282  "inRange returned true for time before the TimeRange" ,
283  __LINE__);
284  testFramework.assert( bothEndsIncluded.inRange(startEndpoint) ,
285  "inRange returned false for the start time for an inclusive TimeRange",
286  __LINE__);
287  testFramework.assert( bothEndsIncluded.inRange(timeInRange) ,
288  "inRange returned false for time internal to the TimeRange" ,
289  __LINE__);
290  testFramework.assert( bothEndsIncluded.inRange(endEndpoint) ,
291  "inRange returned false for the end time for an inclusive TimeRange" ,
292  __LINE__);
293  testFramework.assert(!bothEndsIncluded.inRange(laterThanRange) ,
294  "inRange returned true for time after the TimeRange" ,
295  __LINE__);
296 
297 
298  //--------------------------------------------------------------------
299  // Verify inRange for a TimeRange with both ends included
300  //--------------------------------------------------------------------
301  testFramework.assert(!bothEndsExcluded.inRange(earlierThanRange),
302  "inRange returned true for time before the TimeRange" ,
303  __LINE__);
304  testFramework.assert(!bothEndsExcluded.inRange(startEndpoint) ,
305  "inRange returned true for the start time for an exclusive TimeRange" ,
306  __LINE__);
307  testFramework.assert( bothEndsExcluded.inRange(timeInRange) ,
308  "inRange returned false for time internal to the TimeRange" ,
309  __LINE__);
310  testFramework.assert(!bothEndsExcluded.inRange(endEndpoint) ,
311  "inRange returned true for the end time for an exclusive TimeRange" ,
312  __LINE__);
313  testFramework.assert(!bothEndsIncluded.inRange(laterThanRange) ,
314  "inRange returned true for time after the TimeRange" ,
315  __LINE__);
316 
317  return testFramework.countFails();
318  }
319 //=============================================================================
320 // Test for the isPriorTo method
321 // Usage: referenceRange.isPriorTo(targetRange)
322 // If the reference range occurs completely before the target range, the method returns true
323 //=============================================================================
324  int isPriorToTest ( void )
325  {
326  TUDEF( "TimeRange", "isPriorTo" );
327 
328  //Two time points before the reference TimeRange start endpoint
329  CommonTime earlierThanRangeStart = gnsstk::CivilTime(2010,12,20, 0, 0,
330  0.0 ).convertToCommonTime();
331  CommonTime earlierThanRangeEnd = gnsstk::CivilTime(2010,12,29, 0, 0,
332  0.0 ).convertToCommonTime();
333  //Reference TimeRange start endpoint
334  CommonTime startEndpoint = gnsstk::CivilTime(2011, 1, 1, 0, 0,
335  0.0 ).convertToCommonTime();
336  //Two time points inside the reference TimeRange
337  CommonTime timeInRangeStart = gnsstk::CivilTime(2011, 1,10, 0, 0,
338  0.0 ).convertToCommonTime();
339  CommonTime timeInRangeEnd = gnsstk::CivilTime(2011, 1,20, 0, 0,
340  0.0 ).convertToCommonTime();
341  //Reference TimeRange end endpoint
342  CommonTime endEndpoint = gnsstk::CivilTime(2011, 1,31,23,59,
343  59.59).convertToCommonTime();
344  //Two time points after the reference TimeRange end endpoint
345  CommonTime laterThanRangeStart = gnsstk::CivilTime(2011, 2,20, 0, 0,
346  0.0 ).convertToCommonTime();
347  CommonTime laterThanRangeEnd = gnsstk::CivilTime(2011, 2,27, 0, 0,
348  0.0 ).convertToCommonTime();
349 
350  //Include endpoints for all checks
351  bool beginningIncluded = true;
352  bool endIncluded = true;
353 
354  //Create various TimeRanges
355  TimeRange referenceTimeRange (startEndpoint, endEndpoint,
356  beginningIncluded, endIncluded);
357  TimeRange priorTimeRange (earlierThanRangeStart, earlierThanRangeEnd,
358  beginningIncluded, endIncluded);
359  TimeRange earlyOverlapTimeRange (earlierThanRangeStart, timeInRangeEnd,
360  beginningIncluded, endIncluded);
361  TimeRange interiorTimeRange (timeInRangeStart, timeInRangeEnd,
362  beginningIncluded, endIncluded);
363  TimeRange lateOverlapTimeRange (timeInRangeStart, laterThanRangeEnd,
364  beginningIncluded, endIncluded);
365  TimeRange completeOverlapTimeRange (earlierThanRangeStart, laterThanRangeEnd,
366  beginningIncluded, endIncluded);
367  TimeRange afterTimeRange (laterThanRangeStart, laterThanRangeEnd,
368  beginningIncluded, endIncluded);
369  TimeRange priorEdgeCase (earlierThanRangeStart, startEndpoint,
370  beginningIncluded, endIncluded);
371  TimeRange priorEdgeCaseNoOverlap (earlierThanRangeStart, startEndpoint,
372  beginningIncluded, false );
373  TimeRange interiorEarlyEdge (startEndpoint, timeInRangeEnd,
374  beginningIncluded, endIncluded);
375  TimeRange interiorLateEdge (timeInRangeStart, endEndpoint,
376  beginningIncluded, endIncluded);
377  TimeRange afterEdgeCase (endEndpoint, laterThanRangeEnd,
378  beginningIncluded, endIncluded);
379  TimeRange afterEdgeCaseNoOverlap (endEndpoint, laterThanRangeEnd,
380  false, endIncluded);
381 
382  std::string testMessageArray[13];
383  testMessageArray[0] =
384  "isPriorTo returned true when the target TimeRange comes before the reference TimeRange";
385  testMessageArray[1] =
386  "isPriorTo returned true when the target TimeRange overlaps the beginning of the reference TimeRange";
387  testMessageArray[2] =
388  "isPriorTo returned true when the target TimeRange is interior to the reference TimeRange";
389  testMessageArray[3] =
390  "isPriorTo returned true when the target TimeRange overlaps a later portion of the reference TimeRange";
391  testMessageArray[4] =
392  "isPriorTo returned true when the reference TimeRange is interior to the target TimeRange";
393  testMessageArray[5] =
394  "isPriorTo returned false when the target TimeRange is after the reference TimeRange";
395  testMessageArray[6] =
396  "isPriorTo returned true when the target TimeRange ends at and includes the beginning of the reference TimeRange";
397  testMessageArray[7] =
398  "isPriorTo returned true when the target TimeRange ends at but does not include the beginning of the reference TimeRange";
399  testMessageArray[8] =
400  "isPriorTo returned true when the target TimeRange is interior to the reference TimeRange and shares a start value";
401  testMessageArray[9] =
402  "isPriorTo returned true when the target TimeRange is interior to the reference TimeRange and shares an end value";
403  testMessageArray[10] =
404  "isPriorTo returned true when the target TimeRange starts at and includes the end of reference TimeRange";
405  testMessageArray[11] =
406  "isPriorTo returned false when the target TimeRange starts at but does not include the end of reference TimeRange";
407  testMessageArray[12] =
408  "isPriorTo returned true when the target TimeRange starts equals reference TimeRange";
409 
410  return testFramework.countFails();
411  }
412 
413 //=============================================================================
414 // Test for the overlaps method
415 // Usage: referenceRange.overlaps(targetRange)
416 // If the target range and reference range intersect at all the method is to return true.
417 //=============================================================================
418  int overlapsTest ( void )
419  {
420  TUDEF( "TimeRange", "overlaps" );
421 
422  //Two time points before the reference TimeRange start endpoint
423  CommonTime earlierThanRangeStart = gnsstk::CivilTime(2010,12,20, 0, 0,
424  0.0 ).convertToCommonTime();
425  CommonTime earlierThanRangeEnd = gnsstk::CivilTime(2010,12,29, 0, 0,
426  0.0 ).convertToCommonTime();
427  //Reference TimeRange start endpoint
428  CommonTime startEndpoint = gnsstk::CivilTime(2011, 1, 1, 0, 0,
429  0.0 ).convertToCommonTime();
430  //Two time points inside the reference TimeRange
431  CommonTime timeInRangeStart = gnsstk::CivilTime(2011, 1,10, 0, 0,
432  0.0 ).convertToCommonTime();
433  CommonTime timeInRangeEnd = gnsstk::CivilTime(2011, 1,20, 0, 0,
434  0.0 ).convertToCommonTime();
435  //Reference TimeRange end endpoint
436  CommonTime endEndpoint = gnsstk::CivilTime(2011, 1,31,23,59,
437  59.59).convertToCommonTime();
438  //Two time points after the reference TimeRange end endpoint
439  CommonTime laterThanRangeStart = gnsstk::CivilTime(2011, 2,20, 0, 0,
440  0.0 ).convertToCommonTime();
441  CommonTime laterThanRangeEnd = gnsstk::CivilTime(2011, 2,27, 0, 0,
442  0.0 ).convertToCommonTime();
443 
444  //Include endpoints for all checks
445  bool beginningIncluded = true;
446  bool endIncluded = true;
447 
448  //Create various TimeRanges
449  TimeRange referenceTimeRange (startEndpoint, endEndpoint,
450  beginningIncluded, endIncluded);
451  TimeRange priorTimeRange (earlierThanRangeStart, earlierThanRangeEnd,
452  beginningIncluded, endIncluded);
453  TimeRange earlyOverlapTimeRange (earlierThanRangeStart, timeInRangeEnd,
454  beginningIncluded, endIncluded);
455  TimeRange interiorTimeRange (timeInRangeStart, timeInRangeEnd,
456  beginningIncluded, endIncluded);
457  TimeRange lateOverlapTimeRange (timeInRangeStart, laterThanRangeEnd,
458  beginningIncluded, endIncluded);
459  TimeRange completeOverlapTimeRange (earlierThanRangeStart, laterThanRangeEnd,
460  beginningIncluded, endIncluded);
461  TimeRange afterTimeRange (laterThanRangeStart, laterThanRangeEnd,
462  beginningIncluded, endIncluded);
463  TimeRange priorEdgeCase (earlierThanRangeStart, startEndpoint,
464  beginningIncluded, endIncluded);
465  TimeRange priorEdgeCaseNoOverlap (earlierThanRangeStart, startEndpoint,
466  beginningIncluded, false );
467  TimeRange interiorEarlyEdge (startEndpoint, timeInRangeEnd,
468  beginningIncluded, endIncluded);
469  TimeRange interiorLateEdge (timeInRangeStart, endEndpoint,
470  beginningIncluded, endIncluded);
471  TimeRange afterEdgeCase (endEndpoint, laterThanRangeEnd,
472  beginningIncluded, endIncluded);
473  TimeRange afterEdgeCaseNoOverlap (endEndpoint, laterThanRangeEnd,
474  false, endIncluded);
475 
476  std::string testMessageArray[13];
477  testMessageArray[0] =
478  "overlaps returned true when the target TimeRange is completely before the reference TimeRange";
479  testMessageArray[1] =
480  "overlaps returned false when the target TimeRange overlaps the earlier portion of the reference TimeRange";
481  testMessageArray[2] =
482  "overlaps returned false when the target TimeRange is interior to the reference TimeRange";
483  testMessageArray[3] =
484  "overlaps returned false when the target TimeRange overlaps a later portion of the reference TimeRange";
485  testMessageArray[4] =
486  "overlaps returned false when the reference TimeRange is interior to the target TimeRange";
487  testMessageArray[5] =
488  "overlaps returned true when the target TimeRange is after the reference TimeRange";
489  testMessageArray[6] =
490  "overlaps returned false when the target TimeRange ends at and includes the beginning of the reference TimeRange";
491  testMessageArray[7] =
492  "overlaps returned true when the target TimeRange ends at but does not include the beginning of the reference TimeRange";
493  testMessageArray[8] =
494  "overlaps returned false when the target TimeRange is interior to the reference TimeRange and shares a start value";
495  testMessageArray[9] =
496  "overlaps returned false when the target TimeRange is interior to the reference TimeRange and shares an end value";
497  testMessageArray[10] =
498  "overlaps returned false when the target TimeRange starts at and includes the end of reference TimeRange";
499  testMessageArray[11] =
500  "overlaps returned true when the target TimeRange starts at but does not include the end of reference TimeRange";
501  testMessageArray[12] =
502  "overlaps returned false when the target TimeRange starts equals reference TimeRange";
503 
504 
505  testFramework.assert(!referenceTimeRange.overlaps(priorTimeRange) ,
506  testMessageArray[0] , __LINE__);
507  testFramework.assert( referenceTimeRange.overlaps(earlyOverlapTimeRange) ,
508  testMessageArray[1] , __LINE__);
509  testFramework.assert( referenceTimeRange.overlaps(interiorTimeRange) ,
510  testMessageArray[2] , __LINE__);
511  testFramework.assert( referenceTimeRange.overlaps(lateOverlapTimeRange) ,
512  testMessageArray[3] , __LINE__);
513  testFramework.assert( referenceTimeRange.overlaps(completeOverlapTimeRange),
514  testMessageArray[4] , __LINE__);
515  testFramework.assert(!referenceTimeRange.overlaps(afterTimeRange) ,
516  testMessageArray[5] , __LINE__);
517  testFramework.assert( referenceTimeRange.overlaps(priorEdgeCase) ,
518  testMessageArray[6] , __LINE__);
519  testFramework.assert(!referenceTimeRange.overlaps(priorEdgeCaseNoOverlap) ,
520  testMessageArray[7] , __LINE__);
521  testFramework.assert( referenceTimeRange.overlaps(interiorEarlyEdge) ,
522  testMessageArray[8] , __LINE__);
523  testFramework.assert( referenceTimeRange.overlaps(interiorLateEdge) ,
524  testMessageArray[9] , __LINE__);
525  testFramework.assert( referenceTimeRange.overlaps(afterEdgeCase) ,
526  testMessageArray[10], __LINE__);
527  testFramework.assert(!referenceTimeRange.overlaps(afterEdgeCaseNoOverlap) ,
528  testMessageArray[11], __LINE__);
529  testFramework.assert( referenceTimeRange.overlaps(referenceTimeRange) ,
530  testMessageArray[12], __LINE__);
531 
532 
533 
534  return testFramework.countFails();
535  }
536 
537 //=============================================================================
538 // Test for the isSubsetOf method
539 // Usage: referenceRange.isSubsetOf(targetRange)
540 // If the reference range is entirely within the target range, the method is to return to true.
541 //=============================================================================
542  int isSubsetOfTest ( void )
543  {
544  TUDEF( "TimeRange", "isSubsetOf" );
545 
546  //Two time points before the reference TimeRange start endpoint
547  CommonTime earlierThanRangeStart = gnsstk::CivilTime(2010,12,20, 0, 0,
548  0.0 ).convertToCommonTime();
549  CommonTime earlierThanRangeEnd = gnsstk::CivilTime(2010,12,29, 0, 0,
550  0.0 ).convertToCommonTime();
551  //Reference TimeRange start endpoint
552  CommonTime startEndpoint = gnsstk::CivilTime(2011, 1, 1, 0, 0,
553  0.0 ).convertToCommonTime();
554  //Two time points inside the reference TimeRange
555  CommonTime timeInRangeStart = gnsstk::CivilTime(2011, 1,10, 0, 0,
556  0.0 ).convertToCommonTime();
557  CommonTime timeInRangeEnd = gnsstk::CivilTime(2011, 1,20, 0, 0,
558  0.0 ).convertToCommonTime();
559  //Reference TimeRange end endpoint
560  CommonTime endEndpoint = gnsstk::CivilTime(2011, 1,31,23,59,
561  59.59).convertToCommonTime();
562  //Two time points after the reference TimeRange end endpoint
563  CommonTime laterThanRangeStart = gnsstk::CivilTime(2011, 2,20, 0, 0,
564  0.0 ).convertToCommonTime();
565  CommonTime laterThanRangeEnd = gnsstk::CivilTime(2011, 2,27, 0, 0,
566  0.0 ).convertToCommonTime();
567 
568  //Include endpoints for all checks
569  bool beginningIncluded = true;
570  bool endIncluded = true;
571 
572  //Create various TimeRanges
573  TimeRange referenceTimeRange (startEndpoint, endEndpoint,
574  beginningIncluded, endIncluded);
575  TimeRange priorTimeRange (earlierThanRangeStart, earlierThanRangeEnd,
576  beginningIncluded, endIncluded);
577  TimeRange earlyOverlapTimeRange (earlierThanRangeStart, timeInRangeEnd,
578  beginningIncluded, endIncluded);
579  TimeRange interiorTimeRange (timeInRangeStart, timeInRangeEnd,
580  beginningIncluded, endIncluded);
581  TimeRange lateOverlapTimeRange (timeInRangeStart, laterThanRangeEnd,
582  beginningIncluded, endIncluded);
583  TimeRange completeOverlapTimeRange (earlierThanRangeStart, laterThanRangeEnd,
584  beginningIncluded, endIncluded);
585  TimeRange afterTimeRange (laterThanRangeStart, laterThanRangeEnd,
586  beginningIncluded, endIncluded);
587  TimeRange priorEdgeCase (earlierThanRangeStart, startEndpoint,
588  beginningIncluded, endIncluded);
589  TimeRange priorEdgeCaseNoOverlap (earlierThanRangeStart, startEndpoint,
590  beginningIncluded, false );
591  TimeRange interiorEarlyEdge (startEndpoint, timeInRangeEnd,
592  beginningIncluded, endIncluded);
593  TimeRange interiorLateEdge (timeInRangeStart, endEndpoint,
594  beginningIncluded, endIncluded);
595  TimeRange afterEdgeCase (endEndpoint, laterThanRangeEnd,
596  beginningIncluded, endIncluded);
597  TimeRange afterEdgeCaseNoOverlap (endEndpoint, laterThanRangeEnd,
598  beginningIncluded, false );
599 
600  std::string testMessageArray[13];
601  testMessageArray[0] =
602  "isSubsetOf returned true when the target TimeRange is completely before the reference TimeRange";
603  testMessageArray[1] =
604  "isSubsetOf returned true when the target TimeRange overlaps the earlier portion of the reference TimeRange";
605  testMessageArray[2] =
606  "isSubsetOf returned true when the target TimeRange is interior to the reference TimeRange";
607  testMessageArray[3] =
608  "isSubsetOf returned true when the target TimeRange overlaps a later portion of the reference TimeRange";
609  testMessageArray[4] =
610  "isSubsetOf returned false when the reference TimeRange is interior to the target TimeRange";
611  testMessageArray[5] =
612  "isSubsetOf returned true when the target TimeRange is after the reference TimeRange";
613  testMessageArray[6] =
614  "isSubsetOf returned true when the target TimeRange ends at and includes the beginning of the reference TimeRange";
615  testMessageArray[7] =
616  "isSubsetOf returned true when the target TimeRange ends at but does not include the beginning of the reference TimeRange";
617  testMessageArray[8] =
618  "isSubsetOf returned true when the target TimeRange is interior to the reference TimeRange and shares a start value";
619  testMessageArray[9] =
620  "isSubsetOf returned true when the target TimeRange is interior to the reference TimeRange and shares an end value";
621  testMessageArray[10] =
622  "isSubsetOf returned true when the target TimeRange starts at and includes the end of reference TimeRange";
623  testMessageArray[11] =
624  "isSubsetOf returned true when the target TimeRange starts at but does not include the end of reference TimeRange";
625  testMessageArray[12] =
626  "isSubsetOf returned false when the target TimeRange starts equals reference TimeRange";
627 
628 
629  testFramework.assert(!referenceTimeRange.isSubsetOf(priorTimeRange) ,
630  testMessageArray[0] , __LINE__);
631  testFramework.assert(!referenceTimeRange.isSubsetOf(earlyOverlapTimeRange) ,
632  testMessageArray[1] , __LINE__);
633  testFramework.assert(!referenceTimeRange.isSubsetOf(interiorTimeRange) ,
634  testMessageArray[2] , __LINE__);
635  testFramework.assert(!referenceTimeRange.isSubsetOf(lateOverlapTimeRange) ,
636  testMessageArray[3] , __LINE__);
637  testFramework.assert( referenceTimeRange.isSubsetOf(completeOverlapTimeRange),
638  testMessageArray[4] , __LINE__);
639  testFramework.assert(!referenceTimeRange.isSubsetOf(afterTimeRange) ,
640  testMessageArray[5] , __LINE__);
641  testFramework.assert(!referenceTimeRange.isSubsetOf(priorEdgeCase) ,
642  testMessageArray[6] , __LINE__);
643  testFramework.assert(!referenceTimeRange.isSubsetOf(priorEdgeCaseNoOverlap) ,
644  testMessageArray[7] , __LINE__);
645  testFramework.assert(!referenceTimeRange.isSubsetOf(interiorEarlyEdge) ,
646  testMessageArray[8] , __LINE__);
647  testFramework.assert(!referenceTimeRange.isSubsetOf(interiorLateEdge) ,
648  testMessageArray[9] , __LINE__);
649  testFramework.assert(!referenceTimeRange.isSubsetOf(afterEdgeCase) ,
650  testMessageArray[10], __LINE__);
651  testFramework.assert(!referenceTimeRange.isSubsetOf(afterEdgeCaseNoOverlap) ,
652  testMessageArray[11], __LINE__);
653  testFramework.assert( referenceTimeRange.isSubsetOf(referenceTimeRange) ,
654  testMessageArray[12], __LINE__);
655 
656  return testFramework.countFails();
657  }
658 
659 
660 //=============================================================================
661 // Test for the isAfter method
662 // Usage: referenceRange.isAfter(targetRange)
663 // If the reference range is entirely after the target range, the method is to return to true.
664 //=============================================================================
665  int isAfterTest ( void )
666  {
667  TUDEF( "TimeRange", "isAfter" );
668 
669  //Two time points before the reference TimeRange start endpoint
670  CommonTime earlierThanRangeStart = gnsstk::CivilTime(2010,12,20, 0, 0,
671  0.0 ).convertToCommonTime();
672  CommonTime earlierThanRangeEnd = gnsstk::CivilTime(2010,12,29, 0, 0,
673  0.0 ).convertToCommonTime();
674  //Reference TimeRange start endpoint
675  CommonTime startEndpoint = gnsstk::CivilTime(2011, 1, 1, 0, 0,
676  0.0 ).convertToCommonTime();
677  //Two time points inside the reference TimeRange
678  CommonTime timeInRangeStart = gnsstk::CivilTime(2011, 1,10, 0, 0,
679  0.0 ).convertToCommonTime();
680  CommonTime timeInRangeEnd = gnsstk::CivilTime(2011, 1,20, 0, 0,
681  0.0 ).convertToCommonTime();
682  //Reference TimeRange end endpoint
683  CommonTime endEndpoint = gnsstk::CivilTime(2011, 1,31,23,59,
684  59.59).convertToCommonTime();
685  //Two time points after the reference TimeRange end endpoint
686  CommonTime laterThanRangeStart = gnsstk::CivilTime(2011, 2,20, 0, 0,
687  0.0 ).convertToCommonTime();
688  CommonTime laterThanRangeEnd = gnsstk::CivilTime(2011, 2,27, 0, 0,
689  0.0 ).convertToCommonTime();
690 
691  //Include endpoints for all checks
692  bool beginningIncluded = true;
693  bool endIncluded = true;
694 
695  //Create various TimeRanges
696  TimeRange referenceTimeRange (startEndpoint, endEndpoint,
697  beginningIncluded, endIncluded);
698  TimeRange priorTimeRange (earlierThanRangeStart, earlierThanRangeEnd,
699  beginningIncluded, endIncluded);
700  TimeRange earlyOverlapTimeRange (earlierThanRangeStart, timeInRangeEnd,
701  beginningIncluded, endIncluded);
702  TimeRange interiorTimeRange (timeInRangeStart, timeInRangeEnd,
703  beginningIncluded, endIncluded);
704  TimeRange lateOverlapTimeRange (timeInRangeStart, laterThanRangeEnd,
705  beginningIncluded, endIncluded);
706  TimeRange completeOverlapTimeRange (earlierThanRangeStart, laterThanRangeEnd,
707  beginningIncluded, endIncluded);
708  TimeRange afterTimeRange (laterThanRangeStart, laterThanRangeEnd,
709  beginningIncluded, endIncluded);
710  TimeRange priorEdgeCase (earlierThanRangeStart, startEndpoint,
711  beginningIncluded, endIncluded);
712  TimeRange priorEdgeCaseNoOverlap (earlierThanRangeStart, startEndpoint,
713  beginningIncluded, false );
714  TimeRange interiorEarlyEdge (startEndpoint, timeInRangeEnd,
715  beginningIncluded, endIncluded);
716  TimeRange interiorLateEdge (timeInRangeStart, endEndpoint,
717  beginningIncluded, endIncluded);
718  TimeRange afterEdgeCase (endEndpoint, laterThanRangeEnd,
719  beginningIncluded, endIncluded);
720  TimeRange afterEdgeCaseNoOverlap (endEndpoint, laterThanRangeEnd,
721  beginningIncluded, false );
722 
723 
724  std::string testMessageArray[13];
725  testMessageArray[0] =
726  "isAfter returned false when the target TimeRange is completely before the reference TimeRange";
727  testMessageArray[1] =
728  "isAfter returned true when the target TimeRange overlaps the earlier portion of the reference TimeRange";
729  testMessageArray[2] =
730  "isAfter returned true when the target TimeRange is interior to the reference TimeRange";
731  testMessageArray[3] =
732  "isAfter returned true when the target TimeRange overlaps a later portion of the reference TimeRange";
733  testMessageArray[4] =
734  "isAfter returned true when the reference TimeRange is interior to the target TimeRange";
735  testMessageArray[5] =
736  "isAfter returned true when the target TimeRange is after the reference TimeRange";
737  testMessageArray[6] =
738  "isAfter returned true when the target TimeRange ends at and includes the beginning of the reference TimeRange";
739  testMessageArray[7] =
740  "isAfter returned false when the target TimeRange ends at but does not include the beginning of the reference TimeRange";
741  testMessageArray[8] =
742  "isAfter returned true when the target TimeRange is interior to the reference TimeRange and shares a start value";
743  testMessageArray[9] =
744  "isAfter returned true when the target TimeRange is interior to the reference TimeRange and shares an end value";
745  testMessageArray[10] =
746  "isAfter returned true when the target TimeRange starts at and includes the end of reference TimeRange";
747  testMessageArray[11] =
748  "isAfter returned true when the target TimeRange starts at but does not include the end of reference TimeRange";
749  testMessageArray[12] =
750  "isAfter returned true when the target TimeRange starts equals reference TimeRange";
751 
752 
753  testFramework.assert( referenceTimeRange.isAfter(priorTimeRange) ,
754  testMessageArray[0] , __LINE__);
755  testFramework.assert(!referenceTimeRange.isAfter(earlyOverlapTimeRange) ,
756  testMessageArray[1] , __LINE__);
757  testFramework.assert(!referenceTimeRange.isAfter(interiorTimeRange) ,
758  testMessageArray[2] , __LINE__);
759  testFramework.assert(!referenceTimeRange.isAfter(lateOverlapTimeRange) ,
760  testMessageArray[3] , __LINE__);
761  testFramework.assert(!referenceTimeRange.isAfter(completeOverlapTimeRange),
762  testMessageArray[4] , __LINE__);
763  testFramework.assert(!referenceTimeRange.isAfter(afterTimeRange) ,
764  testMessageArray[5] , __LINE__);
765  testFramework.assert(!referenceTimeRange.isAfter(priorEdgeCase) ,
766  testMessageArray[6] , __LINE__);
767  testFramework.assert( referenceTimeRange.isAfter(priorEdgeCaseNoOverlap) ,
768  testMessageArray[7] , __LINE__);
769  testFramework.assert(!referenceTimeRange.isAfter(interiorEarlyEdge) ,
770  testMessageArray[8] , __LINE__);
771  testFramework.assert(!referenceTimeRange.isAfter(interiorLateEdge) ,
772  testMessageArray[9] , __LINE__);
773  testFramework.assert(!referenceTimeRange.isAfter(afterEdgeCase) ,
774  testMessageArray[10], __LINE__);
775  testFramework.assert(!referenceTimeRange.isAfter(afterEdgeCaseNoOverlap) ,
776  testMessageArray[11], __LINE__);
777  testFramework.assert(!referenceTimeRange.isAfter(referenceTimeRange) ,
778  testMessageArray[12], __LINE__);
779 
780 
781  return testFramework.countFails();
782  }
783 
784 
785 //=============================================================================
786 // Test for the setToString method
787 // Usage: referenceRange.setToString(string, format)
788 // Converts the reference TimeRange instance's start/end times to the start/end
789 // times represented in the input string.
790 //=============================================================================
791  int setToStringTest ( void )
792  {
793  TUDEF("TimeRange", "setToString");
794  /* Formatted string input.
795  * Assume string has
796  * \li possible white space followed by
797  * \li optional '[' or '(' (assume '['),
798  * \li followed by a valid CommonTime string corresponding to fmt,
799  * \li followed by a ','
800  * \li followed by a valid CommonTime string corresponding to fmt,
801  * \li followed by an optional ']' or ')' (assume ']'). */
802  const int NUMTESTS = 21;
803  std::string testStrings[NUMTESTS] =
804  {
805  // Y/m/d H:M:S
806  // %Y %m %d %H %M %S
807  "[2012 1 1 0 0 0.0, 2012 1 31 23 59 59.9]", // Inclusive
808  "(2012 1 1 0 0 0.0, 2012 1 31 23 59 59.9)", // Exclusive
809  "2012 1 1 0 0 0.0, 2012 1 31 23 59 59.9", // Inclusive default
810  "(2012 1 1 0 0 0.0, 2012 1 31 23 59 59.9]", // Exclusive/Inclusive
811  "[2012 1 1 0 0 0.0, 2012 1 31 23 59 59.9)", // Inclusive/Exclusive
812  // Exception cases
813  // This throws a TimeRange exception
814  "2012 1 1 0 0 0.0,@ 2012 1 31 23 59 59.9)", // Invalid character
815  // This doesn't throw - it returns a wonky CommonTime
816  // Not sure if that's what it should do, I'm just documenting it
817  "[2012 1 1 ! 0 0 0.0, 2012 1 31 $ 23 59 59.*", // Invalid characters
818  "[]",
819  " ( ",
820  " ( ]",
821  "[ ) ",
822 
823 
824  // Year, DOY, SOD
825  // %Y %j %s
826  "[2012 001 0.0, 2012 031 86399.0]", // OK
827  "(2003 1 42300.0, 2003 180 42300.0)", // OK
828  "2011 360 0.0, 2012 364 84599.0", // OK
829  // Exception cases
830  // This case throws a TimeRange exception
831  "2016 4 23000.0, 2016 4 8$000.0", // Invalid character
832  // This breaks everything
833  "", // Blank string
834  // This throws a StringUtils::StringException
835  "random four word string", // Random string
836 
837 
838  // full GPSweek, Zcount
839  // %F %Z
840  " [1906 254884, 1906 254890]", // OK, extra whitespace is fine
841  "(1801 114924, 1903 254890)",
842  "1900 123456, 1906 254777",
843  // Exception cases
844  // This doesn't throw - it returns a wonky CommonTime
845  // Not sure if that's what it should do, I'm just documenting it
846  " 1900 abc 123456, 1906 254777)" // Invalid Character
847  };
848 
849  std::string testFmts[NUMTESTS]=
850  {
851  "%Y %m %d %H %M %S",
852  "%Y %m %d %H %M %S",
853  "%Y %m %d %H %M %S",
854  "%Y %m %d %H %M %S",
855  "%Y %m %d %H %M %S",
856  "%Y %m %d %H %M %S",
857  "%Y %m %d %H %M %S",
858  "%Y %m %d %H %M %S",
859  "%Y %m %d %H %M %S",
860  "%Y %m %d %H %M %S",
861  "%Y %m %d %H %M %S",
862  "%Y %j %s",
863  "%Y %j %s",
864  "%Y %j %s",
865  "%Y %j %s",
866  "",
867  "%s %s %s %s",
868  "%F %Z",
869  "%F %Z",
870  "%F %Z",
871  "%F %Z"
872  };
873 
874  TimeRange hardcodedResults[NUMTESTS] =
875  {
876  // %Y %m %d %H %M %S
877  TimeRange(CivilTime(2012, 1, 1, 0, 0, 0.0).convertToCommonTime(),
878  CivilTime(2012, 1, 31, 23, 59, 59.9).convertToCommonTime(),
879  true, true),
880  TimeRange(CivilTime(2012, 1, 1, 0, 0, 0.0).convertToCommonTime(),
881  CivilTime(2012, 1, 31, 23, 59, 59.9).convertToCommonTime(),
882  false, false),
883  TimeRange(CivilTime(2012, 1, 1, 0, 0, 0.0).convertToCommonTime(),
884  CivilTime(2012, 1, 31, 23, 59, 59.9).convertToCommonTime()
885  ),
886  TimeRange(CivilTime(2012, 1, 1, 0, 0, 0.0).convertToCommonTime(),
887  CivilTime(2012, 1, 31, 23, 59, 59.9).convertToCommonTime(),
888  false, true),
889  TimeRange(CivilTime(2012, 1, 1, 0, 0, 0.0).convertToCommonTime(),
890  CivilTime(2012, 1, 31, 23, 59, 59.9).convertToCommonTime(),
891  true, false),
892  TimeRange(CivilTime(2012, 1, 1, 0, 0, 0).convertToCommonTime(),
893  CivilTime(2012, 1, 31, 23, 59, 59.9).convertToCommonTime(),
894  true, false),
895  TimeRange(CivilTime(2012, 1, 1, 0, 0, 0).convertToCommonTime(),
896  CivilTime(2012, 1, 31, 0, 23, 59).convertToCommonTime(),
897  true, true),
898  TimeRange(CivilTime(2012, 1, 1, 0, 0, 0).convertToCommonTime(),
899  CivilTime(2012, 1, 31, 0, 23, 59).convertToCommonTime(),
900  true, true),
901  TimeRange(CivilTime(2012, 1, 1, 0, 0, 0).convertToCommonTime(),
902  CivilTime(2012, 1, 31, 0, 23, 59).convertToCommonTime(),
903  true, true),
904  TimeRange(CivilTime(2012, 1, 1, 0, 0, 0).convertToCommonTime(),
905  CivilTime(2012, 1, 31, 0, 23, 59).convertToCommonTime(),
906  true, true),
907  TimeRange(CivilTime(2012, 1, 1, 0, 0, 0).convertToCommonTime(),
908  CivilTime(2012, 1, 31, 0, 23, 59).convertToCommonTime(),
909  true, true),
910 
911  // %Y %j %s
912  TimeRange(gnsstk::YDSTime(2012, 1, 0.0).convertToCommonTime(),
913  gnsstk::YDSTime(2012, 31, 86399.0).convertToCommonTime(),
914  true, true),
915  TimeRange(gnsstk::YDSTime(2003, 1, 42300.0).convertToCommonTime(),
916  gnsstk::YDSTime(2003, 180, 42300.0).convertToCommonTime(),
917  false, false),
918  TimeRange(gnsstk::YDSTime(2011, 360, 0.0).convertToCommonTime(),
919  gnsstk::YDSTime(2012, 364, 84599.0).convertToCommonTime()
920  ),
921  TimeRange(gnsstk::YDSTime(2016, 4, 23000.0).convertToCommonTime(),
922  gnsstk::YDSTime(2016, 4, 80000.0).convertToCommonTime()
923  ),
924  TimeRange(gnsstk::YDSTime(2016, 4, 23000.0).convertToCommonTime(),
925  gnsstk::YDSTime(2016, 4, 80000.0).convertToCommonTime()
926  ),
927  TimeRange(gnsstk::YDSTime(2016, 4, 23000.0).convertToCommonTime(),
928  gnsstk::YDSTime(2016, 4, 80000.0).convertToCommonTime()
929  ),
930 
931  // %F %Z
932  TimeRange(GPSWeekZcount(1906, 254884).convertToCommonTime(),
933  GPSWeekZcount(1906, 254890).convertToCommonTime(),
934  true, true),
935  TimeRange(GPSWeekZcount(1801, 114924).convertToCommonTime(),
936  GPSWeekZcount(1903, 254890).convertToCommonTime(),
937  false, false),
938  TimeRange(GPSWeekZcount(1900, 123456).convertToCommonTime(),
939  GPSWeekZcount(1906, 254777).convertToCommonTime()
940  ),
941  TimeRange(GPSWeekZcount(1900, 0).convertToCommonTime(),
942  GPSWeekZcount(1906, 254777).convertToCommonTime(),
943  true, false),
944  };
945 
946 
947  // Indices of test cases that should throw
948  int invalid[] = {5,6,7,8,9,10,14,15,16,20};
949 
950  for (size_t i = 0; i < NUMTESTS; ++i)
951  {
952  try
953  {
954  stringstream ss;
955  ss << "setToString loop Index " << i;
956  TUCSM(ss.str());
957  TimeRange testRange;
958  testRange.setToString(testStrings[i],testFmts[i]);
959  TUASSERT(hardcodedResults[i] == testRange);
960  }
961  catch(StringUtils::StringException& exc)
962  {
963  // This checks if i is in the array of invalid
964  // test cases; invalid+10 is the last address of the array
965  int * it = std::find(invalid, invalid+10, i);
966  if (it != (invalid+10))
967  {
968  TUPASS("Received expected exception when trying to call setToString: "
969  + exc.what());
970  }
971  else
972  {
973  TUFAIL("Received unexpected exception when trying to call setToString: "
974  + exc.what());
975  }
976  }
977  catch(TimeRange::TimeRangeException& exc)
978  {
979  int * it = std::find(invalid, invalid+10, i);
980  if (it != (invalid+10))
981  {
982  TUPASS("Received expected exception when trying to call setToString: "
983  + exc.what());
984  }
985  else
986  {
987  TUFAIL("Received unexpected exception when trying to call setToString: "
988  + exc.what());
989  }
990  }
991  catch (gnsstk::InvalidRequest& exc)
992  {
993  TUFAIL("Received unexpected exception when trying to call setToString: "
994  + exc.what());
995  }
996  catch(...)
997  {
998  TUFAIL("Received unexpected exception when trying to call setToString");
999  }
1000  }
1001  TURETURN();
1002  }
1003 
1004 //=============================================================================
1005 // Test for the == Operator
1006 // Usage: leftRange == rightRange
1007 // If the left TimeRange is exactly (same start point, end point,
1008 // and endpoint inclusions) return true. Otherwise false
1009 //=============================================================================
1010  int equalsOperatorTest ( void )
1011  {
1012  TUDEF( "TimeRange", "OperatorEquivalence" );
1013 
1014  //Reference TimeRange endpoints
1015  CommonTime startPoint = gnsstk::CivilTime(2011, 1, 1, 0, 0,
1016  0.0 ).convertToCommonTime();
1017  CommonTime endPoint = gnsstk::CivilTime(2011, 1,31,23,59,
1018  59.59).convertToCommonTime();
1019  CommonTime anotherTime = gnsstk::CivilTime(2011, 1,10, 0, 0,
1020  0.0 ).convertToCommonTime();
1021 
1022  //Create various TimeRanges
1023  TimeRange referenceTimeRange(startPoint, endPoint, true, true );
1024  TimeRange differentStart (anotherTime, endPoint, true, true );
1025  TimeRange differentEnd (startPoint, anotherTime, true, true );
1026  TimeRange noInitialPoint (startPoint, endPoint, false, true );
1027  TimeRange noFinalPoint (startPoint, endPoint, true, false);
1028  TimeRange copiedTimeRange (referenceTimeRange);
1029 
1030  testFramework.assert( !(referenceTimeRange == differentStart) ,
1031  "Equivalence operator returned true when the start time is different"
1032  , __LINE__ );
1033  testFramework.assert( !(referenceTimeRange == differentEnd) ,
1034  "Equivalence operator returned true when the end time is different"
1035  , __LINE__ );
1036  testFramework.assert( !(referenceTimeRange == noInitialPoint) ,
1037  "Equivalence operator returned true when the start time inclusion boolean is different",
1038  __LINE__ );
1039  testFramework.assert( !(referenceTimeRange == noFinalPoint) ,
1040  "Equivalence operator returned true when the end time inclusion boolean is different"
1041  , __LINE__ );
1042  testFramework.assert( (referenceTimeRange == copiedTimeRange),
1043  "Equivalence operator returned false when the time ranges are copies"
1044  , __LINE__ );
1045 
1046 
1047  return testFramework.countFails();
1048  }
1049 
1050 //=============================================================================
1051 // Test for the < Operator
1052 // Usage: leftRange < rightRange
1053 // If the start for the left TimeRange is less than start
1054 // for the right TimeRange return true. Otherwise false
1055 //=============================================================================
1057  {
1058  TUDEF( "TimeRange", "OperatorLessThan" );
1059 
1060  //Reference TimeRange endpoints
1061  CommonTime startPoint = gnsstk::CivilTime(2011, 1, 1, 0, 0,
1062  0.0 ).convertToCommonTime();
1063  CommonTime endPoint = gnsstk::CivilTime(2011, 1,31,23,59,
1064  59.59).convertToCommonTime();
1065  CommonTime anotherTime = gnsstk::CivilTime(2011, 1,10, 0, 0,
1066  0.0 ).convertToCommonTime();
1067 
1068  //Create various TimeRanges
1069  TimeRange referenceTimeRange(startPoint, endPoint, true, true );
1070  TimeRange laterStart (anotherTime, endPoint, true, true );
1071  TimeRange noInitialPoint (startPoint, endPoint, false, true );
1072  TimeRange copiedTimeRange (referenceTimeRange);
1073 
1074  testFramework.assert( !(referenceTimeRange < copiedTimeRange),
1075  "Less than operator returned true when the time ranges are copies"
1076  , __LINE__ );
1077 
1078  testFramework.assert( referenceTimeRange < laterStart,
1079  "Less than operator returned false when the left start < right start"
1080  , __LINE__ );
1081 
1082  testFramework.assert( !(laterStart < referenceTimeRange),
1083  "Less than operator returned true when the left start > right start"
1084  , __LINE__ );
1085 
1086  testFramework.assert( referenceTimeRange < noInitialPoint,
1087  "Less than operator returned true when the left start inclusive == right start exclusive"
1088  , __LINE__ );
1089 
1090  return testFramework.countFails();
1091  }
1092 
1093 
1094 //=============================================================================
1095 // Test for the set method
1096 // Method changes the internal values of the TimeRange object
1097 // Test that the interior attributes have changed.
1098 //=============================================================================
1099  int setTest ( void )
1100  {
1101  TUDEF( "TimeRange", "set" );
1102 
1103 
1104  //Reference TimeRange endpoints
1105  CommonTime startPoint = gnsstk::CivilTime(2011, 1, 1, 0, 0,
1106  0.0 ).convertToCommonTime();
1107  CommonTime endPoint = gnsstk::CivilTime(2011, 1,31,23,59,
1108  59.59).convertToCommonTime();
1109  CommonTime anotherTime = gnsstk::CivilTime(2011, 1,10, 0, 0,
1110  0.0 ).convertToCommonTime();
1111 
1112  //Create various TimeRanges
1113  TimeRange referenceTimeRange(startPoint, endPoint, true, true );
1114  TimeRange changedTimeRange;
1115 
1116  //--------------------------------------------------------------------
1117  //Verify set method functions and throws exceptions when it should
1118  //--------------------------------------------------------------------
1119  try
1120  {
1121  changedTimeRange.set(anotherTime, startPoint, true, true);
1122  testFramework.assert(false,
1123  "set method allowed for the end time to be earlier than the start time",
1124  __LINE__);
1125  }
1126  catch (Exception& e)
1127  {
1128  testFramework.assert(true, "set method threw the expected error", __LINE__);
1129  }
1130  catch (...)
1131  {
1132  testFramework.assert(false,
1133  "set method threw an unexpected error for when the end time is earlier than the start time",
1134  __LINE__);
1135  }
1136 
1137 
1138  //Verify set does not throw an exception when inputs are valid
1139  try
1140  {
1141  changedTimeRange.set(startPoint, endPoint, true, true);
1142  testFramework.assert(true, "set method for valid data functioned properly",
1143  __LINE__);
1144  }
1145  catch (...)
1146  {
1147  testFramework.assert(false,
1148  "set method for valid data functioned threw an error", __LINE__);
1149  }
1150 
1151  changedTimeRange.set(startPoint, endPoint, true, true);
1152  testFramework.assert( (changedTimeRange == referenceTimeRange),
1153  "One of the values was not set properly", __LINE__ );
1154 
1155  return testFramework.countFails();
1156  }
1157 
1158 
1159 
1160 //=============================================================================
1161 // Test for the printf method
1162 //=============================================================================
1163  int printfTest ( void )
1164  {
1165  TUDEF( "TimeRange", "printf" );
1166 
1167 
1168  std::stringstream printfOutputStream;
1169 
1170  //Reference TimeRange endpoints
1171  CommonTime startPoint = gnsstk::CivilTime(2011, 1, 1, 0, 0,
1172  0.0 ).convertToCommonTime();
1173  CommonTime endPoint = gnsstk::CivilTime(2011, 1,31,23,59,
1174  59.59).convertToCommonTime();
1175 
1176  //Create various TimeRanges
1177  TimeRange timeRangeArray[7];
1178  timeRangeArray[0].set(startPoint, endPoint, true, true );
1179  timeRangeArray[1].set(startPoint, endPoint, true, false );
1180  timeRangeArray[2].set(startPoint, endPoint, false, true );
1181  timeRangeArray[3].set(startPoint, endPoint, false, false );
1182  timeRangeArray[4].set(startPoint, endPoint, true, true );
1183  timeRangeArray[5].set(startPoint, endPoint, true, true );
1184  timeRangeArray[6].set(startPoint, endPoint, true, true );
1185 
1186  std::string testFmts[]=
1187  {
1188  "%Y %m %d %H %M %S",
1189  "%Y %m %d %H %M %S",
1190  "%Y %m %d %H %M %S",
1191  "%Y %m %d %H %M %S",
1192  "%02m/%02d/%02y %02H:%02M:%02S",
1193  "%02b %02d, %04Y %02H:%02M:%02S",
1194  "%Y %j %s"
1195  };
1196 
1197 
1198  std::string correctResults[]=
1199  {
1200  "[2011 1 1 0 0 0, 2011 1 31 23 59 59]",
1201  "[2011 1 1 0 0 0, 2011 1 31 23 59 59)",
1202  "(2011 1 1 0 0 0, 2011 1 31 23 59 59]",
1203  "(2011 1 1 0 0 0, 2011 1 31 23 59 59)",
1204  "[01/01/11 00:00:00, 01/31/11 23:59:59]",
1205  "[Jan 01, 2011 00:00:00, Jan 31, 2011 23:59:59]",
1206  "[2011 1 0.000000, 2011 31 86399.590000]"
1207  };
1208 
1209  std::string testMessage = "Printed string did not match expected output";
1210 
1211  for (int i = 0; i < 7; i++)
1212  {
1213  printfOutputStream << timeRangeArray[i].printf(testFmts[i]);
1214  testFramework.assert( (printfOutputStream.str() == correctResults[i]),
1215  testMessage, __LINE__ );
1216  printfOutputStream.str(std::string());
1217  }
1218 
1219  return testFramework.countFails();
1220  }
1221 
1222 //=============================================================================
1223 // Test for the dump method
1224 //=============================================================================
1225  int dumpTest ( void )
1226  {
1227  TUDEF( "TimeRange", "dump" );
1228 
1229  std::stringstream dumpOutputStream;
1230 
1231  //Reference TimeRange endpoints
1232  CommonTime startPoint = gnsstk::CivilTime(2011, 1, 1, 0, 0,
1233  0.0 ).convertToCommonTime();
1234  CommonTime endPoint = gnsstk::CivilTime(2011, 1,31,23,59,
1235  59.59).convertToCommonTime();
1236 
1237  //Create various TimeRanges
1238  TimeRange timeRangeArray[7];
1239  timeRangeArray[0].set(startPoint, endPoint, true, true );
1240  timeRangeArray[1].set(startPoint, endPoint, true, false );
1241  timeRangeArray[2].set(startPoint, endPoint, false, true );
1242  timeRangeArray[3].set(startPoint, endPoint, false, false );
1243  timeRangeArray[4].set(startPoint, endPoint, true, true );
1244  timeRangeArray[5].set(startPoint, endPoint, true, true );
1245  timeRangeArray[6].set(startPoint, endPoint, true, true );
1246 
1247  std::string testFmts[]=
1248  {
1249  "%Y %m %d %H %M %S",
1250  "%Y %m %d %H %M %S",
1251  "%Y %m %d %H %M %S",
1252  "%Y %m %d %H %M %S",
1253  "%02m/%02d/%02y %02H:%02M:%02S",
1254  "%02b %02d, %04Y %02H:%02M:%02S",
1255  "%Y %j %s"
1256  };
1257 
1258 
1259  std::string correctResults[]=
1260  {
1261  "[Start:2011 1 1 0 0 0, End: 2011 1 31 23 59 59]",
1262  "[Start:2011 1 1 0 0 0, End: 2011 1 31 23 59 59)",
1263  "(Start:2011 1 1 0 0 0, End: 2011 1 31 23 59 59]",
1264  "(Start:2011 1 1 0 0 0, End: 2011 1 31 23 59 59)",
1265  "[Start:01/01/11 00:00:00, End: 01/31/11 23:59:59]",
1266  "[Start:Jan 01, 2011 00:00:00, End: Jan 31, 2011 23:59:59]",
1267  "[Start:2011 1 0.000000, End: 2011 31 86399.590000]"
1268  };
1269 
1270  std::string testMessage = "Printed string did not match expected output";
1271 
1272  for (int i = 0; i < 7; i++)
1273  {
1274  dumpOutputStream << timeRangeArray[i].dump(testFmts[i]);
1275  testFramework.assert( (dumpOutputStream.str() == correctResults[i]),
1276  testMessage, __LINE__ );
1277  dumpOutputStream.str(std::string());
1278  }
1279 
1280  return testFramework.countFails();
1281 
1282  }
1283 private:
1284  double eps;
1285 };
1286 
1287 
1288 int main() //Main function to initialize and run all tests above
1289 {
1290  int errorTotal = 0;
1291  TimeRange_T testClass;
1292 
1293  errorTotal += testClass.constructorTest();
1294  errorTotal += testClass.inRangeTest();
1295  errorTotal += testClass.isPriorToTest();
1296  errorTotal += testClass.overlapsTest();
1297  errorTotal += testClass.isSubsetOfTest();
1298  errorTotal += testClass.isAfterTest();
1299  errorTotal += testClass.setToStringTest();
1300  errorTotal += testClass.equalsOperatorTest();
1301  errorTotal += testClass.lessThanOperatorTest();
1302  errorTotal += testClass.setTest();
1303  errorTotal += testClass.printfTest();
1304  errorTotal += testClass.dumpTest();
1305 
1306  cout << "Total Failures for " << __FILE__ << ": " << errorTotal << endl;
1307 
1308  return errorTotal; //Return the total number of errors
1309 }
1310 
GPSWeekZcount.hpp
TUCSM
#define TUCSM(METHOD)
Definition: TestUtil.hpp:59
YDSTime.hpp
main
int main()
Definition: TimeRange_T.cpp:1288
gnsstk::YDSTime
Definition: YDSTime.hpp:58
TUFAIL
#define TUFAIL(MSG)
Definition: TestUtil.hpp:228
TimeRange_T::lessThanOperatorTest
int lessThanOperatorTest(void)
Definition: TimeRange_T.cpp:1056
gnsstk::CommonTime::BEGINNING_OF_TIME
static const GNSSTK_EXPORT CommonTime BEGINNING_OF_TIME
earliest representable CommonTime
Definition: CommonTime.hpp:102
gnsstk::TimeRange::overlaps
bool overlaps(const TimeRange &right) const
Definition: TimeRange.cpp:221
gnsstk::TimeRange::printf
std::string printf(const std::string formatArg="%02m/%02d/%02y %02H:%02M:%02S") const
Definition: TimeRange.cpp:376
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
TimeRange_T::setTest
int setTest(void)
Definition: TimeRange_T.cpp:1099
gnsstk::TimeRange::inRange
bool inRange(const CommonTime &testDT) const
Definition: TimeRange.cpp:146
gnsstk::TimeRange
Definition: TimeRange.hpp:59
gnsstk::Exception
Definition: Exception.hpp:151
TimeRange_T::~TimeRange_T
~TimeRange_T()
Definition: TimeRange_T.cpp:62
gnsstk::CommonTime::END_OF_TIME
static const GNSSTK_EXPORT CommonTime END_OF_TIME
latest representable CommonTime
Definition: CommonTime.hpp:104
gnsstk::TimeRange::isSubsetOf
bool isSubsetOf(const TimeRange &right) const
Definition: TimeRange.cpp:249
TUASSERT
#define TUASSERT(EXPR)
Definition: TestUtil.hpp:63
TestUtil.hpp
gnsstk::CivilTime::convertToCommonTime
virtual CommonTime convertToCommonTime() const
Definition: CivilTime.cpp:75
TimeRange_T::eps
double eps
Definition: TimeRange_T.cpp:1284
TURETURN
#define TURETURN()
Definition: TestUtil.hpp:232
gnsstk::TimeRange::isAfter
bool isAfter(const TimeRange &right) const
Definition: TimeRange.cpp:258
TUPASS
#define TUPASS(MSG)
Definition: TestUtil.hpp:230
TimeRange_T::setToStringTest
int setToStringTest(void)
Definition: TimeRange_T.cpp:791
gnsstk::CommonTime
Definition: CommonTime.hpp:84
gnsstk::TimeRange::set
void set(const CommonTime &startDT, const CommonTime &endDT, const bool startInclusive=true, const bool endInclusive=true)
Definition: TimeRange.cpp:120
CivilTime.hpp
TUDEF
#define TUDEF(CLASS, METHOD)
Definition: TestUtil.hpp:56
gnsstk::TimeRange::dump
std::string dump(const std::string formatArg="%02m/%02d/%02y %02H:%02M:%02S") const
Dump method.
Definition: TimeRange.cpp:394
gnsstk::GPSWeekZcount
Definition: GPSWeekZcount.hpp:55
gnsstk::CivilTime
Definition: CivilTime.hpp:55
TimeRange_T::printfTest
int printfTest(void)
Definition: TimeRange_T.cpp:1163
gnsstk::CivilTime::getDefaultFormat
virtual std::string getDefaultFormat() const
Return a string containing the default format to use in printing.
Definition: CivilTime.hpp:157
Exception.hpp
CommonTime.hpp
BasicFramework.hpp
std
Definition: Angle.hpp:142
TimeRange_T::TimeRange_T
TimeRange_T()
Definition: TimeRange_T.cpp:58
gnsstk::TimeRange::DTPair
std::pair< CommonTime, CommonTime > DTPair
Definition: TimeRange.hpp:65
TimeRange_T::inRangeTest
int inRangeTest(void)
Definition: TimeRange_T.cpp:250
TimeRange_T::equalsOperatorTest
int equalsOperatorTest(void)
Definition: TimeRange_T.cpp:1010
gnsstk::TimeRange::getEnd
CommonTime getEnd() const
Definition: TimeRange.hpp:91
TimeRange_T::isAfterTest
int isAfterTest(void)
Definition: TimeRange_T.cpp:665
TimeRange_T
Definition: TimeRange_T.cpp:55
TimeRange.hpp
TimeRange_T::overlapsTest
int overlapsTest(void)
Definition: TimeRange_T.cpp:418
TimeRange_T::dumpTest
int dumpTest(void)
Definition: TimeRange_T.cpp:1225
gnsstk::TimeRange::setToString
TimeRange & setToString(const std::string &str, const std::string &fmt)
Definition: TimeRange.cpp:274
TimeRange_T::isPriorToTest
int isPriorToTest(void)
Definition: TimeRange_T.cpp:324
gnsstk::TimeRange::getStart
CommonTime getStart() const
Definition: TimeRange.hpp:90
TimeRange_T::constructorTest
int constructorTest(void)
Definition: TimeRange_T.cpp:67
TimeRange_T::isSubsetOfTest
int isSubsetOfTest(void)
Definition: TimeRange_T.cpp:542


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