IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 6, 2004, 1:29:16 PM (22 years ago)
Author:
gusciora
Message:

Tests for NULL paramaters in the MinimizePowell functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/dataManip/tst_psMinimize05.c

    r1810 r1991  
    11/*****************************************************************************
    22    This routine must ensure that psMinimizePowell() works correctly.
     3 
     4    We test with a NULL and non-NULL paramMask.
     5 
     6    XXX: Must verify the stderr for the NULL parameter tests.
    37 *****************************************************************************/
    48#include <stdio.h>
     
    913#define MIN_VALUE 20.0
    1014#define NUM_PARAMS 10
     15#define ERROR_TOLERANCE 0.10
    1116float expectedParm[NUM_PARAMS];
    1217int testStatus = true;
     
    5762
    5863
    59 int main()
     64int t00()
    6065{
    6166    int currentId = psMemGetId();
     
    8691    }
    8792
    88     psMinimizePowell(min, myParams, myParamMask, myCoords, (psMinimizePowellFunc) myFunc);
     93    printPositiveTestHeader(stdout,
     94                            "psMinimize functions",
     95                            "psMinimizePowell()");
     96
     97    psMinimizePowell(min,
     98                     myParams,
     99                     myParamMask,
     100                     myCoords,
     101                     (psMinimizePowellFunc) myFunc);
     102
    89103    printf("\nThe minimum is %f (expected: %f)\n", min->value, MIN_VALUE);
     104
    90105    for (i=0;i<NUM_PARAMS;i++) {
    91106        printf("Parameter %d at the minimum is %f (expected: %f)\n", i,
    92107               myParams->data.F32[i], expectedParm[i]);
    93     }
     108
     109        if (fabs(myParams->data.F32[i] - expectedParm[i]) > fabs(ERROR_TOLERANCE * expectedParm[i])) {
     110            printf("ERROR: Parameter %d: (%.1f), expected was (%.1f)\n",
     111                   i, myParams->data.F32[i], expectedParm[i]);
     112            testStatus = false;
     113        } else {
     114            printf("Parameter %d: (%.1f), expected was (%.1f)\n",
     115                   i, myParams->data.F32[i], expectedParm[i]);
     116        }
     117    }
     118
    94119
    95120    psFree(myCoords);
     
    103128        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
    104129    }
     130    printFooter(stdout,
     131                "psMinimize functions",
     132                "psMinimizePowell()",
     133                testStatus);
     134
     135
    105136    return (!testStatus);
    106137}
     138
     139int t01()
     140{
     141    int currentId = psMemGetId();
     142    int memLeaks = 0;
     143    int i = 0;
     144    psArray *myCoords;
     145    psVector *myParams;
     146    psMinimization *min;
     147
     148    psTraceSetLevel(".psLib", 0);
     149    /**************************************************************************
     150     *************************************************************************/
     151    myParams = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
     152    min = psMinimizationAlloc(100, 0.01);
     153
     154    myCoords = psArrayAlloc(N);
     155    for (i=0;i<N;i++) {
     156        myCoords->data[i] = (psPTR *) psVectorAlloc(2, PS_TYPE_F32);
     157        ((psVector *) (myCoords->data[i]))->data.F32[0] = (float) (i+10);
     158        ((psVector *) (myCoords->data[i]))->data.F32[1] = (float) (i+3);
     159    }
     160    for (i=0;i<NUM_PARAMS;i++) {
     161        expectedParm[i] = 2.32 + (float) (2 * i);
     162        myParams->data.F32[i] = 0.0;
     163    }
     164
     165    printPositiveTestHeader(stdout,
     166                            "psMinimize functions",
     167                            "psMinimizePowell()");
     168
     169    psMinimizePowell(min,
     170                     myParams,
     171                     NULL,
     172                     myCoords,
     173                     (psMinimizePowellFunc) myFunc);
     174
     175    printf("\nThe minimum is %f (expected: %f)\n", min->value, MIN_VALUE);
     176
     177    for (i=0;i<NUM_PARAMS;i++) {
     178        printf("Parameter %d at the minimum is %f (expected: %f)\n", i,
     179               myParams->data.F32[i], expectedParm[i]);
     180
     181        if (fabs(myParams->data.F32[i] - expectedParm[i]) > fabs(ERROR_TOLERANCE * expectedParm[i])) {
     182            printf("ERROR: Parameter %d: (%.1f), expected was (%.1f)\n",
     183                   i, myParams->data.F32[i], expectedParm[i]);
     184            testStatus = false;
     185        } else {
     186            printf("Parameter %d: (%.1f), expected was (%.1f)\n",
     187                   i, myParams->data.F32[i], expectedParm[i]);
     188        }
     189    }
     190
     191
     192    psFree(myCoords);
     193    psFree(myParams);
     194    psFree(min);
     195
     196    psMemCheckCorruption(1);
     197    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
     198    if (0 != memLeaks) {
     199        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
     200    }
     201    printFooter(stdout,
     202                "psMinimize functions",
     203                "psMinimizePowell()",
     204                testStatus);
     205
     206
     207    return (!testStatus);
     208}
     209
     210int t02()
     211{
     212    int currentId = psMemGetId();
     213    int memLeaks = 0;
     214    int i = 0;
     215    psArray *myCoords;
     216    psVector *myParams;
     217    psVector *myParamMask;
     218    psMinimization *min;
     219
     220    psTraceSetLevel(".psLib", 0);
     221    /**************************************************************************
     222     *************************************************************************/
     223    myParams = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
     224    myParamMask = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
     225    min = psMinimizationAlloc(100, 0.01);
     226
     227    myCoords = psArrayAlloc(N);
     228    for (i=0;i<N;i++) {
     229        myCoords->data[i] = (psPTR *) psVectorAlloc(2, PS_TYPE_F32);
     230        ((psVector *) (myCoords->data[i]))->data.F32[0] = (float) (i+10);
     231        ((psVector *) (myCoords->data[i]))->data.F32[1] = (float) (i+3);
     232    }
     233    for (i=0;i<NUM_PARAMS;i++) {
     234        expectedParm[i] = 2.32 + (float) (2 * i);
     235        myParams->data.F32[i] = 0.0;
     236        myParamMask->data.U8[i] = 0;
     237    }
     238
     239    printPositiveTestHeader(stdout,
     240                            "psMinimize functions",
     241                            "psMinimizePowell(): various NULL inputs");
     242
     243    psMinimizePowell(NULL, myParams, myParamMask, myCoords, (psMinimizePowellFunc) myFunc);
     244    psMinimizePowell(min, NULL, myParamMask, myCoords,(psMinimizePowellFunc) myFunc);
     245    psMinimizePowell(min, myParams, myParamMask, NULL, (psMinimizePowellFunc) myFunc);
     246    psMinimizePowell(min, myParams, myParamMask, myCoords, NULL);
     247
     248    psFree(myCoords);
     249    psFree(myParams);
     250    psFree(myParamMask);
     251    psFree(min);
     252
     253    psMemCheckCorruption(1);
     254    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
     255    if (0 != memLeaks) {
     256        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
     257    }
     258    printFooter(stdout,
     259                "psMinimize functions",
     260                "psMinimizePowell(): various NULL inputs",
     261                testStatus);
     262
     263
     264    return (!testStatus);
     265}
     266
     267int main()
     268{
     269    t00();
     270    t01();
     271    t02();
     272}
Note: See TracChangeset for help on using the changeset viewer.