IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 2, 2008, 10:45:23 AM (18 years ago)
Author:
gusciora
Message:

Significant changes and additions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/test/objects/tap_pmSourceFitSet.c

    r15726 r15985  
    55#include "tap.h"
    66#include "pstap.h"
    7 // XXX: This source code file is very lighted test so far.
     7/* STATUS:
     8    All functions are tested except:
     9        pmSourceFitSetCheckLimits()
     10        pmSourceFitSetFunction()
     11    Those functions set static variables which aer invisible to test code.
     12
     13    These functions are very lightly tested and must be augmented:
     14        pmSourceFitSet()
     15        pmSourceFitSetMasks()
     16*/
    817
    918#define MISC_NUM                32
     
    1726#define NUM_MODELS              5
    1827
     28pmSource *create_pmSource() {
     29    pmSource *src = pmSourceAlloc();
     30    if (1) {
     31        src->pixels = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_F32);
     32        src->weight = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_F32);
     33        src->maskObj = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_U8);
     34        if (1) {
     35            for (int i = 0 ; i < TEST_NUM_ROWS ; i++) {
     36                for (int j = 0 ; j < TEST_NUM_COLS ; j++) {
     37                    src->pixels->data.F32[i][j] = 0.0;
     38                    src->weight->data.F32[i][j] = 1.0;
     39                    src->maskObj->data.U8[i][j] = 0;
     40                }
     41            }
     42        }
     43        if (1) {
     44            int halfRows = TEST_NUM_ROWS/2;
     45            int halfCols = TEST_NUM_COLS/2;
     46            for (int i = halfRows-1 ; i < halfRows+1 ; i++) {
     47                for (int j = halfCols-1 ; j < halfCols+1 ; j++) {
     48                    src->pixels->data.F32[i][j] = 1.0;
     49                }
     50            }
     51            src->pixels->data.F32[halfRows][halfCols] = 5.0;
     52        }
     53    }
     54    return(src);
     55}
     56
     57bool call_pmSourceFitSet() {
     58    psArray *modelSet = psArrayAlloc(NUM_MODELS);
     59    for (int i = 0 ; i < NUM_MODELS ; i++) {
     60        modelSet->data[i] = (psPtr *) pmModelAlloc(i);
     61    }
     62    pmSource *src = create_pmSource();
     63    bool rc = pmSourceFitSet(src, modelSet, PM_SOURCE_FIT_PSF, 1);
     64    if (!rc) {
     65        diag("ERROR: pmSourceFitSet() returned FALSE");
     66        return(false);
     67    }
     68    psFree(src);
     69    for (int i = 0 ; i < NUM_MODELS ; i++) {
     70        psFree(modelSet->data[i]);
     71        modelSet->data[i] = NULL;
     72    }
     73    psFree(modelSet);
     74    pmModelClassCleanup();
     75 
     76    return(true);
     77}
     78
     79
    1980int main(int argc, char* argv[])
    2081{
     
    2283    psLogSetLevel(PS_LOG_INFO);
    2384    psTraceSetLevel("err", ERR_TRACE_LEVEL);
    24     plan_tests(14);
     85    plan_tests(70);
    2586
    2687
     
    2889    // pmSourceFitSetDataAlloc() tests
    2990    // Call pmSourceFitSetDataAlloc() with NULL psArray input parameter
    30     if (1) {
     91    {
    3192        psMemId id = psMemGetId();
    3293        psArray *modelSet = psArrayAlloc(NUM_MODELS);
     
    44105
    45106    // Call pmSourceFitSetDataAlloc() with acceptable input parameters
    46     // STATUS: fully tested
    47     if (1) {
     107    {
    48108        psMemId id = psMemGetId();
    49109        psArray *modelSet = psArrayAlloc(NUM_MODELS);
     
    86146    // ----------------------------------------------------------------------
    87147    // pmSourceFitSetCheckLimits() tests
    88     // bool pmSourceFitSetCheckLimits (psMinConstraintMode mode, int nParam,
    89     //                                 float *params, float *betas)
    90148    // Call pmSourceFitSetCheckLimits() with thisSet == NULL
    91     if (1) {
     149    // XXX: Can not test full functionality of pmSourceFitSetCheckLimits() because it
     150    // requires that the static variable thisSet be allocated.
     151    {
    92152        psMemId id = psMemGetId();
    93153        #define NUM_PARAMS 10
     
    102162
    103163
    104     // Call pmSourceFitSetCheckLimits() with acceptable data
    105     // XXX: Must finish this.  Use pmSourceFitSet() to set thisSet
     164    // ----------------------------------------------------------------------
     165    // pmSourceFitSetFunction() tests
     166    // Call pmSourceFitSetFunction() with thisSet == NULL
     167    // XXX: Can not test full functionality of pmSourceFitSetCheckLimits() because it
     168    // requires that the static variable thisSet be allocated.
     169    {
     170        psMemId id = psMemGetId();
     171        #define NUM_PARAMS 10
     172        psVector *deriv = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
     173        psVector *param = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
     174        psVector *x = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
     175        psF32 tmpF = pmSourceFitSetFunction(deriv, param, x);
     176        ok(isnan(tmpF), "pmSourceFitSetFunction() returned NULL with thisSet == FALSE");
     177        psFree(deriv);
     178        psFree(param);
     179        psFree(x);
     180        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     181    }
     182
     183
     184    // ----------------------------------------------------------------------
     185    // pmSourceFitSetJoin() tests
     186    // Call pmSourceFitSetJoin() with NULL pmSourceFitSetData input parameter
     187    {
     188        psMemId id = psMemGetId();
     189        #define NUM_PARAMS 10
     190        psVector *deriv = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
     191        psVector *param = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
     192        psArray *modelSet = psArrayAlloc(NUM_MODELS);
     193        for (int i = 0 ; i < modelSet->n ; i++) {
     194            modelSet->data[i] = (psPtr *) pmModelAlloc(i);
     195        }
     196        pmSourceFitSetData *set = pmSourceFitSetDataAlloc(modelSet);
     197        bool rc = pmSourceFitSetJoin(deriv, param, NULL);
     198        ok(rc == false, "pmSourceFitSetJoin() returned FALSE with NULL pmSourceFitSetData input parameter");
     199        psFree(deriv);
     200        psFree(param);
     201        psFree(modelSet);
     202        psFree(set);
     203        pmModelClassCleanup();
     204        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     205    }
     206
     207
     208    // Call pmSourceFitSetJoin() with unequal size set->paramSet and set->derivSet input parameters
     209    {
     210        psMemId id = psMemGetId();
     211        psVector *deriv = psVectorAlloc(1000, PS_TYPE_F32);
     212        psVector *param = psVectorAlloc(1000, PS_TYPE_F32);
     213        psArray *modelSet = psArrayAlloc(NUM_MODELS);
     214        for (int i = 0 ; i < modelSet->n ; i++) {
     215            modelSet->data[i] = (psPtr *) pmModelAlloc(i);
     216        }
     217        pmSourceFitSetData *set = pmSourceFitSetDataAlloc(modelSet);
     218        psFree(set->paramSet);
     219        set->paramSet = psArrayAlloc(set->derivSet->n + 1);
     220        bool rc = pmSourceFitSetJoin(deriv, param, set);
     221        ok(rc == false, "pmSourceFitSetJoin() returned FALSE with unequal size set->paramSet and set->derivSet input parameters");
     222        psFree(deriv);
     223        psFree(param);
     224        psFree(modelSet);
     225        psFree(set);
     226        pmModelClassCleanup();
     227        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     228    }
     229
     230
     231    // Call pmSourceFitSetJoin() with deriv and param input psVector too small
     232    // XXX: Must add a PS_ASSERT to the source code to detect this
    106233    if (0) {
    107234        psMemId id = psMemGetId();
     235        psVector *small = psVectorAlloc(1, PS_TYPE_F32);
     236        psVector *big = psVectorAlloc(1000, PS_TYPE_F32);
     237        psArray *modelSet = psArrayAlloc(NUM_MODELS);
     238        for (int i = 0 ; i < modelSet->n ; i++) {
     239            modelSet->data[i] = (psPtr *) pmModelAlloc(i);
     240        }
     241        pmSourceFitSetData *set = pmSourceFitSetDataAlloc(modelSet);
     242        bool rc = pmSourceFitSetJoin(small, big, set);
     243        ok(rc == false, "pmSourceFitSetJoin() returned FALSE with deriv input psVector too small");
     244        rc = pmSourceFitSetJoin(big, small, set);
     245        ok(rc == false, "pmSourceFitSetJoin() returned FALSE with param input psVector too small");
     246        psFree(small);
     247        psFree(big);
     248        psFree(modelSet);
     249        psFree(set);
     250        pmModelClassCleanup();
     251        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     252    }
     253
     254
     255    // Call pmSourceFitSetJoin() with acceptable input parameters
     256    {
     257        psMemId id = psMemGetId();
     258        psVector *deriv = psVectorAlloc(1000, PS_TYPE_F32);
     259        psVector *param = psVectorAlloc(1000, PS_TYPE_F32);
     260        psArray *modelSet = psArrayAlloc(NUM_MODELS);
     261        for (int i = 0 ; i < modelSet->n ; i++) {
     262            modelSet->data[i] = (psPtr *) pmModelAlloc(i);
     263        }
     264        pmSourceFitSetData *set = pmSourceFitSetDataAlloc(modelSet);
     265
     266        psF32 cnt = 0.0;
     267        for (int i = 0; i < set->paramSet->n; i++) {
     268            psVector *paramOne = set->paramSet->data[i];
     269            psVector *derivOne = set->derivSet->data[i];
     270            for (int j = 0; j < paramOne->n; j++) {
     271                paramOne->data.F32[j] = cnt;
     272                derivOne->data.F32[j] = cnt;
     273                cnt = cnt + 1.0;
     274            }
     275        }
     276
     277        bool rc = pmSourceFitSetJoin(deriv, param, set);
     278        ok(rc == true, "pmSourceFitSetJoin() returned TRUE acceptable input parameters");
     279
     280        bool errorFlag = false;
     281        for (int i = 0; i < (int) cnt ; i++) {
     282            if (deriv->data.F32[i] != (float) i) {
     283                diag("ERROR: deriv->data.F32[%d] is %.2ff, should be %.2f\n", i, deriv->data.F32[i], (float) i);
     284                errorFlag = true;
     285            }
     286            if (param->data.F32[i] != (float) i) {
     287                diag("ERROR: param->data.F32[%d] is %.2ff, should be %.2f\n", i, param->data.F32[i], (float) i);
     288                errorFlag = true;
     289            }
     290        }
     291        ok(!errorFlag, "pmSourceFitSetJoin() set the deriv and param psVectors correctly");
     292
     293        psFree(deriv);
     294        psFree(param);
     295        psFree(modelSet);
     296        psFree(set);
     297        pmModelClassCleanup();
     298        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     299    }
     300
     301
     302    // ----------------------------------------------------------------------
     303    // pmSourceFitSetSplit() tests
     304    // Call pmSourceFitSetSplit() with NULL pmSourceFitSetData input parameter
     305    {
     306        psMemId id = psMemGetId();
    108307        #define NUM_PARAMS 10
    109         psF32 *params = (psF32 *) psAlloc(NUM_PARAMS * sizeof(psF32));
    110         psF32 *betas = (psF32 *) psAlloc(NUM_PARAMS * sizeof(psF32));
    111         bool rc = pmSourceFitSetCheckLimits(PS_MINIMIZE_PARAM_MIN, 10, params, betas);
    112         ok(rc == false, "pmSourceFitSetCheckLimits() returned NULL with thisSet == FALSE");
    113         psFree(params);
    114         psFree(betas);
     308        psVector *deriv = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
     309        psVector *param = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
     310        psArray *modelSet = psArrayAlloc(NUM_MODELS);
     311        for (int i = 0 ; i < modelSet->n ; i++) {
     312            modelSet->data[i] = (psPtr *) pmModelAlloc(i);
     313        }
     314        pmSourceFitSetData *set = pmSourceFitSetDataAlloc(modelSet);
     315        bool rc = pmSourceFitSetSplit(NULL, deriv, param);
     316        ok(rc == false, "pmSourceFitSetSplit() returned FALSE with NULL pmSourceFitSetData input parameter");
     317        psFree(deriv);
     318        psFree(param);
     319        psFree(modelSet);
     320        psFree(set);
     321        pmModelClassCleanup();
     322        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     323    }
     324
     325
     326    // Call pmSourceFitSetSplit() with NULL src->paramSet and src->derivSet input parameters and
     327    // src->paramSet and src->derivSet of unequal size
     328    {
     329        psMemId id = psMemGetId();
     330        #define NUM_PARAMS 10
     331        psVector *deriv = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
     332        psVector *param = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
     333        psArray *modelSet = psArrayAlloc(NUM_MODELS);
     334        for (int i = 0 ; i < modelSet->n ; i++) {
     335            modelSet->data[i] = (psPtr *) pmModelAlloc(i);
     336        }
     337        pmSourceFitSetData *set = pmSourceFitSetDataAlloc(modelSet);
     338        psArray *tmpArray = set->paramSet;
     339        set->paramSet = NULL;
     340        bool rc = pmSourceFitSetSplit(set, deriv, param);
     341        ok(rc == false, "pmSourceFitSetSplit() returned FALSE with NULL src->paramSet input parameter");
     342        set->paramSet = tmpArray;
     343
     344        tmpArray = set->derivSet;
     345        set->derivSet = NULL;
     346        rc = pmSourceFitSetSplit(set, deriv, param);
     347        ok(rc == false, "pmSourceFitSetSplit() returned FALSE with NULL src->derivSet input parameter");
     348        set->derivSet = tmpArray;
     349
     350        psFree(set->paramSet);
     351        set->paramSet = psArrayAlloc(set->derivSet->n + 1);
     352        ok(rc == false, "pmSourceFitSetSplit() returned FALSE with src->paramSet and src->derivSet of unequal size");
     353
     354        psFree(deriv);
     355        psFree(param);
     356        psFree(modelSet);
     357        psFree(set);
     358        pmModelClassCleanup();
     359        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     360    }
     361
     362
     363    // Call pmSourceFitSetSplit() with NULL param input parameter
     364    {
     365        psMemId id = psMemGetId();
     366        psVector *deriv = psVectorAlloc(1000, PS_TYPE_F32);
     367        psVector *param = psVectorAlloc(1000, PS_TYPE_F32);
     368        for (int i = 0 ; i < 1000 ; i++) {
     369            param->data.F32[i] = (float) i;
     370            deriv->data.F32[i] = (float) i;
     371        }
     372        psArray *modelSet = psArrayAlloc(NUM_MODELS);
     373        for (int i = 0 ; i < modelSet->n ; i++) {
     374            modelSet->data[i] = (psPtr *) pmModelAlloc(i);
     375        }
     376        pmSourceFitSetData *set = pmSourceFitSetDataAlloc(modelSet);
     377        bool rc = pmSourceFitSetSplit(set, deriv, NULL);
     378        ok(rc == false, "pmSourceFitSetSplit() returned FALSE with NULL param input parameter");
     379        psFree(deriv);
     380        psFree(param);
     381        psFree(modelSet);
     382        psFree(set);
     383        pmModelClassCleanup();
     384        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     385    }
     386
     387
     388    // Call pmSourceFitSetSplit() with acceptable input parameters
     389    {
     390        psMemId id = psMemGetId();
     391        psVector *deriv = psVectorAlloc(1000, PS_TYPE_F32);
     392        psVector *param = psVectorAlloc(1000, PS_TYPE_F32);
     393        for (int i = 0 ; i < 1000 ; i++) {
     394            deriv->data.F32[i] = (float) i;
     395            param->data.F32[i] = (float) i;
     396        }
     397        psArray *modelSet = psArrayAlloc(NUM_MODELS);
     398        for (int i = 0 ; i < modelSet->n ; i++) {
     399            modelSet->data[i] = (psPtr *) pmModelAlloc(i);
     400        }
     401        pmSourceFitSetData *set = pmSourceFitSetDataAlloc(modelSet);
     402        bool rc = pmSourceFitSetSplit(set, deriv, param);
     403        ok(rc == true, "pmSourceFitSetSplit() returned FALSE with acceptable input parameters");
     404
     405        bool errorFlag = false;
     406        psF32 cnt = 0.0;
     407        for (int i = 0; i < set->paramSet->n; i++) {
     408            psVector *paramOne = set->paramSet->data[i];
     409            psVector *derivOne = set->derivSet->data[i];
     410            for (int j = 0; j < paramOne->n; j++) {
     411                if (paramOne->data.F32[j] != cnt) {
     412                    diag("ERROR: paramOne->data.F32[%d] is %.2ff, should be %.2f\n", i, paramOne->data.F32[i], (float) i);
     413                    errorFlag = true;
     414                }
     415                if (derivOne->data.F32[j] != cnt) {
     416                    diag("ERROR: derivOne->data.F32[%d] is %.2ff, should be %.2f\n", i, derivOne->data.F32[i], (float) i);
     417                    errorFlag = true;
     418                }
     419                cnt = cnt + 1.0;
     420            }
     421        }
     422        ok(!errorFlag, "pmSourceFitSetSplit() set the deriv and param psVectors correctly");
     423
     424        psFree(deriv);
     425        psFree(param);
     426        psFree(modelSet);
     427        psFree(set);
     428        pmModelClassCleanup();
     429        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     430    }
     431
     432
     433    // ----------------------------------------------------------------------
     434    // pmSourceFitSetValues() tests
     435    // Call pmSourceFitSetValues() with bad input parameters
     436    {
     437        psMemId id = psMemGetId();
     438        #define VEC_SIZE 1000
     439        #define NUM_ITER 32
     440        #define TOL 0.1
     441        psVector *param = psVectorAlloc(VEC_SIZE, PS_TYPE_F32);
     442        psVector *dparam = psVectorAlloc(VEC_SIZE, PS_TYPE_F32);
     443        psArray *modelSet = psArrayAlloc(NUM_MODELS);
     444        for (int i = 0 ; i < modelSet->n ; i++) {
     445            modelSet->data[i] = (psPtr *) pmModelAlloc(i);
     446        }
     447        pmSourceFitSetData *set = pmSourceFitSetDataAlloc(modelSet);
     448        pmSource *src = create_pmSource();
     449        psMinimization *myMin = psMinimizationAlloc(NUM_ITER, TOL);
     450        int nPix = 10;
     451        bool fitStatus = true;
     452        // NULL set input parameter
     453        bool rc = pmSourceFitSetValues(NULL, dparam, param, src, myMin, nPix, fitStatus);
     454        ok(rc == false, "pmSourceFitSetValues() returned FALSE with NULL set input parameter");
     455
     456        // NULL set->paramSet
     457        psArray *tmpArray = set->paramSet;
     458        set->paramSet = NULL;
     459        rc = pmSourceFitSetValues(set, dparam, param, src, myMin, nPix, fitStatus);
     460        ok(rc == false, "pmSourceFitSetValues() returned FALSE with NULL set->paramSet");
     461        set->paramSet = tmpArray;
     462
     463        // NULL dparam input parameter
     464        rc = pmSourceFitSetValues(set, NULL, param, src, myMin, nPix, fitStatus);
     465        ok(rc == false, "pmSourceFitSetValues() returned FALSE with NULL dparam input parameter");
     466
     467        // NULL param input parameter
     468        rc = pmSourceFitSetValues(set, dparam, NULL, src, myMin, nPix, fitStatus);
     469        ok(rc == false, "pmSourceFitSetValues() returned FALSE with NULL param input parameter");
     470
     471        // NULL pmSource input parameter
     472        rc = pmSourceFitSetValues(set, dparam, param, NULL, myMin, nPix, fitStatus);
     473        ok(rc == false, "pmSourceFitSetValues() returned FALSE with NULL pmSource input parameter");
     474
     475        // NULL pmSource->pixels input parameter
     476        psImage *tmpImg = src->pixels;
     477        src->pixels = NULL;
     478        rc = pmSourceFitSetValues(set, dparam, param, src, myMin, nPix, fitStatus);
     479        ok(rc == false, "pmSourceFitSetValues() returned FALSE with NULL pmSource->pixels input parameter");
     480        src->pixels = tmpImg;
     481
     482        // NULL psMinimization input parameter
     483        rc = pmSourceFitSetValues(set, dparam, param, src, NULL, nPix, fitStatus);
     484        ok(rc == false, "pmSourceFitSetValues() returned FALSE with NULL psMinimization input parameter");
     485
     486        psFree(param);
     487        psFree(dparam);
     488        psFree(modelSet);
     489        psFree(set);
     490        psFree(src);
     491        psFree(myMin);
     492        pmModelClassCleanup();
     493        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     494    }
     495
     496
     497    // pmSourceFitSetValues() tests
     498    // Call pmSourceFitSetValues() with acceptable input parameters
     499    {
     500        psMemId id = psMemGetId();
     501        #define VEC_SIZE 1000
     502        #define NUM_ITER 32
     503        #define TOL 0.1
     504        #define MIN_VALUE       22.0
     505        #define NUM_PIX 100
     506        psVector *param = psVectorAlloc(VEC_SIZE, PS_TYPE_F32);
     507        psVector *dparam = psVectorAlloc(VEC_SIZE, PS_TYPE_F32);
     508        for (int i = 0 ; i < VEC_SIZE ; i++) {
     509            param->data.F32[i] = (float) i;
     510            dparam->data.F32[i] = (float) i;
     511        }
     512        psArray *modelSet = psArrayAlloc(NUM_MODELS);
     513        for (int i = 0 ; i < modelSet->n ; i++) {
     514            modelSet->data[i] = (psPtr *) pmModelAlloc(i);
     515        }
     516        pmSourceFitSetData *set = pmSourceFitSetDataAlloc(modelSet);
     517        pmSource *src = create_pmSource();
     518        psMinimization *myMin = psMinimizationAlloc(NUM_ITER, TOL);
     519        int nPix = NUM_PIX;
     520        bool fitStatus = true;
     521
     522        bool rc = pmSourceFitSetValues(set, dparam, param, src, myMin, nPix, fitStatus);
     523        ok(rc == true, "pmSourceFitSetValues() returned TRUE with acceptable input paramaters");
     524
     525        bool errorFlag = false;
     526        psF32 cnt = 0.0;
     527        for (int i = 0; i < set->paramSet->n; i++) {
     528            pmModel *model = set->modelSet->data[i];
     529            for (int j = 0; j < model->params->n; j++) {
     530                if (model->params->data.F32[j] != cnt) {
     531                    diag("ERROR: model->params->data.F32[%d] is %.2ff, should be %.2f\n", i, model->params->data.F32[i], (float) i);
     532                    errorFlag = true;
     533                }
     534                if (model->dparams->data.F32[j] != cnt) {
     535                    diag("ERROR: model->dparams->data.F32[%d] is %.2ff, should be %.2f\n", i, model->dparams->data.F32[i], (float) i);
     536                    errorFlag = true;
     537                }
     538                if (model->chisq != myMin->value) {
     539                    diag("ERROR: model->chisq is %.2f, should be %.2f", model->chisq, MIN_VALUE);
     540                    errorFlag = true;
     541                }
     542                if (model->nIter != myMin->iter) {
     543                    diag("ERROR: model->nIter is %.2f, should be %.2f", model->nIter, NUM_ITER);
     544                    errorFlag = true;
     545                }
     546                if (model->nDOF != NUM_PIX - model->params->n) {
     547                    diag("ERROR: model->nDOF is %d, should be %d", model->nDOF, NUM_PIX-model->params->n);
     548                    errorFlag = true;
     549                }
     550
     551                cnt = cnt + 1.0;
     552            }
     553        }
     554        ok(!errorFlag, "pmSourceFitSetValues() set the deriv and param psVectors correctly");
     555
     556        psFree(param);
     557        psFree(dparam);
     558        psFree(modelSet);
     559        psFree(set);
     560        psFree(src);
     561        psFree(myMin);
     562        pmModelClassCleanup();
     563        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     564    }
     565
     566
     567
     568    // ----------------------------------------------------------------------
     569    // pmSourceFitSetMasks() tests
     570    // Call pmSourceFitSetMasks() with bad input parameters
     571    {
     572        psMemId id = psMemGetId();
     573        #define VEC_SIZE 1000
     574        #define NUM_ITER 32
     575        #define TOL 0.1
     576        psArray *modelSet = psArrayAlloc(NUM_MODELS);
     577        for (int i = 0 ; i < modelSet->n ; i++) {
     578            modelSet->data[i] = (psPtr *) pmModelAlloc(i);
     579        }
     580        pmSourceFitSetData *set = pmSourceFitSetDataAlloc(modelSet);
     581        psMinConstraint *constraint = psMinConstraintAlloc();
     582
     583        // NULL psMinConstraint input parameter
     584        bool rc = pmSourceFitSetMasks(NULL, set, PM_SOURCE_FIT_NORM);
     585        ok(rc == false, "pmSourceFitSetMasks() returned TRUE with NULL psMinConstraint input parameter");
     586
     587        // NULL pmSourceFitSetData input parameter
     588        rc = pmSourceFitSetMasks(constraint, NULL, PM_SOURCE_FIT_NORM);
     589        ok(rc == false, "pmSourceFitSetMasks() returned TRUE with NULL pmSourceFitSetData input parameter");
     590
     591        psFree(modelSet);
     592        psFree(set);
     593        psFree(constraint);
     594        pmModelClassCleanup();
     595        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     596    }
     597
     598
     599    // Call pmSourceFitSetMasks() with acceptable input parameters
     600    // For thoroughness, we should test the PM_SOURCE_FIT_PSF and PM_SOURCE_FIT_EXT mode
     601    {
     602        psMemId id = psMemGetId();
     603        #define VEC_SIZE 1000
     604        #define NUM_ITER 32
     605        #define TOL 0.1
     606        psArray *modelSet = psArrayAlloc(NUM_MODELS);
     607        for (int i = 0 ; i < modelSet->n ; i++) {
     608            modelSet->data[i] = (psPtr *) pmModelAlloc(i);
     609        }
     610        pmSourceFitSetData *set = pmSourceFitSetDataAlloc(modelSet);
     611        psMinConstraint *constraint = psMinConstraintAlloc();
     612        constraint->paramMask = psVectorAlloc(1000, PS_TYPE_F32);
     613
     614        // Acceptable input parameters
     615        bool rc = pmSourceFitSetMasks(constraint, set, PM_SOURCE_FIT_NORM);
     616        ok(rc == true, "pmSourceFitSetMasks() returned TRUE with acceptable input parameters");
     617
     618        bool errorFlag = false;
     619        int n = 0;
     620        for (int i = 0; i < set->paramSet->n; i++) {
     621            psVector *paramOne = set->paramSet->data[i];
     622            for (int j = 0; j < paramOne->n; j++) {
     623                if (j == PM_PAR_I0) continue;
     624                if (constraint->paramMask->data.U8[n + j] != 1) {
     625                    diag("ERROR: constraint->paramMask->data.U8[%d] is %d, should be a",
     626                          n + j, constraint->paramMask->data.U8[n + j]);
     627                    errorFlag = true;
     628                }
     629            }
     630            n += paramOne->n;
     631        }
     632        ok(!errorFlag, "pmSourceFitSetMasks() constraint->paramMask psVector correctly");
     633
     634        psFree(modelSet);
     635        psFree(set);
     636        psFree(constraint);
     637        pmModelClassCleanup();
    115638        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    116639    }
     
    119642    // ----------------------------------------------------------------------
    120643    // pmSourceFitSet() tests
    121     // bool pmSourceFitSet (pmSource *source, psArray *modelSet,
    122     //                 pmSourceFitMode mode, psMaskType maskVal)
    123     // Call pmSourceFitSet() with thisSet == NULL
     644    // Call pmSourceFitSet() with NULL psSource input parameter
     645    {
     646        psMemId id = psMemGetId();
     647        psArray *modelSet = psArrayAlloc(NUM_MODELS);
     648        for (int i = 0 ; i < NUM_MODELS ; i++) {
     649            modelSet->data[i] = (psPtr *) pmModelAlloc(i);
     650        }
     651        pmSource *src = create_pmSource();
     652        bool rc = pmSourceFitSet(NULL, modelSet, PM_SOURCE_FIT_PSF, 1);
     653        ok(rc == false, "pmSourceFitSet() returned FALSE with NULL psSource input parameter");
     654        psFree(src);
     655        for (int i = 0 ; i < NUM_MODELS ; i++) {
     656            psFree(modelSet->data[i]);
     657            modelSet->data[i] = NULL;
     658        }
     659        psFree(modelSet);
     660        pmModelClassCleanup();
     661        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     662    }
     663
     664
     665    // Call pmSourceFitSet() with NULL psSource pixels, weight, maskObj input parameters
     666    {
     667        psMemId id = psMemGetId();
     668        psArray *modelSet = psArrayAlloc(NUM_MODELS);
     669        for (int i = 0 ; i < NUM_MODELS ; i++) {
     670            modelSet->data[i] = (psPtr *) pmModelAlloc(i);
     671        }
     672        pmSource *src = create_pmSource();
     673        psImage *tmpImg = src->pixels;
     674        src->pixels = NULL;
     675        bool rc = pmSourceFitSet(src, modelSet, PM_SOURCE_FIT_PSF, 1);
     676        ok(rc == false, "pmSourceFitSet() returned FALSE with NULL src->pixels input parameter");
     677        src->pixels = tmpImg;
     678
     679        tmpImg = src->weight;
     680        src->weight = NULL;
     681        rc = pmSourceFitSet(src, modelSet, PM_SOURCE_FIT_PSF, 1);
     682        ok(rc == false, "pmSourceFitSet() returned FALSE with NULL src->weight input parameter");
     683        src->weight = tmpImg;
     684
     685        tmpImg = src->maskObj;
     686        src->maskObj = NULL;
     687        rc = pmSourceFitSet(src, modelSet, PM_SOURCE_FIT_PSF, 1);
     688        ok(rc == false, "pmSourceFitSet() returned FALSE with NULL src->maskObj input parameter");
     689        src->maskObj = tmpImg;
     690        psFree(src);
     691        for (int i = 0 ; i < NUM_MODELS ; i++) {
     692            psFree(modelSet->data[i]);
     693            modelSet->data[i] = NULL;
     694        }
     695        psFree(modelSet);
     696        pmModelClassCleanup();
     697        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     698    }
     699
     700
     701    // Call pmSourceFitSet() with acceptable input parameters
     702    // This is a verly limited test.  It only uses a simple object in the pmSource
     703    // parameter and simply tests that pmSourceFitSet() returns teh correct type and mode.
     704    // Must add more extensive input types.
    124705    if (1) {
    125706        psMemId id = psMemGetId();
    126         #define NUM_PARAMS 10
    127         pmSource *src = pmSourceAlloc();
    128         src->pixels = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_F32);
    129         src->weight = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_F32);
    130         src->maskObj = psImageAlloc(TEST_NUM_COLS, TEST_NUM_ROWS, PS_TYPE_U8);
    131         psArray *set = psArrayAlloc(NUM_MODELS);
    132         for (int i = 0 ; i < set->n ; i++) {
    133             set->data[i] = (psPtr *) pmModelAlloc(i);
    134         }
    135         bool rc = pmSourceFitSet(src, set, PM_SOURCE_FIT_PSF, 1);
    136         ok(rc == false, "pmSourceFitSet() returned NULL with thisSet == FALSE");
     707        psArray *modelSet = psArrayAlloc(NUM_MODELS);
     708        for (int i = 0 ; i < NUM_MODELS ; i++) {
     709            modelSet->data[i] = (psPtr *) pmModelAlloc(i);
     710        }
     711        pmSource *src = create_pmSource();
     712        bool rc = pmSourceFitSet(src, modelSet, PM_SOURCE_FIT_PSF, 1);
     713        ok(rc == true, "pmSourceFitSet() returned TRUE with acceptable parameters");
     714        ok(src->mode & PM_SOURCE_MODE_FITTED, "pmSourceFitSet() set source->mode |= PM_SOURCE_MODE_FITTED (%d)", src->mode);
     715        ok(src->type == PM_SOURCE_TYPE_UNKNOWN, "pmSourceFitSet() set source->type correctly (%d)", src->type);
     716
    137717        psFree(src);
    138         psFree(set);
    139         ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
    140     }
    141 
     718        for (int i = 0 ; i < NUM_MODELS ; i++) {
     719            psFree(modelSet->data[i]);
     720            modelSet->data[i] = NULL;
     721        }
     722        psFree(modelSet);
     723        pmModelClassCleanup();
     724        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
     725    }
    142726}
Note: See TracChangeset for help on using the changeset viewer.