Changeset 6304 for trunk/psLib/test/math/tst_psStats09.c
- Timestamp:
- Feb 2, 2006, 11:06:10 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/math/tst_psStats09.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/math/tst_psStats09.c
r5117 r6304 18 18 #define MY_MEAN 30.0 19 19 #define MY_RANGE 2.0 20 #define VERBOSE 1 21 22 #define TST_IN_NULL 0x00000000 23 #define TST_IN_F32 0x00000000 24 #define TST_IN_F64 0x00000000 25 #define TST_IN_S8 0x00000000 26 #define TST_IN_U16 0x00000000 27 #define TST_IN_S32 0x00000000 28 #define TST_ERRORS_NULL 0x00000000 29 #define TST_ERRORS_F32 0x00000000 30 #define TST_ERRORS_F64 0x00000000 31 #define TST_ERRORS_S8 0x00000000 32 #define TST_ERRORS_U16 0x00000000 33 #define TST_ERRORS_S32 0x00000000 34 #define TST_MASK_NULL 0x00000000 35 #define TST_MASK_U8 0x00000000 36 #define TST_MASK_S32 0x00000000 37 38 psS32 genericClippedStatsTest( 39 unsigned int flags, 40 psS32 numData, 41 psU32 maskValue, 42 psBool expectedRC) 43 { 44 psS32 currentId = psMemGetId(); 45 psS32 testStatus = true; 46 psS32 memLeaks = 0; 47 psVector *in = NULL; 48 psVector *errors = NULL; 49 psVector *mask = NULL; 50 printPositiveTestHeader(stdout, "psMathUtils functions", "psVectorStats Clipped Stats Routine"); 51 52 if (expectedRC == false) { 53 printf("This test should generate an error message, and return NULL.\n"); 54 } 55 56 if (flags & TST_IN_NULL) { 57 printf(" using a NULL in vector\n"); 58 } 59 60 if (flags & TST_IN_F32) { 61 printf(" using a psF32 in vector\n"); 62 in = psVectorAlloc(numData, PS_TYPE_F32); 63 for (psS32 i=0;i<numData;i++) { 64 in->data.F32[i] = (psF32) i; 65 } 66 67 if (VERBOSE) { 68 for (psS32 i=0;i<numData;i++) { 69 printf("Original in data %d: (%.1f)\n", i, in->data.F32[i]); 70 } 71 } 72 } 73 74 if (flags & TST_IN_F64) { 75 printf(" using a psF64 in vector\n"); 76 in = psVectorAlloc(numData, PS_TYPE_F64); 77 for (psS32 i=0;i<numData;i++) { 78 in->data.F64[i] = (psF64) i; 79 } 80 81 if (VERBOSE) { 82 for (psS32 i=0;i<numData;i++) { 83 printf("Original in data %d: (%.1f)\n", i, in->data.F64[i]); 84 } 85 } 86 } 87 88 if (flags & TST_IN_S8) { 89 printf(" using a psS8 in vector\n"); 90 in = psVectorAlloc(numData, PS_TYPE_S8); 91 for (psS32 i=0;i<numData;i++) { 92 in->data.S8[i] = (psS8) i; 93 } 94 95 if (VERBOSE) { 96 for (psS32 i=0;i<numData;i++) { 97 printf("Original in data %d: (%d)\n", i, in->data.S8[i]); 98 } 99 } 100 } 101 102 if (flags & TST_IN_U16) { 103 printf(" using a psU16 in vector\n"); 104 in = psVectorAlloc(numData, PS_TYPE_U16); 105 for (psS32 i=0;i<numData;i++) { 106 in->data.U16[i] = (psU16) i; 107 } 108 109 if (VERBOSE) { 110 for (psS32 i=0;i<numData;i++) { 111 printf("Original in data %d: (%d)\n", i, in->data.U16[i]); 112 } 113 } 114 } 115 116 if (flags & TST_IN_S32) { 117 printf(" using a psS32 in vector\n"); 118 in = psVectorAlloc(numData, PS_TYPE_S32); 119 for (psS32 i=0;i<numData;i++) { 120 in->data.S32[i] = (psS32) i; 121 } 122 123 if (VERBOSE) { 124 for (psS32 i=0;i<numData;i++) { 125 printf("Original in data %d: (%d)\n", i, in->data.S32[i]); 126 } 127 } 128 } 129 130 131 if (flags & TST_ERRORS_NULL) { 132 printf(" using a NULL errors vector\n"); 133 } 134 135 if (flags & TST_ERRORS_F32) { 136 printf(" using a psF32 errors vector\n"); 137 errors = psVectorAlloc(numData, PS_TYPE_F32); 138 for (psS32 i=0;i<numData;i++) { 139 errors->data.F32[i] = (psF32) i; 140 } 141 142 if (VERBOSE) { 143 for (psS32 i=0;i<numData;i++) { 144 printf("Original errors data %d: (%.1f)\n", i, errors->data.F32[i]); 145 } 146 } 147 } 148 149 if (flags & TST_ERRORS_F64) { 150 printf(" using a psF64 errors vector\n"); 151 errors = psVectorAlloc(numData, PS_TYPE_F64); 152 for (psS32 i=0;i<numData;i++) { 153 errors->data.F64[i] = (psF64) i; 154 } 155 156 if (VERBOSE) { 157 for (psS32 i=0;i<numData;i++) { 158 printf("Original errors data %d: (%.1f)\n", i, errors->data.F64[i]); 159 } 160 } 161 } 162 163 if (flags & TST_ERRORS_S8) { 164 printf(" using a psS8 errors vector\n"); 165 errors = psVectorAlloc(numData, PS_TYPE_S8); 166 for (psS32 i=0;i<numData;i++) { 167 errors->data.S8[i] = (psS8) i; 168 } 169 170 if (VERBOSE) { 171 for (psS32 i=0;i<numData;i++) { 172 printf("Original errors data %d: (%d)\n", i, errors->data.S8[i]); 173 } 174 } 175 } 176 177 if (flags & TST_ERRORS_U16) { 178 printf(" using a psU16 errors vector\n"); 179 errors = psVectorAlloc(numData, PS_TYPE_U16); 180 for (psS32 i=0;i<numData;i++) { 181 errors->data.U16[i] = (psU16) i; 182 } 183 184 if (VERBOSE) { 185 for (psS32 i=0;i<numData;i++) { 186 printf("Original errors data %d: (%d)\n", i, errors->data.U16[i]); 187 } 188 } 189 } 190 191 if (flags & TST_ERRORS_S32) { 192 printf(" using a psS32 errors vector\n"); 193 errors = psVectorAlloc(numData, PS_TYPE_S32); 194 for (psS32 i=0;i<numData;i++) { 195 errors->data.S32[i] = (psS32) i; 196 } 197 198 if (VERBOSE) { 199 for (psS32 i=0;i<numData;i++) { 200 printf("Original errors data %d: (%d)\n", i, errors->data.S32[i]); 201 } 202 } 203 } 204 205 206 if (flags & TST_MASK_NULL) { 207 printf(" using a NULL mask vector\n"); 208 } 209 210 if (flags & TST_MASK_U8) { 211 printf(" using a psU8 mask vector\n"); 212 mask = psVectorAlloc(numData, PS_TYPE_U8); 213 for (psS32 i=0;i<numData;i++) { 214 mask->data.U8[i] = (psU8) i; 215 } 216 217 if (VERBOSE) { 218 for (psS32 i=0;i<numData;i++) { 219 printf("Original mask data %d: (%d)\n", i, mask->data.U8[i]); 220 } 221 } 222 } 223 224 if (flags & TST_MASK_S32) { 225 printf(" using a psS32 mask vector\n"); 226 mask = psVectorAlloc(numData, PS_TYPE_S32); 227 for (psS32 i=0;i<numData;i++) { 228 mask->data.S32[i] = (psS32) i; 229 } 230 231 if (VERBOSE) { 232 for (psS32 i=0;i<numData;i++) { 233 printf("Original mask data %d: (%d)\n", i, mask->data.S32[i]); 234 } 235 } 236 } 237 238 psStats *myStats = psStatsAlloc(PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV); 239 psStats *rc = psVectorStats(myStats, in, errors, mask, maskValue); 240 241 if (rc == NULL) { 242 if (expectedRC == true) { 243 printf("TEST ERROR: the psVectorStats() function returned NULL.\n"); 244 testStatus = false; 245 } 246 } else { 247 if (expectedRC == false) { 248 printf("TEST ERROR: the psVectorStats() function returned non-NULL.\n"); 249 testStatus = false; 250 } 251 252 } 253 254 psMemCheckCorruption(1); 255 memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false); 256 if (0 != memLeaks) { 257 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks); 258 } 259 260 return(testStatus); 261 } 262 263 264 20 265 21 266 psS32 main() … … 38 283 psTraceSetLevel("psVectorStats", 0); 39 284 40 psStats *myStats = NULL;41 psS32 testStatus = true;42 psS32 globalTestStatus = true;43 psS32 i = 0;44 psVector *maskVector= NULL;45 psVector *myGaussData = NULL;46 // NOTE: These values were calculated by running the function on the data.47 // A: They must be changed if we adjust the number of data points.48 // B: We don't really know that they are correct.49 // float realclippedMeanNoMask = 0.0;50 // float realclippedStdevNoMask = 0.0;51 // float realclippedMeanWithMask = 0.0;52 // float realclippedStdevWithMask = 0.0;53 psS32 count = 0;54 psS32 currentId = psMemGetId();55 psS32 memLeaks = 0;56 57 /*************************************************************************/58 /* Allocate and initialize data structures */59 /*************************************************************************/60 myStats = psStatsAlloc(PS_STAT_CLIPPED_MEAN |61 PS_STAT_CLIPPED_STDEV);62 63 myGaussData = psVectorAlloc(N, PS_TYPE_F32);64 myGaussData->n = myGaussData->nalloc;65 for (i=0;i<N;i++) {66 myGaussData->data.F32[i] = MY_MEAN - (MY_RANGE/1.9) +67 (MY_RANGE) * ((float) i) / ((float) N);68 }69 70 maskVector = psVectorAlloc(N, PS_TYPE_U8);71 maskVector->n = N;72 73 // Set the mask vector and calculate the expected maximum.74 for (i=0;i<N;i++) {75 if (i < (N/2)) {76 maskVector->data.U8[i] = 0;77 count++;78 } else {79 maskVector->data.U8[i] = 1;80 }81 }82 83 /*************************************************************************/84 /* Call psVectorStats() with no vector mask. */85 /*************************************************************************/86 printPositiveTestHeader(stdout,87 "psStats functions",88 "PS_STAT_CLIPPED_MEAN: no vector mask");89 90 myStats = psVectorStats(myStats, myGaussData, NULL, NULL, 0);91 92 printf("Called psVectorStats() on a vector with no elements masked.\n");93 printf("The calculated clippedMean was %.2f\n", myStats->clippedMean);94 95 printFooter(stdout,96 "psVector functions",97 "PS_STAT_CLIPPED_MEAN/STDEV: no vector mask",98 testStatus);99 100 101 102 printPositiveTestHeader(stdout,103 "psStats functions",104 "PS_STAT_CLIPPED_STDEV: no vector mask");105 106 printf("Called psVectorStats() on a vector with no elements masked.\n");107 printf("The calculated clippedStdev was %.2f\n", myStats->clippedStdev);108 109 printFooter(stdout,110 "psVector functions",111 "PS_STAT_CLIPPED_MEAN/STDEV: no vector mask",112 testStatus);113 114 /*************************************************************************/115 /* Call psVectorStats() with vector mask. */116 /*************************************************************************/117 printPositiveTestHeader(stdout,118 "psStats functions",119 "PS_STAT_CLIPPED_MEAN: vector mask");120 121 myStats = psVectorStats(myStats, myGaussData, NULL, maskVector, 1);122 123 printf("Called psVectorStats() on a vector with elements masked.\n");124 printf("The calculated clippedMean was %.2f\n", myStats->clippedMean);125 printFooter(stdout,126 "psVector functions",127 "PS_STAT_CLIPPED_MEAN/STDEV: vector mask",128 testStatus);129 130 131 132 printPositiveTestHeader(stdout,133 "psStats functions",134 "PS_STAT_CLIPPED_STDEV: vector mask");135 136 printf("Called psVectorStats() on a vector with elements masked.\n");137 printf("The calculated clippedStdev was %.2f\n", myStats->clippedStdev);138 printFooter(stdout,139 "psVector functions",140 "PS_STAT_CLIPPED_MEAN/STDEV: vector mask",141 testStatus);142 143 /*************************************************************************/144 /* Deallocate data structures */145 /*************************************************************************/146 printPositiveTestHeader(stdout,147 "psStats functions",148 "psStats(): deallocating memory");149 150 psFree(myStats);151 psFree(myGaussData);152 psFree(maskVector);153 154 psMemCheckCorruption(1);155 memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);156 if (0 != memLeaks) {157 psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);158 }159 160 printFooter(stdout,161 "psVector functions",162 "psStats(): deallocating memory",163 testStatus);164 165 return (!globalTestStatus);166 285 }
Note:
See TracChangeset
for help on using the changeset viewer.
