Changeset 5435 for trunk/psModules/test/detrend/tst_pmNonLinear.c
- Timestamp:
- Oct 20, 2005, 1:06:24 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psModules/test/detrend/tst_pmNonLinear.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/test/detrend/tst_pmNonLinear.c
r5169 r5435 1 /* *@file tst_pmNonLinear.c1 /* @file tst_pmNonLinear.c 2 2 * 3 3 * @brief Contains the tests for pmNonLinear.c: … … 16 16 * @author GLG, MHPCC 17 17 * 18 * @version $Revision: 1.1 $ $Name: not supported by cvs2svn $ 19 * @date $Date: 2005-09-28 20:42:52 $ 18 * XXX: Add tests in which the lookup file has incorrect number of entries, 19 * and where the data is outside the pmReadout range. 20 * 21 * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $ 22 * @date $Date: 2005-10-20 23:06:24 $ 20 23 * 21 24 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 37 40 }; 38 41 39 40 int main(int argc, char* argv[])41 {42 psLogSetFormat("HLNM");43 return !runTestSuite(stderr, "Test Point Driver", tests, argc, argv);44 }45 46 42 #define NUM_ROWS 8 47 43 #define NUM_COLS 8 44 #define LOOKUP_FILENAME ".tmp_tst_pmNonLinearLookupFile" 45 int main(int argc, char* argv[]) 46 { 47 psLogSetFormat("HLNM"); 48 // 49 // We generate a lookup file for future tests. We should probably remove 50 // it when we're done. 51 // 52 FILE *fp = fopen(LOOKUP_FILENAME, "w"); 53 ; 54 for (psS32 i=0;i<PS_MAX(NUM_COLS, NUM_ROWS)*3;i++) { 55 fprintf(fp, "%f %f\n", (float) i, (float) (2 * i)); 56 } 57 fclose(fp); 58 59 // system("rm LOOKUP_FILENAME"); 60 return !runTestSuite(stderr, "Test Point Driver", tests, argc, argv); 61 } 62 48 63 int doNonLinearityPolynomialTest(int numCols, int numRows) 49 64 { … … 105 120 float expect; 106 121 int testStatus = true; 107 int tableSize = PS_MAX(numCols, numRows)*2;108 122 psImage *myImage = psImageAlloc(numCols, numRows, PS_TYPE_F32); 109 123 pmReadout *myReadout = pmReadoutAlloc(NULL); 110 124 myReadout->image = myImage; 111 psVector *in = psVectorAlloc(tableSize, PS_TYPE_F32);112 psVector *out = psVectorAlloc(tableSize, PS_TYPE_F32);113 125 114 126 printPositiveTestHeader(stdout, "pmNonLinear", "doNonLinearityLookupTest"); … … 119 131 } 120 132 121 for (i=0;i<tableSize;i++) { 122 in->data.F32[i] = (float) i; 123 out->data.F32[i] = (float) (2 * i); 124 } 125 126 myReadout = pmNonLinearityLookup(myReadout, in, out); 133 myReadout = pmNonLinearityLookup(myReadout, LOOKUP_FILENAME); 127 134 for (i=0;i<numRows;i++) { 128 135 for (j=0;j<numCols;j++) { … … 136 143 } 137 144 138 139 psFree(myReadout); 140 psFree(in); 141 psFree(out); 145 psFree(myReadout); 142 146 printFooter(stdout, "pmNonLinear", "doNonLinearityLookupTest", true); 143 147 return(testStatus); … … 220 224 int test03() 221 225 { 222 int i; 223 int j; 224 int testStatus = true; 225 int tableSize = PS_MAX(NUM_COLS, NUM_ROWS)*3; 226 int testStatus = true; 226 227 psImage *myImage = psImageAlloc(NUM_COLS, NUM_ROWS, PS_TYPE_F32); 227 228 pmReadout *myReadout = pmReadoutAlloc(NULL); 228 229 pmReadout *rc = NULL; 229 230 myReadout->image = myImage; 230 psVector *in = psVectorAlloc(tableSize, PS_TYPE_F32);231 psVector *inOne = psVectorAlloc(1, PS_TYPE_F32);232 psVector *inSmall = psVectorAlloc(tableSize-1, PS_TYPE_F32);233 psVector *inBig = psVectorAlloc(tableSize+1, PS_TYPE_F32);234 psVector *out = psVectorAlloc(tableSize, PS_TYPE_F32);235 psVector *outOne = psVectorAlloc(1, PS_TYPE_F32);236 psVector *outSmall = psVectorAlloc(tableSize-1, PS_TYPE_F32);237 psVector *outBig = psVectorAlloc(tableSize+1, PS_TYPE_F32);238 231 239 232 test03Init(myReadout); 240 for (i=0;i<tableSize;i++) {241 in->data.F32[i] = (float) i;242 out->data.F32[i] = (float) (2 * i);243 inBig->data.F32[i] = (float) i;244 outBig->data.F32[i] = (float) (2 * i);245 if (i < tableSize-1) {246 inSmall->data.F32[i] = (float) i;247 outSmall->data.F32[i] = (float) (2 * i);248 }249 }250 inBig->data.F32[tableSize] = (float) tableSize;251 outBig->data.F32[tableSize] = (float) (2 * tableSize);252 inOne->data.F32[0] = 0.0;253 outOne->data.F32[0] = 0.0;254 255 233 printf("------------------------------------------------------------\n"); 256 234 printf("Calling pmNonLinearityLookup() with NULL input pmReadout. Should generate error, return NULL.\n"); 257 rc = pmNonLinearityLookup(NULL, in, out);235 rc = pmNonLinearityLookup(NULL, LOOKUP_FILENAME); 258 236 if (rc != NULL) { 259 237 printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL pmReadout\n"); … … 265 243 psImage *tmpImage = myReadout->image; 266 244 myReadout->image = NULL; 267 rc = pmNonLinearityLookup(myReadout, in, out);245 rc = pmNonLinearityLookup(myReadout, LOOKUP_FILENAME); 268 246 if (rc != NULL) { 269 247 printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL pmReadout\n"); … … 273 251 274 252 printf("------------------------------------------------------------\n"); 275 printf("Calling pmNonLinearityLookup() with NULL inFlux psVector. Should generate error, return NULL.\n"); 276 rc = pmNonLinearityLookup(myReadout, NULL, out); 277 if (rc != NULL) { 278 printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL pmReadout\n"); 279 testStatus = false; 280 } 281 282 printf("------------------------------------------------------------\n"); 283 printf("Calling pmNonLinearityLookup() with NULL outFlux psVector. Should generate error, return NULL.\n"); 284 rc = pmNonLinearityLookup(myReadout, in, NULL); 285 if (rc != NULL) { 286 printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL pmReadout\n"); 287 testStatus = false; 288 } 289 290 test03Init(myReadout); 291 printf("------------------------------------------------------------\n"); 292 printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors. Should generate warning.\n"); 293 rc = pmNonLinearityLookup(myReadout, in, outBig); 253 printf("Calling pmNonLinearityLookup() with non-existent lookup file.\n"); 254 rc = pmNonLinearityLookup(myReadout, "I_DONT_EXIST"); 294 255 if (rc == NULL) { 295 256 printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n"); 296 257 testStatus = false; 297 258 } 298 for (i=0;i<NUM_ROWS;i++) { 299 for (j=0;j<NUM_COLS;j++) { 300 psF32 expect = (float) (2 * (i + j)); 301 psF32 actual = rc->image->data.F32[i][j]; 302 if (FLT_EPSILON < fabs(expect - actual)) { 303 printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect); 304 testStatus = false; 305 } 306 } 307 } 308 309 310 test03Init(myReadout); 311 printf("------------------------------------------------------------\n"); 312 printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors. Should generate warning.\n"); 313 rc = pmNonLinearityLookup(myReadout, in, outSmall); 314 if (rc == NULL) { 315 printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n"); 316 testStatus = false; 317 } 318 for (i=0;i<NUM_ROWS;i++) { 319 for (j=0;j<NUM_COLS;j++) { 320 psF32 expect = (float) (2 * (i + j)); 321 psF32 actual = rc->image->data.F32[i][j]; 322 if (FLT_EPSILON < fabs(expect - actual)) { 323 printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect); 324 testStatus = false; 325 } 326 } 327 } 328 329 test03Init(myReadout); 330 printf("------------------------------------------------------------\n"); 331 printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors. Should generate warning.\n"); 332 rc = pmNonLinearityLookup(myReadout, inSmall, out); 333 if (rc == NULL) { 334 printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n"); 335 testStatus = false; 336 } 337 for (i=0;i<NUM_ROWS;i++) { 338 for (j=0;j<NUM_COLS;j++) { 339 psF32 expect = (float) (2 * (i + j)); 340 psF32 actual = rc->image->data.F32[i][j]; 341 if (FLT_EPSILON < fabs(expect - actual)) { 342 printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect); 343 testStatus = false; 344 } 345 } 346 } 347 348 test03Init(myReadout); 349 printf("------------------------------------------------------------\n"); 350 printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors. Should generate warning.\n"); 351 rc = pmNonLinearityLookup(myReadout, inBig, out); 352 if (rc == NULL) { 353 printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n"); 354 testStatus = false; 355 } 356 for (i=0;i<NUM_ROWS;i++) { 357 for (j=0;j<NUM_COLS;j++) { 358 psF32 expect = (float) (2 * (i + j)); 359 psF32 actual = rc->image->data.F32[i][j]; 360 if (FLT_EPSILON < fabs(expect - actual)) { 361 printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect); 362 testStatus = false; 363 } 364 } 365 } 366 367 test03Init(myReadout); 368 printf("------------------------------------------------------------\n"); 369 printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors. Should generate warning.\n"); 370 rc = pmNonLinearityLookup(myReadout, inSmall, outBig); 371 if (rc == NULL) { 372 printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n"); 373 testStatus = false; 374 } 375 for (i=0;i<NUM_ROWS;i++) { 376 for (j=0;j<NUM_COLS;j++) { 377 psF32 expect = (float) (2 * (i + j)); 378 psF32 actual = rc->image->data.F32[i][j]; 379 if (FLT_EPSILON < fabs(expect - actual)) { 380 printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect); 381 testStatus = false; 382 } 383 } 384 } 385 386 test03Init(myReadout); 387 printf("------------------------------------------------------------\n"); 388 printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors. Should generate warning.\n"); 389 rc = pmNonLinearityLookup(myReadout, inBig, outSmall); 390 if (rc == NULL) { 391 printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n"); 392 testStatus = false; 393 } 394 for (i=0;i<NUM_ROWS;i++) { 395 for (j=0;j<NUM_COLS;j++) { 396 psF32 expect = (float) (2 * (i + j)); 397 psF32 actual = rc->image->data.F32[i][j]; 398 if (FLT_EPSILON < fabs(expect - actual)) { 399 printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect); 400 testStatus = false; 401 } 402 } 403 } 404 405 test03Init(myReadout); 406 printf("------------------------------------------------------------\n"); 407 printf("Calling pmNonLinearityLookup() with inFlux psVector size 1. Should generate error, return original pmReadout.\n"); 408 rc = pmNonLinearityLookup(myReadout, inOne, out); 409 if (rc != myReadout) { 410 printf("TEST ERROR: pmNonLinearityPolynomial() did not return the original pmReadout\n"); 411 testStatus = false; 412 } 413 for (i=0;i<NUM_ROWS;i++) { 414 for (j=0;j<NUM_COLS;j++) { 415 psF32 expect = (float) ((i + j)); 416 psF32 actual = rc->image->data.F32[i][j]; 417 if (FLT_EPSILON < fabs(expect - actual)) { 418 printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect); 419 testStatus = false; 420 } 421 } 422 } 259 423 260 424 261 printf("------------------------------------------------------------\n"); 425 262 printf("Calling pmNonLinearityLookup() with one pixels outside inFlux range. Should generate warnings.\n"); 426 test03Init(myReadout); 427 myReadout->image->data.F32[0][0] = -1; 428 rc = pmNonLinearityLookup(myReadout, in, out); 429 if (rc == NULL) { 430 printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n"); 431 testStatus = false; 432 } 433 for (i=0;i<NUM_ROWS;i++) { 434 for (j=0;j<NUM_COLS;j++) { 435 psF32 expect = (float) (2 * (i + j)); 436 psF32 actual = rc->image->data.F32[i][j]; 437 if(i==0 && j==0) { 438 if(actual != 0.0) { 439 printf("TEST ERROR: image[%d][%d] is %f, should be %f\n",i,j,actual,0.0); 440 } 441 } else { 442 if (FLT_EPSILON < fabs(expect - actual)) { 443 printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect); 444 testStatus = false; 445 } 446 } 447 } 448 } 449 450 printf("------------------------------------------------------------\n"); 451 printf("Calling pmNonLinearityLookup() with one pixels outside inFlux range. Should generate warnings.\n"); 452 test03Init(myReadout); 453 myReadout->image->data.F32[NUM_ROWS-1][NUM_COLS-1] = 100; 454 rc = pmNonLinearityLookup(myReadout, in, out); 455 if (rc == NULL) { 456 printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n"); 457 testStatus = false; 458 } 459 for (i=0;i<NUM_ROWS;i++) { 460 for (j=0;j<NUM_COLS;j++) { 461 psF32 expect = (float) (2 * (i + j)); 462 psF32 actual = rc->image->data.F32[i][j]; 463 if(i==(NUM_ROWS-1) && j==(NUM_COLS-1)) { 464 if(actual != (tableSize-1)*2) { 465 printf("TEST ERROR: image[%d][%d] is %f, should be %f\n",i,j,actual,(tableSize-1)*2.0); 466 } 467 } else { 468 if (FLT_EPSILON < fabs(expect - actual)) { 469 printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect); 470 testStatus = false; 471 } 472 } 473 } 474 } 475 476 test03Init(myReadout); 477 printf("------------------------------------------------------------\n"); 478 printf("Calling pmNonLinearityLookup() with image values not in vector.\n"); 479 myReadout->image->data.F32[0][0] = 0.5; 480 rc = pmNonLinearityLookup(myReadout, in, out); 481 if (rc == NULL) { 482 printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL pmReadout\n"); 483 testStatus = false; 484 } 485 for (i=0;i<NUM_ROWS;i++) { 486 for (j=0;j<NUM_COLS;j++) { 487 psF32 expect = (float) (2 * (i + j)); 488 if(i==0 && j==0) { 489 expect = 1.0; 490 } 491 psF32 actual = rc->image->data.F32[i][j]; 492 if (FLT_EPSILON < fabs(expect - actual)) { 493 printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect); 494 testStatus = false; 495 } 496 } 497 } 498 499 psFree(myReadout); 500 psFree(in); 501 psFree(inOne); 502 psFree(inSmall); 503 psFree(inBig); 504 psFree(out); 505 psFree(outOne); 506 psFree(outSmall); 507 psFree(outBig); 263 264 psFree(myReadout); 508 265 509 266 printFooter(stdout, "pmNonLinear", "Testing bad input parameter conditions.", true);
Note:
See TracChangeset
for help on using the changeset viewer.
