IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 887


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

Most of these tests work.

Location:
trunk/psLib/test
Files:
13 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/dataManip/Makefile

    r815 r887  
    33##  Makefile:   test/sysUtils
    44##
    5 ##  $Revision: 1.8 $  $Name: not supported by cvs2svn $
    6 ##  $Date: 2004-05-29 01:15:41 $
     5##  $Revision: 1.9 $  $Name: not supported by cvs2svn $
     6##  $Date: 2004-06-07 00:31:55 $
    77##
    88##  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1717
    1818TARGET = tst_psMatrix01 \
    19          tst_psMatrix02 \
    20          tst_psMatrix03 \
    21          tst_psMatrix04 \
    22          tst_psMatrix05 \
    23          tst_psMatrix06 \
    24          tst_psMatrix07
    25 #         tst_psStats00 \
    26 #         tst_psStats01 \
    27 #         tst_psStats02 \
    28 #         tst_psStats03 \
    29 #         tst_psStats04
     19 tst_psMatrix02 \
     20 tst_psMatrix03 \
     21 tst_psMatrix04 \
     22 tst_psMatrix05 \
     23 tst_psMatrix06 \
     24 tst_psMatrix07 \
     25 tst_psStats00 \
     26 tst_psStats01 \
     27 tst_psStats02 \
     28 tst_psStats03 \
     29 tst_psStats05 \
     30 tst_psStats06 \
     31 tst_psStats07 \
     32 tst_psStats08 \
     33 tst_psStats09 \
     34 tst_psHist00 \
     35 tst_psHist01 \
     36 tst_psHist02 \
     37 tst_psFunc00 \
     38 tst_psFunc01 \
     39 tst_psImageStats00 \
     40 tst_psImageStats01 \
     41 tst_psImageStats02
    3042
    3143all: $(TARGET)
     
    4355tst_psStats03:          tst_psStats03.o
    4456tst_psStats04:          tst_psStats04.o
     57tst_psStats05:          tst_psStats05.o
     58tst_psStats06:          tst_psStats06.o
     59tst_psStats07:          tst_psStats07.o
     60tst_psStats08:          tst_psStats08.o
     61tst_psStats09:          tst_psStats09.o
     62tst_psHist00:           tst_psHist00.o
     63tst_psHist01:           tst_psHist01.o
     64tst_psHist02:           tst_psHist02.o
     65tst_psFunc00:           tst_psFunc00.o
     66tst_psFunc01:           tst_psFunc01.o
     67tst_psFunc02:           tst_psFunc02.o
     68tst_psFunc03:           tst_psFunc03.o
     69tst_psImageStats00:     tst_psImageStats00.o
     70tst_psImageStats01:     tst_psImageStats01.o
     71tst_psImageStats02:     tst_psImageStats02.o
     72tst_psImageStats03:     tst_psImageStats03.o
    4573
    4674clean:
     
    5482        $(CC) -o $@ $< -L$(PSLIB_LIB_DIR) -lpslib -lpstest -lgsl -lgslcblas $(LDFLAGS)
    5583
     84## NOTE: The distclean target does not remove the .o files.  The Makefiles must
     85## be repaired.
     86distclean:
     87        $(RM) $(TARGET)
     88
    5689%.lint: %.c
    5790        splint +posixlib -exportlocal -realcompare $(INCLUDE_GLOBAL) $? > $@; cat $@
  • trunk/psLib/test/dataManip/tst_psStats00.c

    r717 r887  
    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 mean          = 0.0;
    19     float realMean   = 0.0;
    20     float realMean2    = 0.0;
     19    float realMeanNoMask   = 0.0;
     20    float realMeanWithMask = 0.0;
    2121    int count           = 0;
     22    int currentId       = psMemGetId();
     23    int memLeaks        = 0;
    2224
    23     printPositiveTestHeader(stdout,
    24                             "psStats functions",
    25                             "PS_STAT_SAMPLE_MEAN");
    26 
     25    /*************************************************************************/
     26    /*  Allocate and initialize data structures                      */
     27    /*************************************************************************/
    2728    myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
    28     myVector = psVectorAlloc(PS_TYPE_FLOAT, N);
     29    myVector = psVectorAlloc(N, PS_TYPE_F32);
    2930    myVector->n = N;
    30     maskVector = psVectorAlloc(PS_TYPE_UINT8, N);
     31    maskVector = psVectorAlloc(N, PS_TYPE_U8);
    3132    maskVector->n = N;
    3233
    3334    mean = 0.0;
    34     realMean2 = 0.0;
     35    realMeanWithMask = 0.0;
     36    // Set the appropriate values for the vector data.
    3537    for (i=0;i<N;i++) {
    36         myVector->vec.f[i] = (float) i;
     38        myVector->data.F32[i] = (float) i;
     39    }
     40
     41    // Set the mask vector and calculate the expected maximum.
     42    for (i=0;i<N;i++) {
     43        realMeanNoMask+= myVector->data.F32[i];
     44
    3745        if (i < (N/2)) {
    38             maskVector->vec.ui8[i] = 0;
    39             realMean2+= myVector->vec.f[i];
     46            maskVector->data.U8[i] = 0;
     47            realMeanWithMask+= myVector->data.F32[i];
    4048            count++;
    4149        } else {
    42             printf("Masking element %d\n", i);
    43             maskVector->vec.ui8[i] = 1;
     50            maskVector->data.U8[i] = 1;
    4451        }
    45         realMean1+= myVector->vec.f[i];
    4652    }
    47     realMean1 /= (float) N;
    48     realMean2 /= (float) count;
     53    realMeanNoMask /= (float) N;
     54    realMeanWithMask /= (float) count;
    4955
    50     myStats2 = psArrayStats(myVector, NULL, 0, myStats);
    51     mean = myStats2->sampleMean;
     56    /*************************************************************************/
     57    /*  Call psVectorStats() with no vector mask.                    */
     58    /*************************************************************************/
     59    printPositiveTestHeader(stdout,
     60                            "psStats functions",
     61                            "PS_STAT_SAMPLE_MEAN: no vector mask");
    5262
    53     printf("Called psArrayStats() on a vector with no elements masked.\n");
    54     printf("The expected mean was %f; the calculated mean was %f\n", realMean1, mean);
    55     if (mean == realMean1) {
     63    myStats = psVectorStats(myStats, myVector, NULL, 0);
     64    mean = myStats->sampleMean;
     65
     66    printf("Called psVectorStats() on a vector with no elements masked.\n");
     67    printf("The expected mean was %f; the calculated mean was %f\n", realMeanNoMask, mean);
     68    if (mean == realMeanNoMask) {
    5669        testStatus = true;
    5770    } else {
    5871        testStatus = false;
     72        globalTestStatus = false;
    5973    }
     74    printFooter(stdout,
     75                "psVector functions",
     76                "PS_STAT_SAMPLE_MEAN: no vector mask",
     77                testStatus);
    6078
    61     myStats2 = psArrayStats(myVector, maskVector, 1, myStats);
    62     mean = myStats2->sampleMean;
    63     printf("Called psArrayStats() on a vector with last N/2 elements masked.\n");
    64     printf("The expected mean was %f; the calculated mean was %f\n", realMean2, mean);
    65     if (mean == realMean2) {
     79    /*************************************************************************/
     80    /*  Call psVectorStats() with vector mask.                       */
     81    /*************************************************************************/
     82    printPositiveTestHeader(stdout,
     83                            "psStats functions",
     84                            "PS_STAT_SAMPLE_MEAN: with vector mask");
     85
     86    myStats = psVectorStats(myStats, myVector, maskVector, 1);
     87    mean = myStats->sampleMean;
     88    printf("Called psVectorStats() on a vector with last N/2 elements masked.\n");
     89    printf("The expected mean was %f; the calculated mean was %f\n", realMeanWithMask, mean);
     90    if (mean == realMeanWithMask) {
    6691        testStatus = true;
    6792    } else {
    6893        testStatus = false;
     94        globalTestStatus = false;
    6995    }
    7096
    7197    printFooter(stdout,
    72                 "psHash functions",
    73                 "psHashAlloc()",
     98                "psVector functions",
     99                "PS_STAT_SAMPLE_MEAN: with vector mask",
    74100                testStatus);
    75101
    76     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);
    77125}
  • 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}
  • 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}
  • trunk/psLib/test/dataManip/tst_psStats03.c

    r779 r887  
    11/*****************************************************************************
    22    This routine must ensure that PS_STAT_SAMPLE_MEDIAN is correctly computed
    3     by the procedure psArrayStats().
     3    by the procedure psVectorStats().
    44 *****************************************************************************/
    55#include <stdio.h>
    66#include "pslib.h"
    77#include "psTest.h"
    8 #define N1 1029
     8#define N1 1029   // This should be an odd number.
    99#define N ((4 * N1) + 1)
    1010
     
    1212{
    1313    psStats *myStats    = NULL;
    14     psStats *myStats2   = NULL;
    1514    int testStatus      = true;
     15    int globalTestStatus = true;
    1616    int i               = 0;
    1717    psVector *myVector  = NULL;
    1818    psVector *maskVector= NULL;
    1919    float median        = 1e99;
    20     float realMedian1   = 1e99;
    21     float realMedian2   = 1e99;
     20    float realMedianWithMask = (float) (N-3)/4;
     21    float realMedianNoMask = (float) (N-1)/2;
     22    int currentId       = psMemGetId();
     23    int memLeaks        = 0;
    2224
    23     printPositiveTestHeader(stdout,
    24                             "psStats functions",
    25                             "PS_STAT_SAMPLE_MEDIAN");
    26 
     25    /*************************************************************************/
     26    /*  Allocate and initialize data structures                      */
     27    /*************************************************************************/
    2728    myStats = psStatsAlloc(PS_STAT_SAMPLE_MEDIAN);
    28     myVector = psVectorAlloc(PS_TYPE_FLOAT, N);
     29    myVector = psVectorAlloc(N, PS_TYPE_F32);
    2930    myVector->n = N;
    30     maskVector = psVectorAlloc(PS_TYPE_UINT8, N);
     31    maskVector = psVectorAlloc(N, PS_TYPE_U8);
    3132    maskVector->n = N;
    3233
     34    // Set the appropriate values for the vector data.
    3335    for (i=0;i<N;i++) {
    34         myVector->vec.f[i] = (float) i;
     36        myVector->data.F32[i] = (float) i;
     37    }
     38
     39    // Set the mask vector and calculate the expected median.
     40    for (i=0;i<N;i++) {
    3541        if (i < (N/2)) {
    36             maskVector->vec.ui8[i] = 0;
    37             if (myVector->vec.f[i] < realMedian2) {
    38                 realMedian2 = myVector->vec.f[i];
    39             }
     42            maskVector->data.U8[i] = 0;
    4043        } else {
    41             maskVector->vec.ui8[i] = 1;
    42             if (myVector->vec.f[i] < realMedian1) {
    43                 realMedian1 = myVector->vec.f[i];
    44             }
     44            maskVector->data.U8[i] = 1;
    4545        }
    4646    }
    4747
    48     myStats2 = psArrayStats(myVector, NULL, 0, myStats);
    49     median = myStats2->sampleMedian;
     48    /*************************************************************************/
     49    /*  Call psVectorStats() with no vector mask.                    */
     50    /*************************************************************************/
     51    printPositiveTestHeader(stdout,
     52                            "psStats functions",
     53                            "PS_STAT_SAMPLE_MEDIAN: no vector mask");
    5054
    51     printf("Called psArrayStats() on a vector with no elements masked.\n");
     55    myStats = psVectorStats(myStats, myVector, NULL, 0);
     56    median = myStats->sampleMedian;
     57
     58    printf("Called psVectorStats() on a vector with no elements masked.\n");
    5259    printf("The expected median was %f.  The calculated median was %f.\n",
    53            (float) (N-1)/2, median);
    54     if (median == (float) (N-1)/2) {
     60           realMedianNoMask, median);
     61    if (median == realMedianNoMask) {
    5562        testStatus = true;
    5663    } else {
    5764        testStatus = false;
     65        globalTestStatus = false;
    5866    }
    5967
    60     myStats2 = psArrayStats(myVector, maskVector, 1, myStats);
    61     median = myStats2->sampleMedian;
    62     printf("Called psArrayStats() on a vector with last N/2 elements masked.\n");
     68    printFooter(stdout,
     69                "psStats functions",
     70                "PS_STAT_SAMPLE_MEDIAN: no vector mask",
     71                testStatus);
     72
     73    /*************************************************************************/
     74    /*  Call psVectorStats() with vector mask.                       */
     75    /*************************************************************************/
     76    printPositiveTestHeader(stdout,
     77                            "psStats functions",
     78                            "PS_STAT_SAMPLE_MEDIAN: with vector mask");
     79
     80    myStats = psVectorStats(myStats, myVector, maskVector, 1);
     81    median = myStats->sampleMedian;
     82    printf("Called psVectorStats() on a vector with last N/2 elements masked.\n");
    6383    printf("The expected median was %f.  The calculated median was %f.\n",
    64            (float) (N-3)/4, median);
    65     if (median == (float) (N-3)/4) {
     84           realMedianWithMask, median);
     85    if (median == realMedianWithMask) {
    6686        testStatus = true;
    6787    } else {
    6888        testStatus = false;
     89        globalTestStatus = false;
    6990    }
    7091
    7192    printFooter(stdout,
    72                 "psHash functions",
    73                 "psHashAlloc()",
     93                "psStats functions",
     94                "PS_STAT_SAMPLE_MEDIAN: with vector mask",
    7495                testStatus);
    7596
    76     return (!testStatus);
     97    /*************************************************************************/
     98    /*  Deallocate data structures                                   */
     99    /*************************************************************************/
     100    printPositiveTestHeader(stdout,
     101                            "psStats functions",
     102                            "psStats(): deallocating memory");
     103
     104    psStatsFree(myStats);
     105    psVectorFree(myVector);
     106    psVectorFree(maskVector);
     107
     108    psMemCheckCorruption(1);
     109    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
     110    if (0 != memLeaks) {
     111        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
     112    }
     113
     114    printFooter(stdout,
     115                "psStats functions",
     116                "psStats(): deallocating memory",
     117                testStatus);
     118
     119    return (!globalTestStatus);
    77120}
  • trunk/psLib/test/dataManip/tst_psStats04.c

    r779 r887  
    11/*****************************************************************************
    22    This routine must ensure that PS_STAT_NVALUES is correctly computed
    3     by the procedure psArrayStats().
     3    by the procedure psVectorStats().
     4 
     5    Note: The NVALUES stat was removed from the IfA requirements spec.  So,
     6    this test is no longer in use.
    47 *****************************************************************************/
    58#include <stdio.h>
     
    1215{
    1316    psStats *myStats    = NULL;
    14     psStats *myStats2   = NULL;
    1517    int testStatus      = true;
    1618    int i               = 0;
     
    1820    psVector *maskVector= NULL;
    1921
     22    /*************************************************************************/
     23    /*  Allocate and initialize data structures                      */
     24    /*************************************************************************/
     25    myStats = psStatsAlloc(PS_STAT_NVALUES);
     26    myVector = psVectorAlloc(N, PS_TYPE_F32);
     27    myVector->n = N;
     28    maskVector = psVectorAlloc(N, PS_TYPE_U8);
     29    maskVector->n = N;
     30
     31    // Set the appropriate values for the vector data.
     32    for (i=0;i<N;i++) {
     33        myVector->data.F32[i] = (float) i;
     34    }
     35
     36    // Set the mask vector and calculate the expected maximum.
     37    for (i=0;i<N;i++) {
     38        if (i < (N/2)) {
     39            maskVector->data.U8[i] = 0;
     40        } else {
     41            maskVector->data.U8[i] = 1;
     42        }
     43    }
     44
     45    /*************************************************************************/
     46    /*  Call psVectorStats() with no vector mask.                    */
     47    /*************************************************************************/
    2048    printPositiveTestHeader(stdout,
    2149                            "psStats functions",
    2250                            "PS_STAT_NVALUES");
    2351
    24     myStats = psStatsAlloc(PS_STAT_NVALUES);
    25     myVector = psVectorAlloc(PS_TYPE_FLOAT, N);
    26     myVector->n = N;
    27     maskVector = psVectorAlloc(PS_TYPE_UINT8, N);
    28     maskVector->n = N;
     52    myStats = psVectorStats(myStats, myVector, NULL, 0);
    2953
    30     for (i=0;i<N;i++) {
    31         myVector->vec.f[i] = (float) i;
    32         if (i < (N/2)) {
    33             maskVector->vec.ui8[i] = 0;
    34         } else {
    35             maskVector->vec.ui8[i] = 1;
    36         }
    37     }
    38 
    39     myStats2 = psArrayStats(myVector, NULL, 0, myStats);
    40 
    41     printf("Called psArrayStats() on a vector with no elements masked.\n");
     54    printf("Called psVectorStats() on a vector with no elements masked.\n");
    4255    printf("The expected nvalues was %d.  The calculated nvalues was %d.\n",
    43            N, myStats2->nValues);
    44     if (myStats2->nValues == N) {
     56           N, myStats->nValues);
     57    if (myStats->nValues == N) {
    4558        testStatus = true;
    4659    } else {
     
    4861    }
    4962
    50     myStats2 = psArrayStats(myVector, maskVector, 1, myStats);
    51     printf("Called psArrayStats() on a vector with last N/2 elements masked.\n");
     63    /*************************************************************************/
     64    /*  Call psVectorStats() with vector mask.                       */
     65    /*************************************************************************/
     66    myStats = psVectorStats(myStats, myVector, maskVector, 1);
     67    printf("Called psVectorStats() on a vector with last N/2 elements masked.\n");
    5268    printf("The expected nvalues was %d.  The calculated nvalues was %d.\n",
    53            N/2, myStats2->nValues);
    54     if (myStats2->nValues == N/2) {
     69           N/2, myStats->nValues);
     70    if (myStats->nValues == N/2) {
    5571        testStatus = true;
    5672    } else {
Note: See TracChangeset for help on using the changeset viewer.