IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 42336 for trunk/psLib/test


Ignore:
Timestamp:
Jan 30, 2023, 9:51:20 AM (3 years ago)
Author:
eugene
Message:

merge from branches/eam_branches/psLib.20230123: rework of psSpline (cleaner names, do not convert to generic polynomials, allow defined 1st deriv or 0.0 2nd deriv for boundary conditions)

Location:
trunk/psLib
Files:
2 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/psLib

  • trunk/psLib/test/math/tap_psSpline1D.c

    r13124 r42336  
    1 /* @file  tst_psImageManip.c
    2 *
    3 *  @brief This file will contain tests for all of the public psLib functions
     1/* @file  tap_psImageManip.c
     2*
     3*  @brief This file contains tests for all of the public psLib functions
    44*         that implement 1-D spline functionality:
    55* psSpline1DAlloc()
    66* psSpline1DEval()
    77* psSpline1DEvalVector()
    8 * psVectorFitSpline1D()
     8* psSpline1DFitVector()
    99*
    1010*         This file is composed of the tests formerly in tst_psFunc02.c,
     
    3535    psF32 expect)
    3636{
     37    // NOTE: this returns NAN if 'expect' == 0.0
     38    // NOTE 2: this is not testing a percent, but fractional error
    3739    if ((fabs(actual - expect) / fabs(expect)) > ERROR_TOLERANCE_PERCENT) {
    3840        return(true);
     
    8385typedef psF64 (*mappingFuncF64)(psF64 x);
    8486
     87/* EAM 2023.01.22 : these tests are not well considered.  They generate a set of N+1 points
     88   to use as knots at integer values from 0 to N, then evaluate the spline half-way between
     89   the knots.   the function above is a cubic, so a cubic spline should fit it perfectly, which
     90   is fine.  Perhaps this test suite should use a pre-defined collection of data points?
     91 */
     92
    8593bool genericF32Test(psS32 NumSplines, mappingFuncF32 func, bool xNull)
    8694{
    87     // We test the psVectorFitSpline1D, psSpline1DEval() functions.  F32 version.
     95    // We test the psSpline1DFitVector, psSpline1DEval() functions.  F32 version.
    8896    bool testStatus = true;
    8997    {
     98        // Generate the vector data
    9099        psMemId id = psMemGetId();
    91100        psVector *xF32 = psVectorAlloc(NumSplines+1, PS_TYPE_F32);
     
    98107        psSpline1D *tmpSpline = NULL;
    99108        if (!xNull) {
    100             tmpSpline = psVectorFitSpline1D(xF32, yF32);
     109            tmpSpline = psSpline1DFitVector(xF32, yF32);
    101110        } else {
    102             tmpSpline = psVectorFitSpline1D(NULL, yF32);
    103         }
     111            tmpSpline = psSpline1DFitVector(NULL, yF32);
     112        }
     113
    104114        if(tmpSpline == NULL) {
    105             diag("psVectorFitSpline1D() returned NULL");
     115            diag("psSpline1DFitVector() returned NULL");
    106116            testStatus = false;
    107117        } else {
    108118            if (tmpSpline->n != NumSplines) {
    109                 diag("psVectorFitSpline1D() did not properly set the psSpline1D->n member");
     119                diag("psSpline1DFitVector() did not properly set the psSpline1D->n member");
    110120                testStatus = false;
    111121            }
    112122            if(tmpSpline->spline == NULL) {
    113                 diag("psVectorFitSpline1D() returned a NULL psSpline1D->spline member.");
     123                diag("psSpline1DFitVector() returned a NULL psSpline1D->spline member.");
    114124                testStatus = false;
    115125            }
    116126            for (psS32 i = 0 ; i < NumSplines ; i++) {
    117127                if (tmpSpline->spline[i] == NULL) {
    118                     diag("psVectorFitSpline1D() returned a NULL psSpline1D->spline[%d] member.", i);
     128                    diag("psSpline1DFitVector() returned a NULL psSpline1D->spline[%d] member.", i);
    119129                    testStatus = false;
    120130                }
    121131            }
    122132            if (tmpSpline->knots == NULL) {
    123                 diag("psVectorFitSpline1D() returned a NULL psSpline1D->knots member");
     133                diag("psSpline1DFitVector() returned a NULL psSpline1D->knots member");
    124134                testStatus = false;
    125135            }
    126136            if (tmpSpline->p_psDeriv2 == NULL) {
    127                 diag("psVectorFitSpline1D()returned a NULL psSpline1D->p_psDeriv2 member");
     137                diag("psSpline1DFitVector()returned a NULL psSpline1D->p_psDeriv2 member");
    128138                testStatus = false;
    129139            }
     
    136146                    testStatus = false;
    137147                    diag("TEST ERROR: f(%f) is %f, should be %f", x, y, myFunc00(x));
     148                    // XXX EAM : the truth value above should be 'func' not myFunc00
    138149                }
    139150            }
     
    150161                        diag("TEST ERROR: f(%f) is %f, should be %f", xF32->data.F32[i],
    151162                             yF32Test->data.F32[i], myFunc00(xF32->data.F32[i]));
     163                    // XXX EAM : the truth value above should be 'func' not myFunc00
    152164                    }
    153165                }
     
    171183bool genericF64Test(psS32 NumSplines, mappingFuncF64 func, bool xNull)
    172184{
    173     // We test the psVectorFitSpline1D, psSpline1DEval() functions.  F64 version.
     185    // We test the psSpline1DFitVector, psSpline1DEval() functions.  F64 version.
    174186    bool testStatus = true;
    175187    {
     
    184196        psSpline1D *tmpSpline = NULL;
    185197        if (!xNull) {
    186             tmpSpline = psVectorFitSpline1D(xF64, yF64);
     198            tmpSpline = psSpline1DFitVector(xF64, yF64);
    187199        } else {
    188             tmpSpline = psVectorFitSpline1D(NULL, yF64);
     200            tmpSpline = psSpline1DFitVector(NULL, yF64);
    189201        }
    190202        if(tmpSpline == NULL) {
    191             diag("psVectorFitSpline1D() returned NULL");
     203            diag("psSpline1DFitVector() returned NULL");
    192204            testStatus = false;
    193205        } else {
    194206            if (tmpSpline->n != NumSplines) {
    195                 diag("psVectorFitSpline1D() did not properly set the psSpline1D->n member");
     207                diag("psSpline1DFitVector() did not properly set the psSpline1D->n member");
    196208                testStatus = false;
    197209            }
    198210            if(tmpSpline->spline == NULL) {
    199                 diag("psVectorFitSpline1D() returned a NULL psSpline1D->spline member.");
     211                diag("psSpline1DFitVector() returned a NULL psSpline1D->spline member.");
    200212                testStatus = false;
    201213            }
    202214            for (psS32 i = 0 ; i < NumSplines ; i++) {
    203215                if (tmpSpline->spline[i] == NULL) {
    204                     diag("psVectorFitSpline1D() returned a NULL psSpline1D->spline[%d] member.", i);
     216                    diag("psSpline1DFitVector() returned a NULL psSpline1D->spline[%d] member.", i);
    205217                    testStatus = false;
    206218                }
    207219            }
    208220            if (tmpSpline->knots == NULL) {
    209                 diag("psVectorFitSpline1D() returned a NULL psSpline1D->knots member");
     221                diag("psSpline1DFitVector() returned a NULL psSpline1D->knots member");
    210222                testStatus = false;
    211223            }
    212224            if (tmpSpline->p_psDeriv2 == NULL) {
    213                 diag("psVectorFitSpline1D()returned a NULL psSpline1D->p_psDeriv2 member");
     225                diag("psSpline1DFitVector()returned a NULL psSpline1D->p_psDeriv2 member");
    214226                testStatus = false;
    215227            }
     
    274286    }
    275287
    276     // psSplineEvalTest_sub(): Call psVectorFitSpline1D with NULL arguments.
    277     {
    278         psMemId id = psMemGetId();
    279         psSpline1D *tmpSpline = psVectorFitSpline1D(NULL, NULL);
    280         ok(tmpSpline == NULL, "psVectorFitSpline1D() returns NULL with NULL arguments");
     288    // psSplineEvalTest_sub(): Call psSpline1DFitVector with NULL arguments.
     289    {
     290        psMemId id = psMemGetId();
     291        psSpline1D *tmpSpline = psSpline1DFitVector(NULL, NULL);
     292        ok(tmpSpline == NULL, "psSpline1DFitVector() returns NULL with NULL arguments");
    281293        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    282294    }
     
    287299        psMemId id = psMemGetId();
    288300        float y = psSpline1DEval(NULL, 0.0);
    289         ok(isnan(y), "psSpline1DEval() returned NAN will NULL input spline");
     301        ok(isnan(y), "psSpline1DEval() returned NAN with NULL input spline");
    290302        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    291303    }
     
    297309        psVector *x = psVectorAlloc(10, PS_TYPE_F32);
    298310        psVector *y = psSpline1DEvalVector(NULL, x);
    299         ok(y == NULL, "psSpline1DEvalVector() returned NAN will NULL input spline");
     311        ok(y == NULL, "psSpline1DEvalVector() returned NULL with NULL input spline");
    300312        psFree(x);
    301313        psFree(y);
     
    316328        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    317329    }
    318 
    319330
    320331    ok(genericF32Test(1, myFunc00, false), "Generic, simple mapping, F32 test. 1 spline");
Note: See TracChangeset for help on using the changeset viewer.