DayTimeToleranceTest.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: DayTimeToleranceTest.cpp 1895 2009-05-12 19:34:29Z afarris $"
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 2009, 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  */
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          // Set the DayTimes using Year, Month, Day, Hour, Minute, Second.
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          // column widths: 24 24 5 7 7 7 7
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             // Set dt1 and dt2 to one second tolerance.
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             // Set dt1 and dt2 to half second tolerance.
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 }

Generated on Tue May 22 03:30:57 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1