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_psStats01.c

    r717 r887  
    11/*****************************************************************************
    22    This routine must ensure that PS_STAT_MAX 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 max           = 0.0;
    19     float realMax1      = 0.0;
    20     float realMax2      = 0.0;
     19    float realMaxNoMask   = 0.0;
     20    float realMaxWithMask = 0.0;
     21    int currentId       = psMemGetId();
     22    int memLeaks        = 0;
    2123
    22     printPositiveTestHeader(stdout,
    23                             "psStats functions",
    24                             "PS_STAT_MAX");
    25 
     24    /*************************************************************************/
     25    /*  Allocate and initialize data structures                      */
     26    /*************************************************************************/
    2627    myStats = psStatsAlloc(PS_STAT_MAX);
    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 maximum.
     39    for (i=0;i<N;i++) {
     40        if (myVector->data.F32[i] > realMaxNoMask) {
     41            realMaxNoMask = myVector->data.F32[i];
     42        }
     43
    3444        if (i < (N/2)) {
    35             maskVector->vec.ui8[i] = 0;
    36             if (myVector->vec.f[i] > realMax2) {
    37                 realMax2 = myVector->vec.f[i];
     45            maskVector->data.U8[i] = 0;
     46
     47            if (myVector->data.F32[i] > realMaxWithMask) {
     48                realMaxWithMask = myVector->data.F32[i];
    3849            }
    3950        } else {
     51            maskVector->data.U8[i] = 1;
    4052            printf("Masking element %d\n", i);
    41             maskVector->vec.ui8[i] = 1;
    42             if (myVector->vec.f[i] > realMax1) {
    43                 realMax1 = myVector->vec.f[i];
    44             }
    4553        }
    4654    }
    4755
    48     myStats2 = psArrayStats(myVector, NULL, 0, myStats);
    49     max = myStats2->max;
     56    /*************************************************************************/
     57    /*  Call psVectorStats() with no vector mask.                    */
     58    /*************************************************************************/
     59    printPositiveTestHeader(stdout,
     60                            "psStats functions",
     61                            "PS_STAT_MAX: no vector mask");
    5062
    51     printf("Called psArrayStats() on a vector with no elements masked.\n");
    52     printf("The expected max was %f; the calculated max was %f\n", realMax1, max);
    53     if (max == realMax1) {
     63    myStats = psVectorStats(myStats, myVector, NULL, 0);
     64    max = myStats->max;
     65
     66    printf("Called psVectorStats() on a vector with no elements masked.\n");
     67    printf("The expected max was %f; the calculated max was %f\n", realMaxNoMask, max);
     68    if (max == realMaxNoMask) {
    5469        testStatus = true;
    5570    } else {
    5671        testStatus = false;
     72        globalTestStatus = false;
    5773    }
     74    printFooter(stdout,
     75                "psVector functions",
     76                "PS_STAT_MAX: no vector mask",
     77                testStatus);
    5878
    59     myStats2 = psArrayStats(myVector, maskVector, 1, myStats);
    60     max = myStats2->max;
    61     printf("Called psArrayStats() on a vector with last N/2 elements masked.\n");
    62     printf("The expected max was %f; the calculated max was %f\n", realMax2, max);
    63     if (max == realMax2) {
     79    /*************************************************************************/
     80    /*  Call psVectorStats() with vector mask.                       */
     81    /*************************************************************************/
     82    printPositiveTestHeader(stdout,
     83                            "psStats functions",
     84                            "PS_STAT_MAX: with vector mask");
     85
     86    myStats = psVectorStats(myStats, myVector, maskVector, 1);
     87    max = myStats->max;
     88    printf("Called psVectorStats() on a vector with last N/2 elements masked.\n");
     89    printf("The expected max was %f; the calculated max was %f\n", realMaxWithMask, max);
     90    if (max == realMaxWithMask) {
    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_MAX: 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.