IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5822


Ignore:
Timestamp:
Dec 20, 2005, 2:10:44 PM (21 years ago)
Author:
gusciora
Message:

More testing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/math/tst_psPolyFit3DOrd.c

    r5820 r5822  
    3131#define VERBOSE 0
    3232
    33 psF64 setDataF32(psF64 x, psF64 y, psF64 z)
     33psF32 setDataF32(psF32 x, psF32 y, psF32 z)
    3434{
    3535    if (0) {
     
    4242}
    4343
    44 psS32 t00()
     44psF64 setDataF64(psF64 x, psF64 y, psF64 z)
     45{
     46    if (0) {
     47        // Linear case, for testing.
     48        return(A + (B * x) + (D * y) + (H * z));
     49    } else {
     50        return(A + (B * x) + (C * x * x) + (D * y) + (E * y * y) + (F * x * y) + (H * z) +
     51               (J * z * z) + (K * x * z) + (L * y * z));
     52    }
     53}
     54
     55psS32 t00F32()
    4556{
    4657    psS32 currentId = psMemGetId();
     
    5869
    5970    for (psS32 i=0;i<NUM_DATA;i++) {
    60         x->data.F32[i] = (psF64) i;
    61         y->data.F32[i] = (psF64) i;
    62         z->data.F32[i] = (psF64) i;
     71        x->data.F32[i] = (psF32) i;
     72        y->data.F32[i] = (psF32) i;
     73        z->data.F32[i] = (psF32) i;
    6374        f->data.F32[i] = setDataF32(x->data.F32[i], y->data.F32[i], z->data.F32[i]);
    6475        fErr->data.F32[i] = FERR;
     
    6778    printPositiveTestHeader(stdout,
    6879                            "psMinimize functions",
    69                             "psVectorFitPolynomial3D(): equal difference in variable fErr");
     80                            "psVectorFitPolynomial3D(): psF32 data");
    7081
    7182    psVectorFitPolynomial3D(myPoly, NULL, 0, f, fErr, x, y, z);
     
    94105    }
    95106
    96     if (0) {
     107    if (1) {
    97108        printf("Running test with fErr set to NULL.\n");
    98109        psVectorFitPolynomial3D(myPoly, NULL, 0, f, NULL, x, y, z);
     
    106117            }
    107118            if (VERBOSE) {
    108                 printf("Data point [%d] is %f, should be %f.\n", i, actualData, expectData);
    109             }
    110         }
    111         printf("Running test with x, y set to NULL.  Should generate error.\n");
     119                printf("GOOD: Data point [%d] is %f, should be %f.\n", i, actualData, expectData);
     120            }
     121        }
     122    }
     123
     124    if (1) {
     125        psFree(myPoly);
     126        printf("Running test with myPoly set to NULL.  Should generate error.\n");
    112127        myPoly = psVectorFitPolynomial3D(NULL, NULL, 0, f, fErr, NULL, NULL, NULL);
    113128        if (myPoly != NULL) {
     
    138153}
    139154
     155
     156psS32 t00F64()
     157{
     158    psS32 currentId = psMemGetId();
     159    psS32 testStatus = true;
     160    psS32 memLeaks = 0;
     161    psF64 expectData;
     162    psF64 actualData;
     163
     164    psPolynomial3D *myPoly = psPolynomial3DAlloc(POLY_ORDER, POLY_ORDER, POLY_ORDER, PS_POLYNOMIAL_ORD);
     165    psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
     166    psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
     167    psVector *z = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
     168    psVector *f = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
     169    psVector *fErr = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
     170
     171    for (psS32 i=0;i<NUM_DATA;i++) {
     172        x->data.F64[i] = (psF64) i;
     173        y->data.F64[i] = (psF64) i;
     174        z->data.F64[i] = (psF64) i;
     175        f->data.F64[i] = setDataF64(x->data.F64[i], y->data.F64[i], z->data.F64[i]);
     176        fErr->data.F64[i] = FERR;
     177    }
     178
     179    printPositiveTestHeader(stdout,
     180                            "psMinimize functions",
     181                            "psVectorFitPolynomial3D(): psF64 data");
     182
     183    psVectorFitPolynomial3D(myPoly, NULL, 0, f, fErr, x, y, z);
     184
     185    if (VERBOSE) {
     186        for (psS32 i=0;i<POLY_ORDER+1;i++) {
     187            for (psS32 j=0;j<POLY_ORDER+1;j++) {
     188                for (psS32 k=0;k<POLY_ORDER+1;k++) {
     189                    printf("Polynomial coefficient %d is %0.1f\n", i, myPoly->coeff[i][j][k]);
     190                }
     191            }
     192        }
     193    }
     194
     195    for (psS32 i=0;i<NUM_DATA;i++) {
     196        expectData = setDataF64(x->data.F64[i],  y->data.F64[i], z->data.F64[i]);
     197        actualData = psPolynomial3DEval(myPoly, x->data.F64[i], y->data.F64[i], z->data.F64[i]);
     198        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
     199            printf("TEST ERROR: Fitted data %d: (%.1f %.1f %.1f), expected was (%.1f)\n",
     200                   i, x->data.F64[i], y->data.F64[i], actualData, expectData);
     201            testStatus = false;
     202        }
     203        if (VERBOSE) {
     204            printf("GOOD: Data point [%d] is %f, should be %f.\n", i, actualData, expectData);
     205        }
     206    }
     207
     208    if (1) {
     209        printf("Running test with fErr set to NULL.\n");
     210        psVectorFitPolynomial3D(myPoly, NULL, 0, f, NULL, x, y, z);
     211        for (psS32 i=0;i<NUM_DATA;i++) {
     212            expectData = setDataF64(x->data.F64[i],  y->data.F64[i], z->data.F64[i]);
     213            actualData = psPolynomial3DEval(myPoly, x->data.F64[i], y->data.F64[i], z->data.F64[i]);
     214            if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
     215                printf("TEST ERROR: Fitted data %d: (%.1f %.1f %.1f), expected was (%.1f)\n",
     216                       i, x->data.F64[i], y->data.F64[i], actualData, expectData);
     217                testStatus = false;
     218            }
     219            if (VERBOSE) {
     220                printf("GOOD: Data point [%d] is %f, should be %f.\n", i, actualData, expectData);
     221            }
     222        }
     223    }
     224
     225    if (1) {
     226        psFree(myPoly);
     227        printf("Running test with myPoly set to NULL.  Should generate error.\n");
     228        myPoly = psVectorFitPolynomial3D(NULL, NULL, 0, f, fErr, NULL, NULL, NULL);
     229        if (myPoly != NULL) {
     230            printf("TEST ERROR: psVectorFitPolynomial3D() returned non-NULL.\n");
     231            testStatus = false;
     232        }
     233    }
     234
     235    psMemCheckCorruption(1);
     236    psFree(myPoly);
     237    psFree(x);
     238    psFree(y);
     239    psFree(z);
     240    psFree(f);
     241    psFree(fErr);
     242    psMemCheckCorruption(1);
     243    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
     244    if (0 != memLeaks) {
     245        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
     246    }
     247
     248    printFooter(stdout,
     249                "psMinimize functions",
     250                "psVectorFitPolynomial3D(): equal differences in variable fErr",
     251                testStatus);
     252
     253    return (!testStatus);
     254}
     255
    140256psS32 main()
    141257{
    142258    psLogSetFormat("HLNM");
    143     t00();
    144 }
     259    t00F32();
     260    t00F64();
     261}
Note: See TracChangeset for help on using the changeset viewer.