00001 #pragma ident "$Id: DayTimeIncrementTest.cpp 2741 2011-06-22 16:37:02Z nwu $"
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
00030
00031 #include <iostream>
00032 #include <iomanip>
00033
00034 #include "StringUtils.hpp"
00035 #include "DayTime.hpp"
00036 #include "icd_200_constants.hpp"
00037
00038 using namespace std;
00039 using namespace gpstk;
00040
00041 #define TEST_METHOD(method, incCount, incValue, diffTolerance) \
00042 dtcopy = dtorig; \
00043 totalIncrements=0; \
00044 incCountUse = incCount/2; \
00045 for (long j=0; j<incCountUse; ++j) \
00046 { \
00047 dtcopy.method(incValue); \
00048 totalIncrements++; \
00049 } \
00050 for (long j=0; j<incCountUse; ++j) \
00051 { \
00052 dtcopy.method(-incValue); \
00053 totalIncrements++; \
00054 } \
00055 tdiff = dtcopy-dtorig; \
00056 cout << setw(18) << #method; \
00057 cout << setw(18) << totalIncrements; \
00058 cout << setw(22) << setprecision(10) << tdiff; \
00059 cout << setw(21) << setprecision(8) << tdiff * C_GPS_M; \
00060 cout << setw(23) << setprecision(5) << diffTolerance; \
00061 cout << endl; \
00062 cumulativeResult = cumulativeResult && \
00063 ( fabs(tdiff)<diffTolerance );
00064
00065
00067 int main()
00068 {
00069 try
00070 {
00071 cout << endl << "Testing DayTime increment safety." << endl << endl;
00072
00073
00074 gpstk::DayTime dtorig(2000,12,1,0,0,0.0), dtcopy;
00075
00076
00077 DayTime startTime;
00078 bool cumulativeResult = true;
00079 double tdiff;
00080 long totalIncrements=0;
00081 long incCountUse;
00082
00083 cout << setw(18) << "Increment operator";
00084 cout << setw(18) << "# of increments";
00085 cout << setw(22) << "Difference (seconds)";
00086 cout << setw(21) << "Difference (meters)";
00087 cout << setw(23) << "Acceptable Diff (sec)";
00088
00089
00090 cout << endl;
00091
00092 cout << setw(18) << "------------------";
00093 cout << setw(18) << "---------------";
00094 cout << setw(22) << "--------------------";
00095 cout << setw(21) << "-------------------";
00096 cout << setw(23) << "--------------------";
00097 cout << endl;
00098
00099 TEST_METHOD(operator+=, 60, 1, 1e-15)
00100 TEST_METHOD(operator+=, 3600, 1, 1e-15)
00101 TEST_METHOD(operator+=, 86400, 1, 1e-15)
00102 TEST_METHOD(operator+=, 7*86400, 1, 1e-15)
00103 cout << endl;
00104
00105
00106 TEST_METHOD(addMilliSeconds, 1000, 1, 1e-15)
00107 TEST_METHOD(addMilliSeconds, 60*1000, 1, 1e-15)
00108 TEST_METHOD(addMilliSeconds, 3600*1000, 1, 1e-15)
00109 TEST_METHOD(addMilliSeconds, 86400*1000, 1, 1e-15)
00110 TEST_METHOD(addMilliSeconds, 86400*2*1000, 1, 1e-15)
00111 TEST_METHOD(addMilliSeconds, 86400*7*1000, 1, 1e-15)
00112 cout << endl;
00113
00114 TEST_METHOD(addMicroSeconds, 1000*1000, 1, 1e-3)
00115 TEST_METHOD(addMicroSeconds, 60*1000*1000, 1, 1e-3)
00116 TEST_METHOD(addMicroSeconds, 5*60*1000*1000, 1, 1e-3)
00117 cout << endl;
00118
00119 DayTime endTime;
00120
00121
00122 cout << endl << setprecision(4);
00123 cout << endTime.printf("Completed on %B %d, %Y %H:%02M:%02S") << endl;
00124 cout << "Processing time " << endTime-startTime << " seconds." << endl;
00125 cout << endl;
00126
00127 int ret = 0;
00128 if (cumulativeResult)
00129 cout << "All comparison tests PASSED." << endl;
00130 else
00131 {
00132 cout << "One ore more comparison tests FAILED." << endl;
00133 ret = 1;
00134 }
00135
00136 cout << endl;
00137
00138 return ret;
00139 }
00140 catch(gpstk::Exception& e)
00141 {
00142 cout << e << endl;
00143 }
00144 catch(...)
00145 {
00146 cout << "Some other exception thrown..." << endl;
00147 }
00148
00149 cout << "Exiting with exceptions." << endl;
00150 return -1;
00151 }