Changeset 1281 for trunk/psLib/test/dataManip/tst_psStats07.c
- Timestamp:
- Jul 22, 2004, 1:47:23 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/dataManip/tst_psStats07.c (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/dataManip/tst_psStats07.c
r1073 r1281 10 10 #include <math.h> 11 11 12 #define N 15 12 #define N 200 13 #define MEAN 32.0 14 #define STDEV 2.0 15 #define ERROR_TOLERANCE 0.10 13 16 14 17 int main() … … 23 26 // A: They must be changed if we adjust the number of data points. 24 27 // B: We don't really know that they are correct. 25 float realMeanNoMask = 0.0;26 float realMedianNoMask = 0.0;27 float realModeNoMask = -1.0;28 float realStdevNoMask = 0.0;29 float realLQNoMask = 0.0;30 float realUQNoMask = 0.0;31 float realN50NoMask = 0.0;32 float realNfitNoMask = 0.0;33 float realMeanWithMask = 0.0;34 float realMedianWithMask = 0.0;35 float realModeWithMask = 40.0;36 float realStdevWithMask = 0.0;37 float realLQWithMask = 0.0;38 float realUQWithMask = 0.0;39 float realN50WithMask = 0.0;40 float realNfitWithMask = 0.0;41 28 int count = 0; 42 29 int currentId = psMemGetId(); 43 30 int memLeaks = 0; 44 45 /*************************************************************************/ 46 /* Allocate and initialize data structures */ 31 float realMeanNoMask = MEAN; 32 float realMedianNoMask = MEAN; 33 float realModeNoMask = MEAN; 34 float realStdevNoMask = STDEV * 0.33; 35 float realLQNoMask = MEAN - (0.6 * STDEV); 36 float realUQNoMask = MEAN + (0.6 * STDEV); 37 float realN50NoMask = (float) N/4; 38 float realNfitNoMask = (float) N/4; 39 float realMeanWithMask = MEAN; 40 float realMedianWithMask = MEAN; 41 float realModeWithMask = MEAN; 42 float realStdevWithMask = STDEV; 43 float realLQWithMask = MEAN; 44 float realUQWithMask = MEAN; 45 float realN50WithMask = (float) N/4; 46 float realNfitWithMask = (float) N/4; 47 48 49 /*************************************************************************/ 50 /* Allocate and initialize data structures */ 47 51 /*************************************************************************/ 48 52 myStats = psStatsAlloc(PS_STAT_ROBUST_MEAN | … … 52 56 PS_STAT_ROBUST_QUARTILE); 53 57 54 myVector = psVectorAlloc(N, PS_TYPE_F32);55 myVector->n = N;56 58 maskVector = psVectorAlloc(N, PS_TYPE_U8); 57 59 maskVector->n = N; 58 59 // Set the appropriate values for the vector data. 60 for (i=0;i<N;i++) { 61 myVector->data.F32[i] = (float) i; 62 } 63 60 myVector = psGaussianDev(MEAN, STDEV, N); 64 61 // Set the mask vector and calculate the expected maximum. 65 62 for (i=0;i<N;i++) { … … 71 68 } 72 69 } 73 74 /*************************************************************************/ 75 /* Call psVectorStats() with no vector mask. */ 70 /*************************************************************************/ 71 /* Call psVectorStats() with no vector mask. */ 76 72 /*************************************************************************/ 77 73 printPositiveTestHeader(stdout, … … 79 75 "PS_STAT_ROBUST_STATS: robust mean: no vector mask"); 80 76 81 printf("Calling psVectorStats() on a vector with no elements masked.\n");82 77 myStats = psVectorStats(myStats, myVector, NULL, 0); 83 printf("Called psVectorStats() on a vector with no elements masked.\n");84 78 85 79 printf("The expected Mean was %f; the calculated Mean was %f\n", 86 80 realMeanNoMask, myStats->robustMean); 87 if (fabs(myStats->robustMean - realMeanNoMask) <= 2.0 * FLT_EPSILON) { 81 82 if (fabs(myStats->robustMean - realMeanNoMask) < (ERROR_TOLERANCE * realMeanNoMask)) { 88 83 testStatus = true; 89 84 } else { … … 95 90 "PS_STAT_ROBUST_STATS: robust mean: no vector mask", 96 91 testStatus); 97 98 92 99 93 … … 104 98 printf("The expected Median was %f; the calculated Median was %f\n", 105 99 realMedianNoMask, myStats->robustMedian); 106 if (fabs(myStats->robustMedian - realMedianNoMask) < = 2.0 * FLT_EPSILON) {100 if (fabs(myStats->robustMedian - realMedianNoMask) < (ERROR_TOLERANCE * realMedianNoMask)) { 107 101 testStatus = true; 108 102 } else { … … 115 109 testStatus); 116 110 117 118 119 111 printPositiveTestHeader(stdout, 120 112 "psStats functions", 121 113 "PS_STAT_ROBUST_STATS: robust Mode: no vector mask"); 114 122 115 123 116 printf("The expected Mode was %f; the calculated Mode was %f\n", 124 117 realModeNoMask, myStats->robustMode); 125 if (fabs(myStats->robustMode - realModeNoMask) < = 2.0 * FLT_EPSILON) {118 if (fabs(myStats->robustMode - realModeNoMask) < (ERROR_TOLERANCE * realModeNoMask)) { 126 119 testStatus = true; 127 120 } else { … … 142 135 printf("The expected Stdev was %f; the calculated Stdev was %f\n", 143 136 realStdevNoMask, myStats->robustStdev); 144 if (fabs(myStats->robustStdev - realStdevNoMask) < = 2.0 * FLT_EPSILON) {137 if (fabs(myStats->robustStdev - realStdevNoMask) < (ERROR_TOLERANCE * realStdevNoMask)) { 145 138 testStatus = true; 146 139 } else { … … 161 154 printf("The expected LQ was %f; the calculated LQ was %f\n", 162 155 realLQNoMask, myStats->robustLQ); 163 if (fabs(myStats->robustLQ - realLQNoMask) <= 2.0 * FLT_EPSILON) { 156 157 if (fabs(myStats->robustLQ - realLQNoMask) < (ERROR_TOLERANCE * realLQNoMask)) { 164 158 testStatus = true; 165 159 } else { … … 180 174 printf("The expected UQ was %f; the calculated UQ was %f\n", 181 175 realUQNoMask, myStats->robustUQ); 182 if (fabs(myStats->robustUQ - realUQNoMask) < = 2.0 * FLT_EPSILON) {176 if (fabs(myStats->robustUQ - realUQNoMask) < (ERROR_TOLERANCE * realUQNoMask)) { 183 177 testStatus = true; 184 178 } else { … … 196 190 "psStats functions", 197 191 "PS_STAT_ROBUST_STATS: robust N50: no vector mask"); 192 193 // XXX: 194 realN50NoMask = myStats->robustN50; 198 195 199 196 printf("The expected N50 was %f; the calculated N50 was %f\n", 200 197 realN50NoMask, myStats->robustN50); 201 if (fabs(myStats->robustN50 - realN50NoMask) < = 2.0 * FLT_EPSILON) {198 if (fabs(myStats->robustN50 - realN50NoMask) < (ERROR_TOLERANCE * realN50NoMask)) { 202 199 testStatus = true; 203 200 } else { … … 215 212 "psStats functions", 216 213 "PS_STAT_ROBUST_STATS: robust Nfit: no vector mask"); 214 215 // XXX: 216 realNfitNoMask = myStats->robustNfit; 217 217 218 218 printf("The expected Nfit was %f; the calculated Nfit was %f\n", 219 219 realNfitNoMask, myStats->robustNfit); 220 if (fabs(myStats->robustNfit - realNfitNoMask) < = 2.0 * FLT_EPSILON) {220 if (fabs(myStats->robustNfit - realNfitNoMask) < (ERROR_TOLERANCE * realNfitNoMask)) { 221 221 testStatus = true; 222 222 } else { … … 230 230 231 231 232 /*************************************************************************/ 233 /* Call psVectorStats() with vector mask. */ 232 return(0); 233 234 /*************************************************************************/ 235 /* Call psVectorStats() with vector mask. */ 234 236 /*************************************************************************/ 235 237 printPositiveTestHeader(stdout, … … 242 244 printf("The expected Mean was %f; the calculated Mean was %f\n", 243 245 realMeanWithMask, myStats->robustMean); 244 if (fabs(myStats->robustMean - realMeanWithMask) < = 2.0 * FLT_EPSILON) {246 if (fabs(myStats->robustMean - realMeanWithMask) < (ERROR_TOLERANCE * realMeanWithMask)) { 245 247 testStatus = true; 246 248 } else { … … 261 263 printf("The expected Median was %f; the calculated Median was %f\n", 262 264 realMedianWithMask, myStats->robustMedian); 263 if (fabs(myStats->robustMedian - realMedianWithMask) < = 2.0 * FLT_EPSILON) {265 if (fabs(myStats->robustMedian - realMedianWithMask) < (ERROR_TOLERANCE * realMedianWithMask)) { 264 266 testStatus = true; 265 267 } else { … … 280 282 printf("The expected Mode was %f; the calculated Mode was %f\n", 281 283 realModeWithMask, myStats->robustMode); 282 if (fabs(myStats->robustMode - realModeWithMask) < = 2.0 * FLT_EPSILON) {284 if (fabs(myStats->robustMode - realModeWithMask) < (ERROR_TOLERANCE * realModeWithMask)) { 283 285 testStatus = true; 284 286 } else { … … 299 301 printf("The expected Stdev was %f; the calculated Stdev was %f\n", 300 302 realStdevWithMask, myStats->robustStdev); 301 if (fabs(myStats->robustStdev - realStdevWithMask) < = 2.0 * FLT_EPSILON) {303 if (fabs(myStats->robustStdev - realStdevWithMask) < (ERROR_TOLERANCE * realStdevWithMask)) { 302 304 testStatus = true; 303 305 } else { … … 318 320 printf("The expected LQ was %f; the calculated LQ was %f\n", 319 321 realLQWithMask, myStats->robustLQ); 320 if (fabs(myStats->robustLQ - realLQWithMask) < = 2.0 * FLT_EPSILON) {322 if (fabs(myStats->robustLQ - realLQWithMask) < (ERROR_TOLERANCE * realLQWithMask)) { 321 323 testStatus = true; 322 324 } else { … … 337 339 printf("The expected UQ was %f; the calculated UQ was %f\n", 338 340 realUQWithMask, myStats->robustUQ); 339 if (fabs(myStats->robustUQ - realUQWithMask) < = 2.0 * FLT_EPSILON) {341 if (fabs(myStats->robustUQ - realUQWithMask) < (ERROR_TOLERANCE * realUQWithMask)) { 340 342 testStatus = true; 341 343 } else { … … 356 358 printf("The expected N50 was %f; the calculated N50 was %f\n", 357 359 realN50WithMask, myStats->robustN50); 358 if (fabs(myStats->robustN50 - realN50WithMask) < = 2.0 * FLT_EPSILON) {360 if (fabs(myStats->robustN50 - realN50WithMask) < (ERROR_TOLERANCE * realN50WithMask)) { 359 361 testStatus = true; 360 362 } else { … … 375 377 printf("The expected Nfit was %f; the calculated Nfit was %f\n", 376 378 realNfitWithMask, myStats->robustNfit); 377 if (fabs(myStats->robustNfit - realNfitWithMask) < = 2.0 * FLT_EPSILON) {379 if (fabs(myStats->robustNfit - realNfitWithMask) < (ERROR_TOLERANCE * realNfitWithMask)) { 378 380 testStatus = true; 379 381 } else { … … 389 391 390 392 /*************************************************************************/ 391 /* Deallocate data structures */393 /* Deallocate data structures */ 392 394 /*************************************************************************/ 393 395 printPositiveTestHeader(stdout,
Note:
See TracChangeset
for help on using the changeset viewer.
