IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 6, 2004, 2:31:55 PM (22 years ago)
Author:
gusciora
Message:

Most of these tests work.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/dataManip/tst_psStats02.c

    r717 r887  
    11/*****************************************************************************
    22    This routine must ensure that PS_STAT_MIN is correctly computed
    3     by the procedure psArrayStats().
     3    by the procedure psVectorStats().
    44 *****************************************************************************/
    55#include <stdio.h>
     
    1111{
    1212    psStats *myStats    = NULL;
    13     psStats *myStats2   = NULL;
    1413    int testStatus      = true;
     14    int globalTestStatus = true;
    1515    int i               = 0;
    1616    psVector *myVector  = NULL;
    1717    psVector *maskVector= NULL;
    1818    float min           = 1e99;
    19     float realMin1      = 1e99;
    20     float realMin2      = 1e99;
     19    float realMinNoMask   = 1e99;
     20    float realMinWithMask = 1e99;
     21    int currentId       = psMemGetId();
     22    int memLeaks        = 0;
    2123
    22     printPositiveTestHeader(stdout,
    23                             "psStats functions",
    24                             "PS_STAT_MIN");
    25 
     24    /*************************************************************************/
     25    /*  Allocate and initialize data structures                      */
     26    /*************************************************************************/
    2627    myStats = psStatsAlloc(PS_STAT_MIN);
    27     myVector = psVectorAlloc(PS_TYPE_FLOAT, N);
     28    myVector = psVectorAlloc(N, PS_TYPE_F32);
    2829    myVector->n = N;
    29     maskVector = psVectorAlloc(PS_TYPE_UINT8, N);
     30    maskVector = psVectorAlloc(N, PS_TYPE_U8);
    3031    maskVector->n = N;
    3132
     33    // Set the appropriate values for the vector data.
    3234    for (i=0;i<N;i++) {
    33         myVector->vec.f[i] = (float) i;
     35        myVector->data.F32[i] = (float) i;
     36    }
     37
     38    // Set the mask vector and calculate the expected minimum.
     39    for (i=0;i<N;i++) {
     40        if (myVector->data.F32[i] < realMinNoMask) {
     41            realMinNoMask = myVector->data.F32[i];
     42        }
     43
    3444        if (i < (N/2)) {
    35             maskVector->vec.ui8[i] = 0;
    36             if (myVector->vec.f[i] < realMin2) {
    37                 realMin2 = myVector->vec.f[i];
    38             }
     45            maskVector->data.U8[i] = 1;
    3946        } else {
    40             printf("Masking element %d\n", i);
    41             maskVector->vec.ui8[i] = 1;
    42             if (myVector->vec.f[i] < realMin1) {
    43                 realMin1 = myVector->vec.f[i];
     47            maskVector->data.U8[i] = 0;
     48            if (myVector->data.F32[i] < realMinWithMask) {
     49                realMinWithMask = myVector->data.F32[i];
    4450            }
    4551        }
    4652    }
    4753
    48     myStats2 = psArrayStats(myVector, NULL, 0, myStats);
    49     min = myStats2->min;
     54    /*************************************************************************/
     55    /*  Call psVectorStats() with no vector mask.                    */
     56    /*************************************************************************/
     57    printPositiveTestHeader(stdout,
     58                            "psStats functions",
     59                            "PS_STAT_MIN: no vector mask");
    5060
    51     printf("Called psArrayStats() on a vector with no elements masked.\n");
    52     printf("The expected min was %f; the calculated min was %f\n", realMin1, min);
    53     if (min == realMin1) {
     61    myStats = psVectorStats(myStats, myVector, NULL, 0);
     62    min = myStats->min;
     63
     64    printf("Called psVectorStats() on a vector with no elements masked.\n");
     65    printf("The expected min was %f; the calculated min was %f\n",
     66           realMinNoMask, min);
     67    if (min == realMinNoMask) {
    5468        testStatus = true;
    5569    } else {
    5670        testStatus = false;
     71        globalTestStatus = false;
    5772    }
     73    printFooter(stdout,
     74                "psVector functions",
     75                "PS_STAT_MIN: no vector mask",
     76                testStatus);
    5877
    59     myStats2 = psArrayStats(myVector, maskVector, 1, myStats);
    60     min = myStats2->min;
    61     printf("Called psArrayStats() on a vector with last N/2 elements masked.\n");
    62     printf("The expected min was %f; the calculated min was %f\n", realMin2, min);
    63     if (min == realMin2) {
     78    /*************************************************************************/
     79    /*  Call psVectorStats() with vector mask.                       */
     80    /*************************************************************************/
     81    printPositiveTestHeader(stdout,
     82                            "psStats functions",
     83                            "PS_STAT_MIN: with vector mask");
     84
     85    myStats = psVectorStats(myStats, myVector, maskVector, 1);
     86    min = myStats->min;
     87    printf("Called psVectorStats() on a vector with last N/2 elements masked.\n");
     88    printf("The expected min was %f; the calculated min was %f\n",
     89           realMinWithMask, min);
     90    if (min == realMinWithMask) {
    6491        testStatus = true;
    6592    } else {
    6693        testStatus = false;
     94        globalTestStatus = false;
    6795    }
    6896
    6997    printFooter(stdout,
    70                 "psHash functions",
    71                 "psHashAlloc()",
     98                "psVector functions",
     99                "PS_STAT_MIN: with vector mask",
    72100                testStatus);
    73101
    74     return (!testStatus);
     102    /*************************************************************************/
     103    /*  Deallocate data structures                                   */
     104    /*************************************************************************/
     105    printPositiveTestHeader(stdout,
     106                            "psStats functions",
     107                            "psStats(): deallocating memory");
     108
     109    psStatsFree(myStats);
     110    psVectorFree(myVector);
     111    psVectorFree(maskVector);
     112
     113    psMemCheckCorruption(1);
     114    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
     115    if (0 != memLeaks) {
     116        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
     117    }
     118
     119    printFooter(stdout,
     120                "psVector functions",
     121                "psStats(): deallocating memory",
     122                testStatus);
     123
     124    return (!globalTestStatus);
    75125}
Note: See TracChangeset for help on using the changeset viewer.