IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 5, 2005, 1:25:25 PM (22 years ago)
Author:
gusciora
Message:

Added tests to for various input parameters being NULL, or of incorrect
length.

File:
1 edited

Legend:

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

    r2857 r2915  
    1111 * N), (N, 1), (N, N)]. 
    1212 *
     13 * test02, test03: This code tests the functions with various unallowable
     14 * input parameters (NULLS) and incorrect vector sizes.
     15 *
    1316 *  @author GLG, MHPCC
    1417 *
    15  *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
    16  *  @date $Date: 2004-12-30 22:22:00 $
     18 *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
     19 *  @date $Date: 2005-01-05 23:25:25 $
    1720 *
    1821 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2427static int test00(void);
    2528static int test01(void);
     29static int test02(void);
     30static int test03(void);
    2631testDescription tests[] = {
    27                               {test00, 000, "pmNonLinearityPolynomial", 0, false},
    28                               {test01, 000, "pmNonLinearityLookup", 0, false},
     32                              {test00, 000, "pmNonLinearityPolynomial", true, false},
     33                              {test01, 000, "pmNonLinearityLookup", true, false},
     34                              {test02, 000, "pmNonLinearityPolynomial(): error/warning conditions", true, false},
     35                              {test03, 000, "pmNonLinearityLookup(): error/warning conditions", true, false},
    2936                              {NULL}
    3037                          };
     
    4451    float actual;
    4552    float expect;
    46     int testStatus = 0;
     53    int testStatus = true;
    4754    psImage *myImage = psImageAlloc(numCols, numRows, PS_TYPE_F32);
    48     //    psReadout *myReadout = psReadoutAlloc(numCols, numRows, myImage);
    4955    psReadout *myReadout = psReadoutAlloc();
    5056    myReadout->image = myImage;
     
    6470            actual = myReadout->image->data.F32[i][j];
    6571            if (FLT_EPSILON < fabs(expect - actual)) {
    66                 printf("ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
    67                 testStatus = 1;
     72                printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
     73                testStatus = false;
    6874            }
    6975        }
     
    94100    float actual;
    95101    float expect;
    96     int testStatus = 0;
     102    int testStatus = true;
    97103    int tableSize = PS_MAX(numCols, numRows)*2;
    98104    psImage *myImage = psImageAlloc(numCols, numRows, PS_TYPE_F32);
    99     //    psReadout *myReadout = psReadoutAlloc(numCols, numRows, myImage);
    100105    psReadout *myReadout = psReadoutAlloc();
    101106    myReadout->image = myImage;
     
    120125            actual = myReadout->image->data.F32[i][j];
    121126            if (FLT_EPSILON < fabs(expect - actual)) {
    122                 printf("ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
    123                 testStatus = 1;
     127                printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
     128                testStatus = false;
    124129            }
    125130        }
     
    144149    return(testStatus);
    145150}
     151
     152int test02( void )
     153{
     154    int i;
     155    int j;
     156    int testStatus = true;
     157    psImage *myImage = psImageAlloc(NUM_COLS, NUM_ROWS, PS_TYPE_F32);
     158    psReadout *myReadout = psReadoutAlloc();
     159    psReadout *rc = NULL;
     160    myReadout->image = myImage;
     161    psPolynomial1D *myPoly = psPolynomial1DAlloc(2, PS_POLYNOMIAL_ORD);
     162    myPoly->coeff[1] = 1.0;
     163
     164    for (i=0;i<NUM_ROWS;i++) {
     165        for (j=0;j<NUM_COLS;j++) {
     166            myReadout->image->data.F32[i][j] = (float) (i + j);
     167        }
     168    }
     169
     170    printf("------------------------------------------------------------\n");
     171    printf("Calling pmNonLinearityPolynomial() with NULL input readout.  Should generate error, return NULL.\n");
     172    rc = pmNonLinearityPolynomial(NULL, myPoly);
     173    if (rc != NULL) {
     174        printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL psReadout\n");
     175        testStatus = false;
     176    }
     177
     178    printf("------------------------------------------------------------\n");
     179    printf("Calling pmNonLinearityPolynomial() with NULL input readout->image.  Should generate error, return NULL.\n");
     180    psImage *tmpImage = myReadout->image;
     181    myReadout->image = NULL;
     182    rc = pmNonLinearityPolynomial(myReadout, myPoly);
     183    if (rc != NULL) {
     184        printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL psReadout\n");
     185        testStatus = false;
     186    }
     187    myReadout->image = tmpImage;
     188
     189    printf("------------------------------------------------------------\n");
     190    printf("Calling pmNonLinearityPolynomial() with NULL polynomial.  Should generate error, return NULL.\n");
     191    rc = pmNonLinearityPolynomial(myReadout, NULL);
     192    if (rc != NULL) {
     193        printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL psReadout\n");
     194        testStatus = false;
     195    }
     196
     197    psFree(myReadout);
     198    psFree(myPoly);
     199    return(testStatus);
     200}
     201
     202
     203int test03Init(psReadout *myReadout)
     204{
     205    for (psS32 i=0;i<NUM_ROWS;i++) {
     206        for (psS32 j=0;j<NUM_COLS;j++) {
     207            myReadout->image->data.F32[i][j] = (float) (i + j);
     208        }
     209    }
     210    return(0);
     211}
     212
     213int test03()
     214{
     215    int i;
     216    int j;
     217    int testStatus = true;
     218    int tableSize = PS_MAX(NUM_COLS, NUM_ROWS)*3;
     219    psImage *myImage = psImageAlloc(NUM_COLS, NUM_ROWS, PS_TYPE_F32);
     220    psReadout *myReadout = psReadoutAlloc();
     221    psReadout *rc = NULL;
     222    myReadout->image = myImage;
     223    psVector *in = psVectorAlloc(tableSize, PS_TYPE_F32);
     224    psVector *inOne = psVectorAlloc(1, PS_TYPE_F32);
     225    psVector *inSmall = psVectorAlloc(tableSize-1, PS_TYPE_F32);
     226    psVector *inBig = psVectorAlloc(tableSize+1, PS_TYPE_F32);
     227    psVector *out = psVectorAlloc(tableSize, PS_TYPE_F32);
     228    psVector *outOne = psVectorAlloc(1, PS_TYPE_F32);
     229    psVector *outSmall = psVectorAlloc(tableSize-1, PS_TYPE_F32);
     230    psVector *outBig = psVectorAlloc(tableSize+1, PS_TYPE_F32);
     231
     232    test03Init(myReadout);
     233    for (i=0;i<tableSize;i++) {
     234        in->data.F32[i] = (float) i;
     235        out->data.F32[i] = (float) (2 * i);
     236        inBig->data.F32[i] = (float) i;
     237        outBig->data.F32[i] = (float) (2 * i);
     238        if (i < tableSize-1) {
     239            inSmall->data.F32[i] = (float) (2 * i);
     240            outSmall->data.F32[i] = (float) (2 * i);
     241        }
     242    }
     243    inBig->data.F32[tableSize] = (float) tableSize;
     244    outBig->data.F32[tableSize] = (float) (2 * tableSize);
     245    inOne->data.F32[0] = 0.0;
     246    outOne->data.F32[0] = 0.0;
     247
     248    printf("------------------------------------------------------------\n");
     249    printf("Calling pmNonLinearityLookup() with NULL input psReadout.  Should generate error, return NULL.\n");
     250    rc = pmNonLinearityLookup(NULL, in, out);
     251    if (rc != NULL) {
     252        printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL psReadout\n");
     253        testStatus = false;
     254    }
     255
     256    printf("------------------------------------------------------------\n");
     257    printf("Calling pmNonLinearityLookup() with NULL input psReadout->image.  Should generate error, return NULL.\n");
     258    psImage *tmpImage = myReadout->image;
     259    myReadout->image = NULL;
     260    rc = pmNonLinearityLookup(myReadout, in, out);
     261    if (rc != NULL) {
     262        printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL psReadout\n");
     263        testStatus = false;
     264    }
     265    myReadout->image = tmpImage;
     266
     267    printf("------------------------------------------------------------\n");
     268    printf("Calling pmNonLinearityLookup() with NULL inFlux psVector.  Should generate error, return NULL.\n");
     269    rc = pmNonLinearityLookup(myReadout, NULL, out);
     270    if (rc != NULL) {
     271        printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL psReadout\n");
     272        testStatus = false;
     273    }
     274
     275    printf("------------------------------------------------------------\n");
     276    printf("Calling pmNonLinearityLookup() with NULL outFlux psVector.  Should generate error, return NULL.\n");
     277    rc = pmNonLinearityLookup(myReadout, in, NULL);
     278    if (rc != NULL) {
     279        printf("TEST ERROR: pmNonLinearityPolynomial() returned a non-NULL psReadout\n");
     280        testStatus = false;
     281    }
     282
     283    test03Init(myReadout);
     284    printf("------------------------------------------------------------\n");
     285    printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
     286    rc = pmNonLinearityLookup(myReadout, in, outBig);
     287    if (rc == NULL) {
     288        printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL psReadout\n");
     289        testStatus = false;
     290    }
     291    for (i=0;i<NUM_ROWS;i++) {
     292        for (j=0;j<NUM_COLS;j++) {
     293            psF32 expect = (float) (2 * (i + j));
     294            psF32 actual = rc->image->data.F32[i][j];
     295            if (FLT_EPSILON < fabs(expect - actual)) {
     296                printf("TEST ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
     297                testStatus = false;
     298            }
     299        }
     300    }
     301
     302
     303    test03Init(myReadout);
     304    printf("------------------------------------------------------------\n");
     305    printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
     306    rc = pmNonLinearityLookup(myReadout, in, outSmall);
     307    if (rc == NULL) {
     308        printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL psReadout\n");
     309        testStatus = false;
     310    }
     311
     312    test03Init(myReadout);
     313    printf("------------------------------------------------------------\n");
     314    printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
     315    rc = pmNonLinearityLookup(myReadout, inSmall, out);
     316    if (rc == NULL) {
     317        printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL psReadout\n");
     318        testStatus = false;
     319    }
     320
     321    test03Init(myReadout);
     322    printf("------------------------------------------------------------\n");
     323    printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
     324    rc = pmNonLinearityLookup(myReadout, inBig, out);
     325    if (rc == NULL) {
     326        printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL psReadout\n");
     327        testStatus = false;
     328    }
     329
     330    test03Init(myReadout);
     331    printf("------------------------------------------------------------\n");
     332    printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
     333    rc = pmNonLinearityLookup(myReadout, inSmall, outBig);
     334    if (rc == NULL) {
     335        printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL psReadout\n");
     336        testStatus = false;
     337    }
     338
     339    test03Init(myReadout);
     340    printf("------------------------------------------------------------\n");
     341    printf("Calling pmNonLinearityLookup() with size difference in inFlux/outFLux psVectors.  Should generate warning.\n");
     342    rc = pmNonLinearityLookup(myReadout, inBig, outSmall);
     343    if (rc == NULL) {
     344        printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL psReadout\n");
     345        testStatus = false;
     346    }
     347
     348    test03Init(myReadout);
     349    printf("------------------------------------------------------------\n");
     350    printf("Calling pmNonLinearityLookup() with inFlux psVector size 1.  Should generate error, return original psReadout.\n");
     351    rc = pmNonLinearityLookup(myReadout, inOne, out);
     352    if (rc != myReadout) {
     353        printf("TEST ERROR: pmNonLinearityPolynomial() did not return the original psReadout\n");
     354        testStatus = false;
     355    }
     356
     357    printf("------------------------------------------------------------\n");
     358    printf("Calling pmNonLinearityLookup() with one pixels outside inFlux range.  Should generate warnings.\n");
     359    test03Init(myReadout);
     360    myReadout->image->data.F32[0][0] = -1;
     361    rc = pmNonLinearityLookup(myReadout, in, out);
     362    if (rc == NULL) {
     363        printf("TEST ERROR: pmNonLinearityPolynomial() returned a NULL psReadout\n");
     364        testStatus = false;
     365    }
     366
     367
     368    psFree(myReadout);
     369    psFree(in);
     370    psFree(inOne);
     371    psFree(inSmall);
     372    psFree(inBig);
     373    psFree(out);
     374    psFree(outOne);
     375    psFree(outSmall);
     376    psFree(outBig);
     377
     378    return(testStatus);
     379}
Note: See TracChangeset for help on using the changeset viewer.