Changeset 660 for trunk/psLib/test/dataManip/tst_psStats00.c
- Timestamp:
- May 12, 2004, 9:42:51 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/dataManip/tst_psStats00.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/dataManip/tst_psStats00.c
r659 r660 1 1 /***************************************************************************** 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(). 3 4 *****************************************************************************/ 4 5 #include <stdio.h> … … 14 15 int i = 0; 15 16 psType dummyFloatType; 17 psType dummyIntType; 16 18 psVector *myVector = NULL; 19 psVector *maskVector= NULL; 17 20 float mean = 0.0; 18 float realMean = 0.0; 21 float realMean1 = 0.0; 22 float realMean2 = 0.0; 23 int count = 0; 19 24 20 25 printPositiveTestHeader(stdout, … … 25 30 dummyFloatType.type = PS_TYPE_FLOAT; 26 31 dummyFloatType.dimen = PS_DIMEN_VECTOR; 32 dummyIntType.type = PS_TYPE_INT; 33 dummyIntType.dimen = PS_DIMEN_VECTOR; 27 34 myVector = psVectorAlloc(dummyFloatType, N); 28 35 myVector->n = N; 36 maskVector = psVectorAlloc(dummyIntType, N); 37 maskVector->n = N; 29 38 30 39 mean = 0.0; 31 realMean = 0.0;40 realMean2 = 0.0; 32 41 for (i=0;i<N;i++) { 33 42 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]; 35 52 } 36 realMean /= (float) N; 53 realMean1 /= (float) N; 54 realMean2 /= (float) count; 37 55 38 56 myStats2 = psArrayStats(myVector, NULL, 0, myStats); 39 57 mean = myStats2->sampleMean; 40 58 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) { 42 62 testStatus = true; 43 63 } else { 44 64 testStatus = false; 45 65 } 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); 46 71 47 72 printFooter(stdout,
Note:
See TracChangeset
for help on using the changeset viewer.
