IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 16, 2004, 8:53:35 AM (22 years ago)
Author:
harman
Message:

Added new time math functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/astronomy/tst_psTime_03.c

    r2681 r2725  
    1212 *  @author  Ross Harman, MHPCC
    1313 *
    14  *  @version $Revision: 1.5 $  $Name: not supported by cvs2svn $
    15  *  @date  $Date: 2004-12-10 02:50:15 $
     14 *  @version $Revision: 1.6 $  $Name: not supported by cvs2svn $
     15 *  @date  $Date: 2004-12-16 18:53:28 $
    1616 *
    1717 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    3030    // Test A - Add two times
    3131    printPositiveTestHeader(stdout, "psTime", "Test A - Add two times");
    32     psTime *time1a   = NULL;
    33     psTime *time1b   = NULL;
     32    psTime *time1a = NULL;
     33    psF64 time1b = 1.111111;
    3434    psTime *timeOut1 = NULL;
    35     time1a = psTimeAlloc(PS_TIME_UTC);
    36     time1b = psTimeAlloc(PS_TIME_UTC);
     35    time1a = psTimeAlloc(PS_TIME_TAI);
    3736    time1a->sec  = 1;
    3837    time1a->usec = 111111;
    39     time1b->sec  = 1;
    40     time1b->usec = 111111;
    41     timeOut1 = psTimeAdd(time1a, time1b);
    42     PRINT_TIME("Time 1:",time1a);
    43     PRINT_TIME("Time 2:",time1b);
    44     PRINT_TIME("Output Time:",timeOut1);
     38    timeOut1 = psTimeMath(time1a, time1b);
     39    if(timeOut1->sec!=2 && timeOut1->usec!=222222) {
     40        printf("ERROR: Incorrect time, %lld:%u. Expected 2:222222\n",timeOut1->sec, timeOut1->usec);
     41    }
    4542    printFooter(stdout, "psTime", "Test A - Add two times", true);
     43
    4644
    4745    // Test B - Add two times with overflow in microseconds
    4846    printPositiveTestHeader(stdout, "psTime", "Test B - Add two times with overflow in microseconds");
    49     psTime *time2a   = NULL;
    50     psTime *time2b   = NULL;
     47    psTime *time2a = NULL;
     48    psF64 time2b = 5.500001;
    5149    psTime *timeOut2 = NULL;
    52     time2a = psTimeAlloc(PS_TIME_UTC);
    53     time2b = psTimeAlloc(PS_TIME_UTC);
     50    time2a = psTimeAlloc(PS_TIME_TAI);
    5451    time2a->sec  = 6;
    5552    time2a->usec = 600001;
    56     time2b->sec  = 5;
    57     time2b->usec = 500001;
    58     timeOut2 = psTimeAdd(time2a, time2b);
    59     PRINT_TIME("Time 1:",time2a);
    60     PRINT_TIME("Time 2:",time2b);
    61     PRINT_TIME("Output Time:",timeOut2);
     53    timeOut2 = psTimeMath(time2a, time2b);
     54    if(timeOut2->sec!=12 && timeOut2->usec!=100002) {
     55        printf("ERROR: Incorrect time, %lld:%u. Expected 12:100002\n",timeOut2->sec, timeOut2->usec);
     56    }
    6257    printFooter(stdout, "psTime", "Test B - Add two times with overflow in microseconds", true);
    6358
     
    6560    // Test C - Subtact two times
    6661    printPositiveTestHeader(stdout, "psTime", "Test C - Subtract two times");
    67     psTime *time3a   = NULL;
    68     psTime *time3b   = NULL;
     62    psTime *time3a = NULL;
     63    psF64 time3b = -1.111111;
    6964    psTime *timeOut3 = NULL;
    70     time3a = psTimeAlloc(PS_TIME_UTC);
    71     time3b = psTimeAlloc(PS_TIME_UTC);
     65    time3a = psTimeAlloc(PS_TIME_TAI);
    7266    time3a->sec  = 3;
    7367    time3a->usec = 333333;
    74     time3b->sec  = 1;
    75     time3b->usec = 111111;
    76     timeOut3 = psTimeSubtract(time3a, time3b);
    77     PRINT_TIME("Time 1:",time3a);
    78     PRINT_TIME("Time 2:",time3b);
    79     PRINT_TIME("Output Time:",timeOut3);
     68    timeOut3 = psTimeMath(time3a, time3b);
     69    if(timeOut3->sec!=2 && timeOut3->usec!=222222) {
     70        printf("ERROR: Incorrect time, %lld:%u. Expected 2:222222\n",timeOut3->sec, timeOut3->usec);
     71    }
    8072    printFooter(stdout, "psTime", "Test C - Subtract two times", true);
    8173
     
    8375    // Test D - Subtact two times with underflow in microseconds
    8476    printPositiveTestHeader(stdout, "psTime", "Test D - Subtact two times with underflow in microseconds");
    85     psTime *time4a   = NULL;
    86     psTime *time4b   = NULL;
     77    psTime *time4a = NULL;
     78    psF64 time4b = -2.000003;
    8779    psTime *timeOut4 = NULL;
    88     time4a = psTimeAlloc(PS_TIME_UTC);
    89     time4b = psTimeAlloc(PS_TIME_UTC);
     80    time4a = psTimeAlloc(PS_TIME_TAI);
    9081    time4a->sec  = 5;
    9182    time4a->usec = 1;
    92     time4b->sec  = 2;
    93     time4b->usec = 3;
    94     timeOut4 = psTimeSubtract(time4a, time4b);
    95     PRINT_TIME("Time 1:",time4a);
    96     PRINT_TIME("Time 2:",time4b);
    97     PRINT_TIME("Output Time:",timeOut4);
     83    timeOut4 = psTimeMath(time4a, time4b);
     84    if(timeOut4->sec!=2 && timeOut4->usec!=999997) {
     85        printf("ERROR: Incorrect time, %lld:%u. Expected 2:999997\n",timeOut4->sec, timeOut4->usec);
     86    }
    9887    printFooter(stdout, "psTime", "Test D - Subtact two times with underflow in microseconds", true);
     88
    9989
    10090    // Test E - Delta two times
    10191    printPositiveTestHeader(stdout, "psTime", "Test E - Delta two times");
    102     psTime *time5a   = NULL;
    103     psTime *time5b   = NULL;
    104     psTime *timeOut5 = NULL;
    105     time5a = psTimeAlloc(PS_TIME_UTC);
    106     time5b = psTimeAlloc(PS_TIME_UTC);
    107     time5a->sec  = 2;
    108     time5a->usec = 1;
    109     time5b->sec  = 5;
    110     time5b->usec = 3;
     92    psTime *time5a = NULL;
     93    psTime *time5b = NULL;
     94    psF64 timeOut5 = 0.0;
     95    time5a = psTimeAlloc(PS_TIME_TAI);
     96    time5b = psTimeAlloc(PS_TIME_TAI);
     97    time5a->sec  = 8;
     98    time5a->usec = 8;
     99    time5b->sec  = 7;
     100    time5b->usec = 7;
    111101    timeOut5 = psTimeDelta(time5a, time5b);
    112     PRINT_TIME("Time 1:",time5a);
    113     PRINT_TIME("Time 2:",time5b);
    114     PRINT_TIME("Output Time:",timeOut5);
     102    if(fabs(timeOut5-1.000001) > FLT_EPSILON) {
     103        printf("ERROR: Incorrect delta, %lf. Expected -1.000001\n", timeOut5);
     104    }
    115105    printFooter(stdout, "psTime", "Test E - Delta two times", true);
    116106
    117107
    118     // Test D - Free data
    119     printPositiveTestHeader(stdout, "psTime", "Test D - Free data");
     108    // Test F - Delta two times with underflow in microseconds
     109    printPositiveTestHeader(stdout, "psTime", "Test F - Delta two times with underflow in microseconds");
     110    psTime *time6a = NULL;
     111    psTime *time6b = NULL;
     112    psF64 timeOut6 = 0.0;
     113    time6a = psTimeAlloc(PS_TIME_TAI);
     114    time6b = psTimeAlloc(PS_TIME_TAI);
     115    time6a->sec  = 8;
     116    time6a->usec = 1;
     117    time6b->sec  = 7;
     118    time6b->usec = 7;
     119    timeOut6 = psTimeDelta(time6a, time6b);
     120    if(fabs(timeOut6-0.999994) > FLT_EPSILON) {
     121        printf("ERROR: Incorrect delta, %lf. Expected 0.999994\n", timeOut6);
     122    }
     123    printFooter(stdout, "psTime", "Test F - Delta two times with underflow in microseconds", true);
     124
     125
     126    // Test G - Add two times across leapsecond boundary
     127    printPositiveTestHeader(stdout, "psTime", "Test G - Add two times across leapsecond boundary");
     128    psF64 time7b = 30.0;
     129    char *out7 = NULL;
     130    psTime *time7a = NULL;
     131    psTime *timeOut7 = NULL;
     132    time7a = psTimeFromISOTime("1998-12-31T23:59:45.00");
     133    time7a->type = PS_TIME_UTC;
     134    timeOut7 = psTimeMath(time7a, time7b);
     135    out7 = psTimeToISOTime(timeOut7);
     136    printf("%s\n", out7);
     137    printFooter(stdout, "psTime", "Test G - Add two times across leapsecond boundary", true);
     138
     139
     140    // Test G - Free data
     141    printPositiveTestHeader(stdout, "psTime", "Test G - Free data");
     142    psLibFinalize();
    120143    psFree(time1a);
    121     psFree(time1b);
    122144    psFree(timeOut1);
    123145    psFree(time2a);
    124     psFree(time2b);
    125146    psFree(timeOut2);
    126147    psFree(time3a);
    127     psFree(time3b);
    128148    psFree(timeOut3);
    129149    psFree(time4a);
    130     psFree(time4b);
    131150    psFree(timeOut4);
    132151    psFree(time5a);
    133152    psFree(time5b);
    134     psFree(timeOut5);
    135     if ( psMemCheckLeaks(0, NULL, stdout,false) ) {
     153    psFree(time6a);
     154    psFree(time6b);
     155    psFree(out7);
     156    psFree(time7a);
     157    psFree(timeOut7);
     158    if (psMemCheckLeaks(0, NULL, stdout,false)) {
    136159        psError(PS_ERR_UNKNOWN,true,"Memory leaks detected.");
    137160        return 10;
     
    142165        printf("ERROR: Found %d bad memory blocks\n", nBad);
    143166    }
    144     printFooter(stdout, "psTime", "Test D - Free data", true);
     167    printFooter(stdout, "psTime", "Test G - Free data", true);
    145168    return 0;
    146169}
Note: See TracChangeset for help on using the changeset viewer.