DayTimeIncrementTest.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: DayTimeIncrementTest.cpp 2741 2011-06-22 16:37:02Z nwu $"
00002 
00003 //============================================================================
00004 //
00005 //  This file is part of GPSTk, the GPS Toolkit.
00006 //
00007 //  The GPSTk is free software; you can redistribute it and/or modify
00008 //  it under the terms of the GNU Lesser General Public License as published
00009 //  by the Free Software Foundation; either version 2.1 of the License, or
00010 //  any later version.
00011 //
00012 //  The GPSTk is distributed in the hope that it will be useful,
00013 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 //  GNU Lesser General Public License for more details.
00016 //
00017 //  You should have received a copy of the GNU Lesser General Public
00018 //  License along with GPSTk; if not, write to the Free Software Foundation,
00019 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 //
00021 //  Copyright 2006, The University of Texas at Austin
00022 //
00023 //============================================================================
00024 
00025 /* \example DayTimeToleranceTest.cpp
00026  * This test evaluates user defined comparison tolerance feature of DayTime.
00027  * It merely increments then decrements DayTime in different ways, then
00028  * reports to the user the estimate of machine error.
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          // Set the DayTimes using Year, Month, Day, Hour, Minute, Second.
00074       gpstk::DayTime dtorig(2000,12,1,0,0,0.0), dtcopy;
00075 
00076          // Used to time the test.
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 }

Generated on Thu Feb 9 03:30:55 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1