Changeset 6307
- Timestamp:
- Feb 2, 2006, 12:15:21 PM (20 years ago)
- Location:
- trunk/psLib/test/math
- Files:
-
- 2 edited
-
tst_psStats09.c (modified) (13 diffs)
-
verified/tst_psStats09.stdout (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/math/tst_psStats09.c
r6304 r6307 4 4 psVectorStats(). 5 5 6 XXX: Must add tests for various data types, other than psF32. Copy code7 from tst_psStats00.c-tst_psStats02.c.6 XXX: The capability is here to test a wide variety of input parameters. 7 We must do this, later. 8 8 *****************************************************************************/ 9 9 #include <stdio.h> 10 10 #include "pslib_strict.h" 11 11 #include "psTest.h" 12 #include "psTest.h"13 #include "psImageStats.h"14 12 #include "float.h" 15 13 #include <math.h> 16 14 17 #define N 500 18 #define MY_MEAN 30.0 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( 15 #define NUM_DATA 1000 16 #define VERBOSE 0 17 #define PERCENT_OUTLIERS 2 18 #define ERROR_TOLERANCE .10 19 #define ERRORS 1000.0 20 #define SEED 1995 21 22 #define TST_IN_NULL 0x00000001 23 #define TST_IN_F32 0x00000002 24 #define TST_IN_F64 0x00000004 25 #define TST_IN_S8 0x00000008 26 #define TST_IN_U16 0x00000010 27 #define TST_IN_S32 0x00000020 28 #define TST_ERRORS_NULL 0x00000040 29 #define TST_ERRORS_F32 0x00000080 30 #define TST_ERRORS_F64 0x00000100 31 #define TST_ERRORS_S8 0x00000200 32 #define TST_ERRORS_U16 0x00000400 33 #define TST_ERRORS_S32 0x00000800 34 #define TST_MASK_NULL 0x00001000 35 #define TST_MASK_U8 0x00002000 36 #define TST_MASK_S32 0x00004000 37 38 39 psBool genericClippedStatsTest( 39 40 unsigned int flags, 40 41 psS32 numData, … … 43 44 { 44 45 psS32 currentId = psMemGetId(); 45 ps S32testStatus = true;46 psBool testStatus = true; 46 47 psS32 memLeaks = 0; 47 48 psVector *in = NULL; 48 49 psVector *errors = NULL; 49 50 psVector *mask = NULL; 51 srand(SEED); 50 52 printPositiveTestHeader(stdout, "psMathUtils functions", "psVectorStats Clipped Stats Routine"); 51 53 54 if (expectedRC == true) { 55 printf("This test should not generate any errors.\n"); 56 } 52 57 if (expectedRC == false) { 53 58 printf("This test should generate an error message, and return NULL.\n"); … … 128 133 } 129 134 130 131 135 if (flags & TST_ERRORS_NULL) { 132 136 printf(" using a NULL errors vector\n"); … … 137 141 errors = psVectorAlloc(numData, PS_TYPE_F32); 138 142 for (psS32 i=0;i<numData;i++) { 139 errors->data.F32[i] = (psF32) i;143 errors->data.F32[i] = ERRORS; 140 144 } 141 145 … … 151 155 errors = psVectorAlloc(numData, PS_TYPE_F64); 152 156 for (psS32 i=0;i<numData;i++) { 153 errors->data.F64[i] = (psF64) i;157 errors->data.F64[i] = ERRORS; 154 158 } 155 159 … … 165 169 errors = psVectorAlloc(numData, PS_TYPE_S8); 166 170 for (psS32 i=0;i<numData;i++) { 167 errors->data.S8[i] = (psS8) i;171 errors->data.S8[i] = (psS8) ERRORS; 168 172 } 169 173 … … 179 183 errors = psVectorAlloc(numData, PS_TYPE_U16); 180 184 for (psS32 i=0;i<numData;i++) { 181 errors->data.U16[i] = (psU16) i;185 errors->data.U16[i] = (psU16) ERRORS; 182 186 } 183 187 … … 193 197 errors = psVectorAlloc(numData, PS_TYPE_S32); 194 198 for (psS32 i=0;i<numData;i++) { 195 errors->data.S32[i] = (psS32) i;199 errors->data.S32[i] = (psS32) ERRORS; 196 200 } 197 201 … … 212 216 mask = psVectorAlloc(numData, PS_TYPE_U8); 213 217 for (psS32 i=0;i<numData;i++) { 214 mask->data.U8[i] = (psU8) i;218 mask->data.U8[i] = (psU8) 0; 215 219 } 216 220 … … 226 230 mask = psVectorAlloc(numData, PS_TYPE_S32); 227 231 for (psS32 i=0;i<numData;i++) { 228 mask->data.S32[i] = (psS32) i;232 mask->data.S32[i] = (psS32) 0; 229 233 } 230 234 … … 236 240 } 237 241 242 243 // 244 // We calculate the sample mean and stdev without and outliers in the data. 245 // We will use this later in determining if the clipped stats are correct. 246 // 247 psF32 sampleMean; 248 psF32 sampleStdev; 249 if (expectedRC == true) { 250 psStats *myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV); 251 psStats *rc = psVectorStats(myStats, in, NULL, NULL, maskValue); 252 if (rc == NULL) { 253 printf("TEST ERROR: the psVectorStats() function returned NULL.\n"); 254 testStatus = false; 255 } else { 256 sampleMean = myStats->sampleMean; 257 sampleStdev = myStats->sampleStdev; 258 } 259 psFree(myStats); 260 } 261 262 // 263 // We add a few outliers to the input data. 264 // 265 if (flags & TST_IN_F32) { 266 for (psS32 i=0;i<numData;i++) { 267 if (PERCENT_OUTLIERS > (random() % 100)) { 268 in->data.F32[i] = (psF32) (10 * numData); 269 } 270 } 271 272 if (VERBOSE) { 273 for (psS32 i=0;i<numData;i++) { 274 printf("Original in data %d: (%.1f)\n", i, in->data.F32[i]); 275 } 276 } 277 } 278 if (flags & TST_IN_F64) { 279 for (psS32 i=0;i<numData;i++) { 280 if (PERCENT_OUTLIERS > (random() % 100)) { 281 in->data.F64[i] = (psF64) (10 * numData); 282 } 283 } 284 285 if (VERBOSE) { 286 for (psS32 i=0;i<numData;i++) { 287 printf("Original in data %d: (%.1f)\n", i, in->data.F64[i]); 288 } 289 } 290 } 291 if (flags & TST_IN_S8) { 292 for (psS32 i=0;i<numData;i++) { 293 if (PERCENT_OUTLIERS > (random() % 100)) { 294 in->data.S8[i] = (psS8) (10 * numData); 295 } 296 } 297 298 if (VERBOSE) { 299 for (psS32 i=0;i<numData;i++) { 300 printf("Original in data %d: (%d)\n", i, in->data.S8[i]); 301 } 302 } 303 } 304 if (flags & TST_IN_U16) { 305 for (psS32 i=0;i<numData;i++) { 306 if (PERCENT_OUTLIERS > (random() % 100)) { 307 in->data.U16[i] = (psU16) (10 * numData); 308 } 309 } 310 311 if (VERBOSE) { 312 for (psS32 i=0;i<numData;i++) { 313 printf("Original in data %d: (%d)\n", i, in->data.U16[i]); 314 } 315 } 316 } 317 if (flags & TST_IN_S32) { 318 for (psS32 i=0;i<numData;i++) { 319 if (PERCENT_OUTLIERS > (random() % 100)) { 320 in->data.S32[i] = (psS32) (10 * numData); 321 } 322 } 323 324 if (VERBOSE) { 325 for (psS32 i=0;i<numData;i++) { 326 printf("Original in data %d: (%d)\n", i, in->data.S32[i]); 327 } 328 } 329 } 330 331 // 332 // We call psVectorStats() and calculate the clipped stats. 333 // 238 334 psStats *myStats = psStatsAlloc(PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV); 239 335 psStats *rc = psVectorStats(myStats, in, errors, mask, maskValue); 240 241 336 if (rc == NULL) { 242 337 if (expectedRC == true) { … … 250 345 } 251 346 252 } 253 347 if (fabs(myStats->clippedMean - sampleMean) > (ERROR_TOLERANCE * sampleMean)) { 348 printf("TEST ERROR: the clipped mean was %.2f, should have been %.2f\n", myStats->clippedMean, sampleMean); 349 testStatus = false; 350 } else if (VERBOSE) { 351 printf("GOOD: the clipped mean was %.2f, should have been %.2f\n", myStats->clippedMean, sampleMean); 352 } 353 354 if (fabs(myStats->clippedStdev - sampleStdev) > (ERROR_TOLERANCE * sampleStdev)) { 355 printf("TEST ERROR: the clipped stdev was %.2f, should have been %.2f\n", myStats->clippedStdev, sampleStdev); 356 testStatus = false; 357 } else if (VERBOSE) { 358 printf("GOOD: the clipped stdev was %.2f, should have been %.2f\n", myStats->clippedStdev, sampleStdev); 359 } 360 361 } 362 363 psFree(myStats); 364 psFree(in); 365 psFree(errors); 366 psFree(mask); 254 367 psMemCheckCorruption(1); 255 368 memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false); … … 261 374 } 262 375 263 264 265 376 #define TRACE_LEVEL 0 266 377 psS32 main() 267 378 { 268 379 psLogSetFormat("HLNM"); 380 psBool testStatus = true; 381 269 382 // 270 383 // We list pertinent psStats.c functions here for debugging ease. 271 384 // 272 psTraceSetLevel(".", 0); 273 psTraceSetLevel("p_psGetStatValue", 0); 274 psTraceSetLevel("p_psVectorSampleMean", 0); 275 psTraceSetLevel("p_psVectorMax", 0); 276 psTraceSetLevel("p_psVectorMin", 0); 277 psTraceSetLevel("p_psVectorCheckNonEmpty", 0); 278 psTraceSetLevel("p_psVectorNValues", 0); 279 psTraceSetLevel("p_psVectorClippedStats", 0); 280 psTraceSetLevel("p_psNormalizeVectorRange", 0); 281 psTraceSetLevel("psStatsAlloc", 0); 282 psTraceSetLevel("p_psConvertToF32", 0); 283 psTraceSetLevel("psVectorStats", 0); 284 385 psTraceSetLevel(".", TRACE_LEVEL); 386 psTraceSetLevel("p_psGetStatValue", TRACE_LEVEL); 387 psTraceSetLevel("p_psVectorSampleMean", TRACE_LEVEL); 388 psTraceSetLevel("p_psVectorMax", TRACE_LEVEL); 389 psTraceSetLevel("p_psVectorMin", TRACE_LEVEL); 390 psTraceSetLevel("p_psVectorCheckNonEmpty", TRACE_LEVEL); 391 psTraceSetLevel("p_psVectorNValues", TRACE_LEVEL); 392 psTraceSetLevel("p_psVectorClippedStats", TRACE_LEVEL); 393 psTraceSetLevel("p_psNormalizeVectorRange", TRACE_LEVEL); 394 psTraceSetLevel("psStatsAlloc", TRACE_LEVEL); 395 psTraceSetLevel("p_psConvertToF32", TRACE_LEVEL); 396 psTraceSetLevel("psVectorStats", TRACE_LEVEL); 397 398 testStatus &= genericClippedStatsTest(TST_IN_NULL | TST_ERRORS_NULL | TST_MASK_NULL, NUM_DATA, 1, false); 399 testStatus &= genericClippedStatsTest(TST_IN_F32 | TST_ERRORS_NULL | TST_MASK_NULL, NUM_DATA, 1, true); 400 testStatus &= genericClippedStatsTest(TST_IN_F64 | TST_ERRORS_NULL | TST_MASK_NULL, NUM_DATA, 1, true); 401 testStatus &= genericClippedStatsTest(TST_IN_F32 | TST_ERRORS_F32 | TST_MASK_NULL, NUM_DATA, 1, true); 402 testStatus &= genericClippedStatsTest(TST_IN_F32 | TST_ERRORS_NULL | TST_MASK_U8, NUM_DATA, 1, true); 403 404 if (testStatus) { 405 printf("TEST PASSED\n"); 406 } else { 407 printf("TEST FAILED\n"); 408 } 285 409 } -
trunk/psLib/test/math/verified/tst_psStats09.stdout
r4547 r6307 1 1 /***************************** TESTPOINT ******************************************\ 2 2 * TestFile: tst_psStats09.c * 3 * TestPoint: ps Stats functions{PS_STAT_CLIPPED_MEAN: no vector mask}*3 * TestPoint: psMathUtils functions{psVectorStats Clipped Stats Routine} * 4 4 * TestType: Positive * 5 5 \**********************************************************************************/ 6 6 7 Called psVectorStats() on a vector with no elements masked. 8 The calculated clippedMean was 29.95 9 10 ---> TESTPOINT PASSED (psVector functions{PS_STAT_CLIPPED_MEAN/STDEV: no vector mask} | tst_psStats09.c) 11 7 This test should generate an error message, and return NULL. 8 using a NULL in vector 9 using a NULL errors vector 10 using a NULL mask vector 12 11 /***************************** TESTPOINT ******************************************\ 13 12 * TestFile: tst_psStats09.c * 14 * TestPoint: ps Stats functions{PS_STAT_CLIPPED_STDEV: no vector mask}*13 * TestPoint: psMathUtils functions{psVectorStats Clipped Stats Routine} * 15 14 * TestType: Positive * 16 15 \**********************************************************************************/ 17 16 18 Called psVectorStats() on a vector with no elements masked. 19 The calculated clippedStdev was 0.58 20 21 ---> TESTPOINT PASSED (psVector functions{PS_STAT_CLIPPED_MEAN/STDEV: no vector mask} | tst_psStats09.c) 22 17 This test should not generate any errors. 18 using a psF32 in vector 19 using a NULL errors vector 20 using a NULL mask vector 23 21 /***************************** TESTPOINT ******************************************\ 24 22 * TestFile: tst_psStats09.c * 25 * TestPoint: ps Stats functions{PS_STAT_CLIPPED_MEAN: vector mask}*23 * TestPoint: psMathUtils functions{psVectorStats Clipped Stats Routine} * 26 24 * TestType: Positive * 27 25 \**********************************************************************************/ 28 26 29 Called psVectorStats() on a vector with elements masked. 30 The calculated clippedMean was 29.45 31 32 ---> TESTPOINT PASSED (psVector functions{PS_STAT_CLIPPED_MEAN/STDEV: vector mask} | tst_psStats09.c) 33 27 This test should not generate any errors. 28 using a psF64 in vector 29 using a NULL errors vector 30 using a NULL mask vector 34 31 /***************************** TESTPOINT ******************************************\ 35 32 * TestFile: tst_psStats09.c * 36 * TestPoint: ps Stats functions{PS_STAT_CLIPPED_STDEV: vector mask}*33 * TestPoint: psMathUtils functions{psVectorStats Clipped Stats Routine} * 37 34 * TestType: Positive * 38 35 \**********************************************************************************/ 39 36 40 Called psVectorStats() on a vector with elements masked. 41 The calculated clippedStdev was 0.29 42 43 ---> TESTPOINT PASSED (psVector functions{PS_STAT_CLIPPED_MEAN/STDEV: vector mask} | tst_psStats09.c) 44 37 This test should not generate any errors. 38 using a psF32 in vector 39 using a psF32 errors vector 40 using a NULL mask vector 45 41 /***************************** TESTPOINT ******************************************\ 46 42 * TestFile: tst_psStats09.c * 47 * TestPoint: ps Stats functions{psStats(): deallocating memory}*43 * TestPoint: psMathUtils functions{psVectorStats Clipped Stats Routine} * 48 44 * TestType: Positive * 49 45 \**********************************************************************************/ 50 46 51 52 ---> TESTPOINT PASSED (psVector functions{psStats(): deallocating memory} | tst_psStats09.c) 53 47 This test should not generate any errors. 48 using a psF32 in vector 49 using a NULL errors vector 50 using a psU8 mask vector 51 TEST PASSED
Note:
See TracChangeset
for help on using the changeset viewer.
