IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 19, 2005, 12:58:48 PM (21 years ago)
Author:
gusciora
Message:

Cleaning the code in pmObjects.c, fixing bugs with the allocators and the
vector/image find peaks routines, adding additional tests for these.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/test/tst_pmObjects01.c

    r3697 r3717  
    1919 * abd never deallocate, no error is generated.
    2020 *
    21  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    22  *  @date $Date: 2005-04-14 00:16:39 $
     21 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     22 *  @date $Date: 2005-04-19 22:58:48 $
    2323 *
    2424 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    6262int main(int argc, char* argv[])
    6363{
    64     return !runTestSuite(stderr, "Test Point Driver", tests, argc, argv);
     64    //    return !runTestSuite(stderr, "Test Point Driver", tests, argc, argv);
     65    test02();
    6566}
    6667
     
    7374    psTraceSetLevel(".", 0);
    7475
    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);
    7678    if (tmpPeak == NULL) {
    7779        printf("TEST ERROR: pmPeakAlloc() returned a NULL psPeak\n");
    7880        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    }
    8199    psFree(tmpPeak);
    82100
     101    printf("Testing pmMomentsAlloc()...\n");
    83102    psMoments *tmpMoments = pmMomentsAlloc();
    84103    if (tmpMoments == NULL) {
    85104        printf("TEST ERROR: pmMomentsAlloc() returned a NULL psMoments\n");
    86105        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        }
    87119    }
    88120    psFree(tmpMoments);
    89121
    90     // XXX: Must test this with variety of models, and verify param length.
     122    printf("Testing pmModelAlloc(PS_MODEL_GAUSS)...\n");
    91123    psModel *tmpModel = pmModelAlloc(PS_MODEL_GAUSS);
    92124    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    }
    97141    psFree(tmpModel);
    98142
    99     // XXX: Must test this with variety of models, and verify param length.
     143    printf("Testing pmModelAlloc(PS_MODEL_PGAUSS)...\n");
    100144    tmpModel = pmModelAlloc(PS_MODEL_PGAUSS);
    101145    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    }
    106162    psFree(tmpModel);
    107163
    108     // XXX: Must test this with variety of models, and verify param length.
     164    printf("Testing pmModelAlloc(PS_MODEL_TWIST_GAUSS)...\n");
    109165    tmpModel = pmModelAlloc(PS_MODEL_TWIST_GAUSS);
    110166    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    }
    115183    psFree(tmpModel);
    116184
    117     // XXX: Must test this with variety of models, and verify param length.
     185    printf("Testing pmModelAlloc(PS_MODEL_WAUSS)...\n");
    118186    tmpModel = pmModelAlloc(PS_MODEL_WAUSS);
    119187    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    }
    124204    psFree(tmpModel);
    125205
    126     // XXX: Must test this with variety of models, and verify param length.
     206    printf("Testing pmModelAlloc(PS_MODEL_SERSIC)...\n");
    127207    tmpModel = pmModelAlloc(PS_MODEL_SERSIC);
    128208    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    }
    133225    psFree(tmpModel);
    134226
    135     // XXX: Must test this with variety of models, and verify param length.
     227    printf("Testing pmModelAlloc(PS_MODEL_SERSIC_CORE)...\n");
    136228    tmpModel = pmModelAlloc(PS_MODEL_SERSIC_CORE);
    137229    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    }
    142246    psFree(tmpModel);
    143247
     
    152256}
    153257
    154 #define VECTOR_SIZE 10
     258/******************************************************************************
     259test01(): we first test pmFindVectorPeaks() with a variety of bad input
     260parameters.  Then we test it with a simple vector both 1- and multi-elements.
     261 *****************************************************************************/
     262#define TST01_VECTOR_LENGTH 10
    155263bool test_pmFindVectorPeaks(int n)
    156264{
     
    174282        testStatus = false;
    175283    } else {
    176 
    177284        if (outData->n != 1) {
    178285            printf("TEST ERROR: outData->n is %d\n", outData->n);
     
    315422    }
    316423
    317 
    318424    psFree(inData);
    319425    return(testStatus);
    320426}
    321 
    322427
    323428int test01( void )
     
    325430    bool testStatus = true;
    326431    psVector *tmpVec = NULL;
    327     psVector *tmpVecF64 = psVectorAlloc(10, PS_TYPE_F64);
     432    psVector *tmpVecF64 = psVectorAlloc(TST01_VECTOR_LENGTH, PS_TYPE_F64);
    328433    psVector *tmpVecEmpty = psVectorAlloc(0, PS_TYPE_F32);
    329434
     
    357462    }
    358463    testStatus&= test_pmFindVectorPeaks(1);
    359     testStatus&= test_pmFindVectorPeaks(VECTOR_SIZE);
     464    testStatus&= test_pmFindVectorPeaks(TST01_VECTOR_LENGTH);
    360465
    361466    psFree(tmpVecF64);
     
    364469}
    365470
    366 // XXX: Add tests for the PEAK_TYPE.
    367 // XXX: Add interior peaks, edge peaks, and flat peaks.
     471/******************************************************************************
     472test02():
     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
    368478bool test_pmFindImagePeaks(int numRows, int numCols)
    369479{
    370480    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    }
    371485    bool testStatus = true;
    372486    psImage *inData = psImageAlloc(numCols, numRows, PS_TYPE_F32);
     
    374488
    375489    //
    376     // Test first pixel peak.
     490    // Initialize test image.
    377491    //
    378492    for (psS32 i = 0 ; i < numRows ; i++) {
     
    381495        }
    382496    }
     497    //
     498    // Set corner and center pixels as peaks.
     499    //
    383500    inData->data.F32[0][0] = PS_SQR(numRows) + PS_SQR(numCols);
    384501    inData->data.F32[0][numCols-1] = PS_SQR(numRows) + PS_SQR(numCols);
    385502    inData->data.F32[numRows-1][0] = PS_SQR(numRows) + PS_SQR(numCols);
    386503    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    //
    387509    for (psS32 i = 0 ; i < numRows ; i++) {
    388510        for (psS32 j = 0 ; j < numCols ; j++) {
     
    392514    }
    393515
     516    //
     517    // Call pmFindImagePeaks() with a threshold of 0.0.
     518    //
    394519    outData = pmFindImagePeaks(inData, 0.0);
    395520
     
    398523        testStatus = false;
    399524    } 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);
    402527            testStatus = false;
    403528        }
     
    406531        while (tmpPeakLE != NULL) {
    407532            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);
    412549                testStatus = false;
    413550            }
     551
    414552            tmpPeakLE = tmpPeakLE->next;
    415553        }
     
    421559}
    422560
    423 
    424561int test02( void )
    425562{
    426563    bool testStatus = true;
    427564    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);
    429566    psImage *tmpImageEmpty = psImageAlloc(0, 0, PS_TYPE_F32);
    430567
     
    461598    //    testStatus&= test_pmFindImagePeaks(2, 5);
    462599    //    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);
    464604
    465605
Note: See TracChangeset for help on using the changeset viewer.