IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 12, 2004, 9:42:51 PM (22 years ago)
Author:
gusciora
Message:

Added some tests and fixed some bugs in psArrayStats().

File:
1 edited

Legend:

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

    r659 r660  
    11/*****************************************************************************
    2     This code tests whether a hash table be allocated successfully.
     2    This routine must ensure that PS_STAT_SAMPLE_MEAN is correctly computed
     3    by the procedure psArrayStats().
    34 *****************************************************************************/
    45#include <stdio.h>
     
    1415    int i               = 0;
    1516    psType dummyFloatType;
     17    psType dummyIntType;
    1618    psVector *myVector  = NULL;
     19    psVector *maskVector= NULL;
    1720    float mean          = 0.0;
    18     float realMean      = 0.0;
     21    float realMean1     = 0.0;
     22    float realMean2     = 0.0;
     23    int count           = 0;
    1924
    2025    printPositiveTestHeader(stdout,
     
    2530    dummyFloatType.type = PS_TYPE_FLOAT;
    2631    dummyFloatType.dimen = PS_DIMEN_VECTOR;
     32    dummyIntType.type = PS_TYPE_INT;
     33    dummyIntType.dimen = PS_DIMEN_VECTOR;
    2734    myVector = psVectorAlloc(dummyFloatType, N);
    2835    myVector->n = N;
     36    maskVector = psVectorAlloc(dummyIntType, N);
     37    maskVector->n = N;
    2938
    3039    mean = 0.0;
    31     realMean = 0.0;
     40    realMean2 = 0.0;
    3241    for (i=0;i<N;i++) {
    3342        myVector->vec.f[i] = (float) i;
    34         realMean+= myVector->vec.f[i];
     43        if (i < (N/2)) {
     44            maskVector->vec.i[i] = 0;
     45            realMean2+= myVector->vec.f[i];
     46            count++;
     47        } else {
     48            printf("Masking element %d\n", i);
     49            maskVector->vec.i[i] = 1;
     50        }
     51        realMean1+= myVector->vec.f[i];
    3552    }
    36     realMean /= (float) N;
     53    realMean1 /= (float) N;
     54    realMean2 /= (float) count;
    3755
    3856    myStats2 = psArrayStats(myVector, NULL, 0, myStats);
    3957    mean = myStats2->sampleMean;
    4058
    41     if (mean == realMean) {
     59    printf("Called psArrayStats() on a vector with no elements masked.\n");
     60    printf("The expected mean was %f; the calculated mean was %f\n", realMean1, mean);
     61    if (mean == realMean1) {
    4262        testStatus = true;
    4363    } else {
    4464        testStatus = false;
    4565    }
     66
     67    myStats2 = psArrayStats(myVector, maskVector, 1, myStats);
     68    mean = myStats2->sampleMean;
     69    printf("Called psArrayStats() on a vector with last N/2 elements masked.\n");
     70    printf("The expected mean was %f; the calculated mean was %f\n", realMean2, mean);
    4671
    4772    printFooter(stdout,
Note: See TracChangeset for help on using the changeset viewer.