Changeset 3717 for trunk/psModules/test/tst_pmObjects01.c
- Timestamp:
- Apr 19, 2005, 12:58:48 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/psModules/test/tst_pmObjects01.c (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/test/tst_pmObjects01.c
r3697 r3717 19 19 * abd never deallocate, no error is generated. 20 20 * 21 * @version $Revision: 1. 4$ $Name: not supported by cvs2svn $22 * @date $Date: 2005-04-1 4 00:16:39$21 * @version $Revision: 1.5 $ $Name: not supported by cvs2svn $ 22 * @date $Date: 2005-04-19 22:58:48 $ 23 23 * 24 24 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 62 62 int main(int argc, char* argv[]) 63 63 { 64 return !runTestSuite(stderr, "Test Point Driver", tests, argc, argv); 64 // return !runTestSuite(stderr, "Test Point Driver", tests, argc, argv); 65 test02(); 65 66 } 66 67 … … 73 74 psTraceSetLevel(".", 0); 74 75 75 psPeak *tmpPeak = pmPeakAlloc(0, 0, 0.0, PM_PEAK_UNDEF); 76 printf("Testing pmPeakAlloc()...\n"); 77 psPeak *tmpPeak = pmPeakAlloc(1, 2, 3.0, PM_PEAK_LONE); 76 78 if (tmpPeak == NULL) { 77 79 printf("TEST ERROR: pmPeakAlloc() returned a NULL psPeak\n"); 78 80 testStatus = false; 79 } 80 // XXX: Test that values were set properly. 81 } else { 82 if (tmpPeak->x != 1) { 83 printf("TEST ERROR: pmPeakAlloc() improperly set psPeak->x\n"); 84 testStatus = false; 85 } 86 if (tmpPeak->y != 2) { 87 printf("TEST ERROR: pmPeakAlloc() improperly set psPeak->y\n"); 88 testStatus = false; 89 } 90 if (tmpPeak->counts != 3.0) { 91 printf("TEST ERROR: pmPeakAlloc() improperly set psPeak->counts\n"); 92 testStatus = false; 93 } 94 if (tmpPeak->class != PM_PEAK_LONE) { 95 printf("TEST ERROR: pmPeakAlloc() improperly set psPeak->class\n"); 96 testStatus = false; 97 } 98 } 81 99 psFree(tmpPeak); 82 100 101 printf("Testing pmMomentsAlloc()...\n"); 83 102 psMoments *tmpMoments = pmMomentsAlloc(); 84 103 if (tmpMoments == NULL) { 85 104 printf("TEST ERROR: pmMomentsAlloc() returned a NULL psMoments\n"); 86 105 testStatus = false; 106 } else { 107 if ((tmpMoments->x != 0.0) || 108 (tmpMoments->y != 0.0) || 109 (tmpMoments->Sx != 0.0) || 110 (tmpMoments->Sy != 0.0) || 111 (tmpMoments->Sxy != 0.0) || 112 (tmpMoments->Sum != 0.0) || 113 (tmpMoments->Peak != 0.0) || 114 (tmpMoments->Sky != 0.0) || 115 (tmpMoments->nPixels != 0)) { 116 printf("TEST ERROR: pmMomentsAlloc() did not properly initialize the psMoments structure.\n"); 117 testStatus = false; 118 } 87 119 } 88 120 psFree(tmpMoments); 89 121 90 // XXX: Must test this with variety of models, and verify param length.122 printf("Testing pmModelAlloc(PS_MODEL_GAUSS)...\n"); 91 123 psModel *tmpModel = pmModelAlloc(PS_MODEL_GAUSS); 92 124 if (tmpModel == NULL) { 93 printf("TEST ERROR: pmModelAlloc() returned a NULL psModel\n"); 94 testStatus = false; 95 } 96 // XXX: Test that values were set properly. 125 printf("TEST ERROR: pmModelAlloc(PS_MODEL_GAUSS) returned a NULL psModel\n"); 126 testStatus = false; 127 } else { 128 if (tmpModel->Nparams != 7) { 129 printf("TEST ERROR: pmModelAlloc(PS_MODEL_GAUSS) allocated an incorrect number of params (%d)\n", tmpModel->Nparams); 130 testStatus = false; 131 } else { 132 for (psS32 i = 0 ; i < 7 ; i++) { 133 if ((tmpModel->params[i] != 0.0) || 134 (tmpModel->dparams[i] != 0.0)) { 135 printf("TEST ERROR: pmModelAlloc(PS_MODEL_GAUSS) did not ininitialize the params/dparams array to 0.0.\n"); 136 testStatus = false; 137 } 138 } 139 } 140 } 97 141 psFree(tmpModel); 98 142 99 // XXX: Must test this with variety of models, and verify param length.143 printf("Testing pmModelAlloc(PS_MODEL_PGAUSS)...\n"); 100 144 tmpModel = pmModelAlloc(PS_MODEL_PGAUSS); 101 145 if (tmpModel == NULL) { 102 printf("TEST ERROR: pmModelAlloc() returned a NULL psModel\n"); 103 testStatus = false; 104 } 105 // XXX: Test that values were set properly. 146 printf("TEST ERROR: pmModelAlloc(PS_MODEL_PGAUSS) returned a NULL psModel\n"); 147 testStatus = false; 148 } else { 149 if (tmpModel->Nparams != 7) { 150 printf("TEST ERROR: pmModelAlloc(PS_MODEL_PGAUSS) allocated an incorrect number of params (%d)\n", tmpModel->Nparams); 151 testStatus = false; 152 } else { 153 for (psS32 i = 0 ; i < 7 ; i++) { 154 if ((tmpModel->params[i] != 0.0) || 155 (tmpModel->dparams[i] != 0.0)) { 156 printf("TEST ERROR: pmModelAlloc(PS_MODEL_PGAUSS) did not ininitialize the params/dparams array to 0.0.\n"); 157 testStatus = false; 158 } 159 } 160 } 161 } 106 162 psFree(tmpModel); 107 163 108 // XXX: Must test this with variety of models, and verify param length.164 printf("Testing pmModelAlloc(PS_MODEL_TWIST_GAUSS)...\n"); 109 165 tmpModel = pmModelAlloc(PS_MODEL_TWIST_GAUSS); 110 166 if (tmpModel == NULL) { 111 printf("TEST ERROR: pmModelAlloc() returned a NULL psModel\n"); 112 testStatus = false; 113 } 114 // XXX: Test that values were set properly. 167 printf("TEST ERROR: pmModelAlloc(PS_MODEL_TWIST_GAUSS) returned a NULL psModel\n"); 168 testStatus = false; 169 } else { 170 if (tmpModel->Nparams != 11) { 171 printf("TEST ERROR: pmModelAlloc(PS_MODEL_TWIST_GAUSS) allocated an incorrect number of params (%d)\n", tmpModel->Nparams); 172 testStatus = false; 173 } else { 174 for (psS32 i = 0 ; i < 11 ; i++) { 175 if ((tmpModel->params[i] != 0.0) || 176 (tmpModel->dparams[i] != 0.0)) { 177 printf("TEST ERROR: pmModelAlloc(PS_MODEL_TWIST_GAUSS) did not ininitialize the params/dparams array to 0.0.\n"); 178 testStatus = false; 179 } 180 } 181 } 182 } 115 183 psFree(tmpModel); 116 184 117 // XXX: Must test this with variety of models, and verify param length.185 printf("Testing pmModelAlloc(PS_MODEL_WAUSS)...\n"); 118 186 tmpModel = pmModelAlloc(PS_MODEL_WAUSS); 119 187 if (tmpModel == NULL) { 120 printf("TEST ERROR: pmModelAlloc() returned a NULL psModel\n"); 121 testStatus = false; 122 } 123 // XXX: Test that values were set properly. 188 printf("TEST ERROR: pmModelAlloc(PS_MODEL_WAUSS) returned a NULL psModel\n"); 189 testStatus = false; 190 } else { 191 if (tmpModel->Nparams != 9) { 192 printf("TEST ERROR: pmModelAlloc(PS_MODEL_WAUSS) allocated an incorrect number of params (%d)\n", tmpModel->Nparams); 193 testStatus = false; 194 } else { 195 for (psS32 i = 0 ; i < 9 ; i++) { 196 if ((tmpModel->params[i] != 0.0) || 197 (tmpModel->dparams[i] != 0.0)) { 198 printf("TEST ERROR: pmModelAlloc(PS_MODEL_WAUSS) did not ininitialize the params/dparams array to 0.0.\n"); 199 testStatus = false; 200 } 201 } 202 } 203 } 124 204 psFree(tmpModel); 125 205 126 // XXX: Must test this with variety of models, and verify param length.206 printf("Testing pmModelAlloc(PS_MODEL_SERSIC)...\n"); 127 207 tmpModel = pmModelAlloc(PS_MODEL_SERSIC); 128 208 if (tmpModel == NULL) { 129 printf("TEST ERROR: pmModelAlloc() returned a NULL psModel\n"); 130 testStatus = false; 131 } 132 // XXX: Test that values were set properly. 209 printf("TEST ERROR: pmModelAlloc(PS_MODEL_SERSIC) returned a NULL psModel\n"); 210 testStatus = false; 211 } else { 212 if (tmpModel->Nparams != 8) { 213 printf("TEST ERROR: pmModelAlloc(PS_MODEL_SERSIC) allocated an incorrect number of params (%d)\n", tmpModel->Nparams); 214 testStatus = false; 215 } else { 216 for (psS32 i = 0 ; i < 8 ; i++) { 217 if ((tmpModel->params[i] != 0.0) || 218 (tmpModel->dparams[i] != 0.0)) { 219 printf("TEST ERROR: pmModelAlloc(PS_MODEL_SERSIC) did not ininitialize the params/dparams array to 0.0.\n"); 220 testStatus = false; 221 } 222 } 223 } 224 } 133 225 psFree(tmpModel); 134 226 135 // XXX: Must test this with variety of models, and verify param length.227 printf("Testing pmModelAlloc(PS_MODEL_SERSIC_CORE)...\n"); 136 228 tmpModel = pmModelAlloc(PS_MODEL_SERSIC_CORE); 137 229 if (tmpModel == NULL) { 138 printf("TEST ERROR: pmModelAlloc() returned a NULL psModel\n"); 139 testStatus = false; 140 } 141 // XXX: Test that values were set properly. 230 printf("TEST ERROR: pmModelAlloc(PS_MODEL_SERSIC_CORE) returned a NULL psModel\n"); 231 testStatus = false; 232 } else { 233 if (tmpModel->Nparams != 12) { 234 printf("TEST ERROR: pmModelAlloc(PS_MODEL_SERSIC_CORE) allocated an incorrect number of params (%d)\n", tmpModel->Nparams); 235 testStatus = false; 236 } else { 237 for (psS32 i = 0 ; i < 12 ; i++) { 238 if ((tmpModel->params[i] != 0.0) || 239 (tmpModel->dparams[i] != 0.0)) { 240 printf("TEST ERROR: pmModelAlloc(PS_MODEL_SERSIC_CORE) did not ininitialize the params/dparams array to 0.0.\n"); 241 testStatus = false; 242 } 243 } 244 } 245 } 142 246 psFree(tmpModel); 143 247 … … 152 256 } 153 257 154 #define VECTOR_SIZE 10 258 /****************************************************************************** 259 test01(): we first test pmFindVectorPeaks() with a variety of bad input 260 parameters. Then we test it with a simple vector both 1- and multi-elements. 261 *****************************************************************************/ 262 #define TST01_VECTOR_LENGTH 10 155 263 bool test_pmFindVectorPeaks(int n) 156 264 { … … 174 282 testStatus = false; 175 283 } else { 176 177 284 if (outData->n != 1) { 178 285 printf("TEST ERROR: outData->n is %d\n", outData->n); … … 315 422 } 316 423 317 318 424 psFree(inData); 319 425 return(testStatus); 320 426 } 321 322 427 323 428 int test01( void ) … … 325 430 bool testStatus = true; 326 431 psVector *tmpVec = NULL; 327 psVector *tmpVecF64 = psVectorAlloc( 10, PS_TYPE_F64);432 psVector *tmpVecF64 = psVectorAlloc(TST01_VECTOR_LENGTH, PS_TYPE_F64); 328 433 psVector *tmpVecEmpty = psVectorAlloc(0, PS_TYPE_F32); 329 434 … … 357 462 } 358 463 testStatus&= test_pmFindVectorPeaks(1); 359 testStatus&= test_pmFindVectorPeaks( VECTOR_SIZE);464 testStatus&= test_pmFindVectorPeaks(TST01_VECTOR_LENGTH); 360 465 361 466 psFree(tmpVecF64); … … 364 469 } 365 470 366 // XXX: Add tests for the PEAK_TYPE. 367 // XXX: Add interior peaks, edge peaks, and flat peaks. 471 /****************************************************************************** 472 test02(): 473 // XXX: Must test flat peaks. 474 // XXX: test 1-by-n and n-by-1 images. 475 *****************************************************************************/ 476 #define TST02_NUM_ROWS 5 477 #define TST02_NUM_COLS 5 368 478 bool test_pmFindImagePeaks(int numRows, int numCols) 369 479 { 370 480 printf("-------------- Calling test_pmFindVectorPeaks on an %d-by-%d image. --------------\n", numRows, numCols); 481 if ((numRows < 4) || (numCols < 4)) { 482 printf("WARNING: Don't call this test with a smaller than 4-by-4 image.\n"); 483 return(true); 484 } 371 485 bool testStatus = true; 372 486 psImage *inData = psImageAlloc(numCols, numRows, PS_TYPE_F32); … … 374 488 375 489 // 376 // Test first pixel peak.490 // Initialize test image. 377 491 // 378 492 for (psS32 i = 0 ; i < numRows ; i++) { … … 381 495 } 382 496 } 497 // 498 // Set corner and center pixels as peaks. 499 // 383 500 inData->data.F32[0][0] = PS_SQR(numRows) + PS_SQR(numCols); 384 501 inData->data.F32[0][numCols-1] = PS_SQR(numRows) + PS_SQR(numCols); 385 502 inData->data.F32[numRows-1][0] = PS_SQR(numRows) + PS_SQR(numCols); 386 503 inData->data.F32[numRows-1][numCols-1] = PS_SQR(numRows) + PS_SQR(numCols); 504 inData->data.F32[numRows/2][numCols/2] = PS_SQR(numRows) + PS_SQR(numCols); 505 506 // 507 // Print image. 508 // 387 509 for (psS32 i = 0 ; i < numRows ; i++) { 388 510 for (psS32 j = 0 ; j < numCols ; j++) { … … 392 514 } 393 515 516 // 517 // Call pmFindImagePeaks() with a threshold of 0.0. 518 // 394 519 outData = pmFindImagePeaks(inData, 0.0); 395 520 … … 398 523 testStatus = false; 399 524 } else { 400 if (outData->size != 4) {401 printf("TEST ERROR: pmFindImagePeaks found only%d peaks (should be 4)\n", outData->size);525 if (outData->size != 5) { 526 printf("TEST ERROR: pmFindImagePeaks found %d peaks (should be 4)\n", outData->size); 402 527 testStatus = false; 403 528 } … … 406 531 while (tmpPeakLE != NULL) { 407 532 psPeak *tmpPeak = (psPeak *) tmpPeakLE->data; 408 if (((tmpPeak->x == 0) || (tmpPeak->x == numRows-1)) && 409 ((tmpPeak->y == 0) || (tmpPeak->y == numCols-1))) {} 410 else { 411 printf("TEST ERROR: Peak at (%d, %d) (%f)\n", tmpPeak->x, tmpPeak->y, tmpPeak->counts); 533 if (((tmpPeak->x == 0) && (tmpPeak->y == 0)) || 534 ((tmpPeak->x == 0) && (tmpPeak->y == numRows-1)) || 535 ((tmpPeak->x == numCols-1) && (tmpPeak->y == 0)) || 536 ((tmpPeak->x == numCols-1) && (tmpPeak->y == numRows-1))) { 537 if (!(tmpPeak->class & PM_PEAK_LONE) || 538 !(tmpPeak->class & PM_PEAK_EDGE)) { 539 printf("TEST ERROR: peak at (%d, %d) (%f) ->class set improperly (0x%x).\n", tmpPeak->y, tmpPeak->x, tmpPeak->counts, tmpPeak->class); 540 testStatus = false; 541 } 542 } else if ((tmpPeak->x == numCols/2) && (tmpPeak->y == numRows/2)) { 543 if (!(tmpPeak->class & PM_PEAK_LONE)) { 544 printf("TEST ERROR: peak at (%d, %d) (%f) ->class set improperly (0x%x).\n", tmpPeak->y, tmpPeak->x, tmpPeak->counts, tmpPeak->class); 545 testStatus = false; 546 } 547 } else { 548 printf("TEST ERROR: Peak at (%d, %d) (%f)\n", tmpPeak->y, tmpPeak->x, tmpPeak->counts); 412 549 testStatus = false; 413 550 } 551 414 552 tmpPeakLE = tmpPeakLE->next; 415 553 } … … 421 559 } 422 560 423 424 561 int test02( void ) 425 562 { 426 563 bool testStatus = true; 427 564 psList *tmpList = NULL; 428 psImage *tmpImageF64 = psImageAlloc( 10, 10, PS_TYPE_F64);565 psImage *tmpImageF64 = psImageAlloc(TST02_NUM_ROWS, TST02_NUM_COLS, PS_TYPE_F64); 429 566 psImage *tmpImageEmpty = psImageAlloc(0, 0, PS_TYPE_F32); 430 567 … … 461 598 // testStatus&= test_pmFindImagePeaks(2, 5); 462 599 // testStatus&= test_pmFindImagePeaks(5, 2); 463 testStatus&= test_pmFindImagePeaks(10, 10); 600 // HEY 601 testStatus&= test_pmFindImagePeaks(TST02_NUM_ROWS, TST02_NUM_COLS); 602 testStatus&= test_pmFindImagePeaks(2*TST02_NUM_ROWS, TST02_NUM_COLS); 603 testStatus&= test_pmFindImagePeaks(TST02_NUM_ROWS, 2*TST02_NUM_COLS); 464 604 465 605
Note:
See TracChangeset
for help on using the changeset viewer.
