IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 6307


Ignore:
Timestamp:
Feb 2, 2006, 12:15:21 PM (20 years ago)
Author:
gusciora
Message:

This test was completely rewritten.

Location:
trunk/psLib/test/math
Files:
2 edited

Legend:

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

    r6304 r6307  
    44    psVectorStats().
    55 
    6     XXX: Must add tests for various data types, other than psF32.  Copy code
    7     from tst_psStats00.c-tst_psStats02.c.
     6    XXX: The capability is here to test a wide variety of input parameters.
     7    We must do this, later.
    88 *****************************************************************************/
    99#include <stdio.h>
    1010#include "pslib_strict.h"
    1111#include "psTest.h"
    12 #include "psTest.h"
    13 #include "psImageStats.h"
    1412#include "float.h"
    1513#include <math.h>
    1614
    17 #define N 500
    18 #define MY_MEAN  30.0
    19 #define MY_RANGE 2.0
    20 #define VERBOSE 1
    21 
    22 #define TST_IN_NULL  0x00000000
    23 #define TST_IN_F32  0x00000000
    24 #define TST_IN_F64  0x00000000
    25 #define TST_IN_S8  0x00000000
    26 #define TST_IN_U16  0x00000000
    27 #define TST_IN_S32  0x00000000
    28 #define TST_ERRORS_NULL  0x00000000
    29 #define TST_ERRORS_F32  0x00000000
    30 #define TST_ERRORS_F64  0x00000000
    31 #define TST_ERRORS_S8  0x00000000
    32 #define TST_ERRORS_U16  0x00000000
    33 #define TST_ERRORS_S32  0x00000000
    34 #define TST_MASK_NULL  0x00000000
    35 #define TST_MASK_U8  0x00000000
    36 #define TST_MASK_S32  0x00000000
    37 
    38 psS32 genericClippedStatsTest(
     15#define NUM_DATA 1000
     16#define VERBOSE 0
     17#define PERCENT_OUTLIERS 2
     18#define ERROR_TOLERANCE .10
     19#define ERRORS 1000.0
     20#define SEED 1995
     21
     22#define TST_IN_NULL  0x00000001
     23#define TST_IN_F32  0x00000002
     24#define TST_IN_F64  0x00000004
     25#define TST_IN_S8  0x00000008
     26#define TST_IN_U16  0x00000010
     27#define TST_IN_S32  0x00000020
     28#define TST_ERRORS_NULL  0x00000040
     29#define TST_ERRORS_F32  0x00000080
     30#define TST_ERRORS_F64  0x00000100
     31#define TST_ERRORS_S8  0x00000200
     32#define TST_ERRORS_U16  0x00000400
     33#define TST_ERRORS_S32  0x00000800
     34#define TST_MASK_NULL  0x00001000
     35#define TST_MASK_U8  0x00002000
     36#define TST_MASK_S32  0x00004000
     37
     38
     39psBool genericClippedStatsTest(
    3940    unsigned int flags,
    4041    psS32 numData,
     
    4344{
    4445    psS32 currentId = psMemGetId();
    45     psS32 testStatus = true;
     46    psBool testStatus = true;
    4647    psS32 memLeaks = 0;
    4748    psVector *in = NULL;
    4849    psVector *errors = NULL;
    4950    psVector *mask = NULL;
     51    srand(SEED);
    5052    printPositiveTestHeader(stdout, "psMathUtils functions", "psVectorStats Clipped Stats Routine");
    5153
     54    if (expectedRC == true) {
     55        printf("This test should not generate any errors.\n");
     56    }
    5257    if (expectedRC == false) {
    5358        printf("This test should generate an error message, and return NULL.\n");
     
    128133    }
    129134
    130 
    131135    if (flags & TST_ERRORS_NULL) {
    132136        printf("        using a NULL errors vector\n");
     
    137141        errors = psVectorAlloc(numData, PS_TYPE_F32);
    138142        for (psS32 i=0;i<numData;i++) {
    139             errors->data.F32[i] = (psF32) i;
     143            errors->data.F32[i] = ERRORS;
    140144        }
    141145
     
    151155        errors = psVectorAlloc(numData, PS_TYPE_F64);
    152156        for (psS32 i=0;i<numData;i++) {
    153             errors->data.F64[i] = (psF64) i;
     157            errors->data.F64[i] = ERRORS;
    154158        }
    155159
     
    165169        errors = psVectorAlloc(numData, PS_TYPE_S8);
    166170        for (psS32 i=0;i<numData;i++) {
    167             errors->data.S8[i] = (psS8) i;
     171            errors->data.S8[i] = (psS8) ERRORS;
    168172        }
    169173
     
    179183        errors = psVectorAlloc(numData, PS_TYPE_U16);
    180184        for (psS32 i=0;i<numData;i++) {
    181             errors->data.U16[i] = (psU16) i;
     185            errors->data.U16[i] = (psU16) ERRORS;
    182186        }
    183187
     
    193197        errors = psVectorAlloc(numData, PS_TYPE_S32);
    194198        for (psS32 i=0;i<numData;i++) {
    195             errors->data.S32[i] = (psS32) i;
     199            errors->data.S32[i] = (psS32) ERRORS;
    196200        }
    197201
     
    212216        mask = psVectorAlloc(numData, PS_TYPE_U8);
    213217        for (psS32 i=0;i<numData;i++) {
    214             mask->data.U8[i] = (psU8) i;
     218            mask->data.U8[i] = (psU8) 0;
    215219        }
    216220
     
    226230        mask = psVectorAlloc(numData, PS_TYPE_S32);
    227231        for (psS32 i=0;i<numData;i++) {
    228             mask->data.S32[i] = (psS32) i;
     232            mask->data.S32[i] = (psS32) 0;
    229233        }
    230234
     
    236240    }
    237241
     242
     243    //
     244    // We calculate the sample mean and stdev without and outliers in the data.
     245    // We will use this later in determining if the clipped stats are correct.
     246    //
     247    psF32 sampleMean;
     248    psF32 sampleStdev;
     249    if (expectedRC == true) {
     250        psStats *myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV);
     251        psStats *rc = psVectorStats(myStats, in, NULL, NULL, maskValue);
     252        if (rc == NULL) {
     253            printf("TEST ERROR: the psVectorStats() function returned NULL.\n");
     254            testStatus = false;
     255        } else {
     256            sampleMean = myStats->sampleMean;
     257            sampleStdev = myStats->sampleStdev;
     258        }
     259        psFree(myStats);
     260    }
     261
     262    //
     263    // We add a few outliers to the input data.
     264    //
     265    if (flags & TST_IN_F32) {
     266        for (psS32 i=0;i<numData;i++) {
     267            if (PERCENT_OUTLIERS > (random() % 100)) {
     268                in->data.F32[i] = (psF32) (10 * numData);
     269            }
     270        }
     271
     272        if (VERBOSE) {
     273            for (psS32 i=0;i<numData;i++) {
     274                printf("Original in data %d: (%.1f)\n", i, in->data.F32[i]);
     275            }
     276        }
     277    }
     278    if (flags & TST_IN_F64) {
     279        for (psS32 i=0;i<numData;i++) {
     280            if (PERCENT_OUTLIERS > (random() % 100)) {
     281                in->data.F64[i] = (psF64) (10 * numData);
     282            }
     283        }
     284
     285        if (VERBOSE) {
     286            for (psS32 i=0;i<numData;i++) {
     287                printf("Original in data %d: (%.1f)\n", i, in->data.F64[i]);
     288            }
     289        }
     290    }
     291    if (flags & TST_IN_S8) {
     292        for (psS32 i=0;i<numData;i++) {
     293            if (PERCENT_OUTLIERS > (random() % 100)) {
     294                in->data.S8[i] = (psS8) (10 * numData);
     295            }
     296        }
     297
     298        if (VERBOSE) {
     299            for (psS32 i=0;i<numData;i++) {
     300                printf("Original in data %d: (%d)\n", i, in->data.S8[i]);
     301            }
     302        }
     303    }
     304    if (flags & TST_IN_U16) {
     305        for (psS32 i=0;i<numData;i++) {
     306            if (PERCENT_OUTLIERS > (random() % 100)) {
     307                in->data.U16[i] = (psU16) (10 * numData);
     308            }
     309        }
     310
     311        if (VERBOSE) {
     312            for (psS32 i=0;i<numData;i++) {
     313                printf("Original in data %d: (%d)\n", i, in->data.U16[i]);
     314            }
     315        }
     316    }
     317    if (flags & TST_IN_S32) {
     318        for (psS32 i=0;i<numData;i++) {
     319            if (PERCENT_OUTLIERS > (random() % 100)) {
     320                in->data.S32[i] = (psS32) (10 * numData);
     321            }
     322        }
     323
     324        if (VERBOSE) {
     325            for (psS32 i=0;i<numData;i++) {
     326                printf("Original in data %d: (%d)\n", i, in->data.S32[i]);
     327            }
     328        }
     329    }
     330
     331    //
     332    // We call psVectorStats() and calculate the clipped stats.
     333    //
    238334    psStats *myStats = psStatsAlloc(PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV);
    239335    psStats *rc = psVectorStats(myStats, in, errors, mask, maskValue);
    240 
    241336    if (rc == NULL) {
    242337        if (expectedRC == true) {
     
    250345        }
    251346
    252     }
    253 
     347        if (fabs(myStats->clippedMean - sampleMean) > (ERROR_TOLERANCE * sampleMean)) {
     348            printf("TEST ERROR: the clipped mean was %.2f, should have been %.2f\n", myStats->clippedMean, sampleMean);
     349            testStatus = false;
     350        } else if (VERBOSE) {
     351            printf("GOOD: the clipped mean was %.2f, should have been %.2f\n", myStats->clippedMean, sampleMean);
     352        }
     353
     354        if (fabs(myStats->clippedStdev - sampleStdev) > (ERROR_TOLERANCE * sampleStdev)) {
     355            printf("TEST ERROR: the clipped stdev was %.2f, should have been %.2f\n", myStats->clippedStdev, sampleStdev);
     356            testStatus = false;
     357        } else if (VERBOSE) {
     358            printf("GOOD: the clipped stdev was %.2f, should have been %.2f\n", myStats->clippedStdev, sampleStdev);
     359        }
     360
     361    }
     362
     363    psFree(myStats);
     364    psFree(in);
     365    psFree(errors);
     366    psFree(mask);
    254367    psMemCheckCorruption(1);
    255368    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
     
    261374}
    262375
    263 
    264 
    265 
     376#define TRACE_LEVEL 0
    266377psS32 main()
    267378{
    268379    psLogSetFormat("HLNM");
     380    psBool testStatus = true;
     381
    269382    //
    270383    // We list pertinent psStats.c functions here for debugging ease.
    271384    //
    272     psTraceSetLevel(".", 0);
    273     psTraceSetLevel("p_psGetStatValue", 0);
    274     psTraceSetLevel("p_psVectorSampleMean", 0);
    275     psTraceSetLevel("p_psVectorMax", 0);
    276     psTraceSetLevel("p_psVectorMin", 0);
    277     psTraceSetLevel("p_psVectorCheckNonEmpty", 0);
    278     psTraceSetLevel("p_psVectorNValues", 0);
    279     psTraceSetLevel("p_psVectorClippedStats", 0);
    280     psTraceSetLevel("p_psNormalizeVectorRange", 0);
    281     psTraceSetLevel("psStatsAlloc", 0);
    282     psTraceSetLevel("p_psConvertToF32", 0);
    283     psTraceSetLevel("psVectorStats", 0);
    284 
     385    psTraceSetLevel(".", TRACE_LEVEL);
     386    psTraceSetLevel("p_psGetStatValue", TRACE_LEVEL);
     387    psTraceSetLevel("p_psVectorSampleMean", TRACE_LEVEL);
     388    psTraceSetLevel("p_psVectorMax", TRACE_LEVEL);
     389    psTraceSetLevel("p_psVectorMin", TRACE_LEVEL);
     390    psTraceSetLevel("p_psVectorCheckNonEmpty", TRACE_LEVEL);
     391    psTraceSetLevel("p_psVectorNValues", TRACE_LEVEL);
     392    psTraceSetLevel("p_psVectorClippedStats", TRACE_LEVEL);
     393    psTraceSetLevel("p_psNormalizeVectorRange", TRACE_LEVEL);
     394    psTraceSetLevel("psStatsAlloc", TRACE_LEVEL);
     395    psTraceSetLevel("p_psConvertToF32", TRACE_LEVEL);
     396    psTraceSetLevel("psVectorStats", TRACE_LEVEL);
     397
     398    testStatus &= genericClippedStatsTest(TST_IN_NULL | TST_ERRORS_NULL | TST_MASK_NULL, NUM_DATA, 1, false);
     399    testStatus &= genericClippedStatsTest(TST_IN_F32 | TST_ERRORS_NULL | TST_MASK_NULL, NUM_DATA, 1, true);
     400    testStatus &= genericClippedStatsTest(TST_IN_F64 | TST_ERRORS_NULL | TST_MASK_NULL, NUM_DATA, 1, true);
     401    testStatus &= genericClippedStatsTest(TST_IN_F32 | TST_ERRORS_F32 | TST_MASK_NULL, NUM_DATA, 1, true);
     402    testStatus &= genericClippedStatsTest(TST_IN_F32 | TST_ERRORS_NULL | TST_MASK_U8, NUM_DATA, 1, true);
     403
     404    if (testStatus) {
     405        printf("TEST PASSED\n");
     406    } else {
     407        printf("TEST FAILED\n");
     408    }
    285409}
  • trunk/psLib/test/math/verified/tst_psStats09.stdout

    r4547 r6307  
    11/***************************** TESTPOINT ******************************************\
    22*             TestFile: tst_psStats09.c                                            *
    3 *            TestPoint: psStats functions{PS_STAT_CLIPPED_MEAN: no vector mask}    *
     3*            TestPoint: psMathUtils functions{psVectorStats Clipped Stats Routine} *
    44*             TestType: Positive                                                   *
    55\**********************************************************************************/
    66
    7 Called psVectorStats() on a vector with no elements masked.
    8 The calculated clippedMean was 29.95
    9 
    10 ---> TESTPOINT PASSED (psVector functions{PS_STAT_CLIPPED_MEAN/STDEV: no vector mask} | tst_psStats09.c)
    11 
     7This test should generate an error message, and return NULL.
     8        using a NULL in vector
     9        using a NULL errors vector
     10        using a NULL mask vector
    1211/***************************** TESTPOINT ******************************************\
    1312*             TestFile: tst_psStats09.c                                            *
    14 *            TestPoint: psStats functions{PS_STAT_CLIPPED_STDEV: no vector mask}  *
     13*            TestPoint: psMathUtils functions{psVectorStats Clipped Stats Routine} *
    1514*             TestType: Positive                                                   *
    1615\**********************************************************************************/
    1716
    18 Called psVectorStats() on a vector with no elements masked.
    19 The calculated clippedStdev was 0.58
    20 
    21 ---> TESTPOINT PASSED (psVector functions{PS_STAT_CLIPPED_MEAN/STDEV: no vector mask} | tst_psStats09.c)
    22 
     17This test should not generate any errors.
     18        using a psF32 in vector
     19        using a NULL errors vector
     20        using a NULL mask vector
    2321/***************************** TESTPOINT ******************************************\
    2422*             TestFile: tst_psStats09.c                                            *
    25 *            TestPoint: psStats functions{PS_STAT_CLIPPED_MEAN: vector mask}      *
     23*            TestPoint: psMathUtils functions{psVectorStats Clipped Stats Routine} *
    2624*             TestType: Positive                                                   *
    2725\**********************************************************************************/
    2826
    29 Called psVectorStats() on a vector with elements masked.
    30 The calculated clippedMean was 29.45
    31 
    32 ---> TESTPOINT PASSED (psVector functions{PS_STAT_CLIPPED_MEAN/STDEV: vector mask} | tst_psStats09.c)
    33 
     27This test should not generate any errors.
     28        using a psF64 in vector
     29        using a NULL errors vector
     30        using a NULL mask vector
    3431/***************************** TESTPOINT ******************************************\
    3532*             TestFile: tst_psStats09.c                                            *
    36 *            TestPoint: psStats functions{PS_STAT_CLIPPED_STDEV: vector mask}      *
     33*            TestPoint: psMathUtils functions{psVectorStats Clipped Stats Routine} *
    3734*             TestType: Positive                                                   *
    3835\**********************************************************************************/
    3936
    40 Called psVectorStats() on a vector with elements masked.
    41 The calculated clippedStdev was 0.29
    42 
    43 ---> TESTPOINT PASSED (psVector functions{PS_STAT_CLIPPED_MEAN/STDEV: vector mask} | tst_psStats09.c)
    44 
     37This test should not generate any errors.
     38        using a psF32 in vector
     39        using a psF32 errors vector
     40        using a NULL mask vector
    4541/***************************** TESTPOINT ******************************************\
    4642*             TestFile: tst_psStats09.c                                            *
    47 *            TestPoint: psStats functions{psStats(): deallocating memory}          *
     43*            TestPoint: psMathUtils functions{psVectorStats Clipped Stats Routine} *
    4844*             TestType: Positive                                                   *
    4945\**********************************************************************************/
    5046
    51 
    52 ---> TESTPOINT PASSED (psVector functions{psStats(): deallocating memory} | tst_psStats09.c)
    53 
     47This test should not generate any errors.
     48        using a psF32 in vector
     49        using a NULL errors vector
     50        using a psU8 mask vector
     51TEST PASSED
Note: See TracChangeset for help on using the changeset viewer.