00001 #pragma ident "$Id: DayTimeToleranceTest.cpp 1895 2009-05-12 19:34:29Z afarris $"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <iostream>
00030
00031 #include "StringUtils.hpp"
00032 #include "DayTime.hpp"
00033
00034 using namespace std;
00035
00037 int main()
00038 {
00039 using gpstk::DayTime;
00040
00041 try
00042 {
00043 cout << "Testing DayTime tolerances." << endl;
00044
00045
00046 gpstk::DayTime dt1(2000,12,1,0,0,0.0),
00047 dt2(2000,12,1,0,0,0.0);
00048
00049 int nCases = 11;
00050 double secDiff[]=
00051 { 1.01, 1.0, .99, .5, .25, .0, -.25, -.5, -.99, -1.0, - 1.01 };
00052
00053 bool oneSecTolPass[]=
00054 { false, true, true, true, true, true, true, true, true, true, false};
00055
00056 bool halfSecTolPass[]=
00057 { false, false, false, true, true, true, true, true, false, false, false};
00058
00059 cout << " Time 1 Time 2 "
00060 " diff 1 sec 0.5 sec" << endl;
00061
00062 string equal( " Equal");
00063 string inequal(" Inequal");
00064
00065 bool cumulativeResult = true;
00066
00067 for (int i=0; i<nCases; i++)
00068 {
00069 dt2 = dt1 + secDiff[i];
00070 string fmt("%m/%d/%Y %02H:%02M:%07.4f");
00071 cout << setw(24) << dt1.printf(fmt) << " "
00072 << setw(24) << dt2.printf(fmt) << " "
00073 << setw(5) << dt2 - dt1 << " ";
00074
00075
00076 dt1.setTolerance(gpstk::DayTime::ONE_SEC_TOLERANCE);
00077 dt2.setTolerance(gpstk::DayTime::ONE_SEC_TOLERANCE);
00078
00079 cout << (oneSecTolPass[i] ? equal : inequal)
00080 << ((dt1 == dt2) ? equal : inequal) ;
00081
00082 cumulativeResult = cumulativeResult && (oneSecTolPass[i]==(dt1==dt2));
00083
00084
00085 dt1.setTolerance(gpstk::DayTime::ONE_SEC_TOLERANCE * 0.5);
00086 dt2.setTolerance(gpstk::DayTime::ONE_SEC_TOLERANCE * 0.5);
00087
00088 cout << (halfSecTolPass[i] ? equal : inequal)
00089 << ((dt1 == dt2) ? equal : inequal)
00090 << endl ;
00091
00092 cumulativeResult = cumulativeResult &&
00093 (halfSecTolPass[i]==(dt1==dt2));
00094
00095 }
00096
00097 cout << endl;
00098 cout << DayTime().printf("Completed on %B %d, %Y %H:%02M:%02S");
00099 cout << endl << endl;
00100
00101 int ret = 0;
00102 if (cumulativeResult)
00103 cout << "All comparison tests PASSED." << endl;
00104 else
00105 {
00106 cout << "One ore more comparison tests FAILED." << endl;
00107 ret = 1;
00108 }
00109
00110 return ret;
00111 }
00112 catch(gpstk::Exception& e)
00113 {
00114 cout << e << endl;
00115 }
00116 catch(...)
00117 {
00118 cout << "Some other exception thrown..." << endl;
00119 }
00120
00121 cout << "Exiting with exceptions." << endl;
00122 return -1;
00123 }