IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 3530


Ignore:
Timestamp:
Mar 28, 2005, 12:50:59 PM (21 years ago)
Author:
evanalst
Message:

Update test cases for finding max with psVectorStats.

Location:
trunk/psLib/test/dataManip
Files:
1 added
2 edited

Legend:

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

    r2780 r3530  
    1 /*****************************************************************************
    2     This routine must ensure that PS_STAT_MAX is correctly computed
    3     by the procedure psVectorStats().
    4  *****************************************************************************/
    5 #include <stdio.h>
     1/** @file  tst_psStats01.c
     2*
     3*  @brief Contains tests for psVectorStats with max calculations
     4*
     5*  @author George Gusciora, MHPCC
     6*
     7*  @version $Revision: 1.10 $  $Name: not supported by cvs2svn $
     8*  @date $Date: 2005-03-28 22:50:59 $
     9*
     10* Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii
     11*/
     12
    613#include "pslib.h"
    714#include "psTest.h"
    8 #define N 10
    9 
    10 psS32 main()
    11 {
    12     psStats *myStats    = NULL;
    13     psS32 testStatus      = true;
    14     psS32 globalTestStatus = true;
    15     psS32 i               = 0;
    16     psVector *myVector  = NULL;
    17     psVector *maskVector= NULL;
    18     float max           = 0.0;
    19     float realMaxNoMask   = 0.0;
    20     float realMaxWithMask = 0.0;
    21     psS32 currentId       = psMemGetId();
    22     psS32 memLeaks        = 0;
     15
     16#define N 15
     17#define ERROR_TOL  0.0001
     18
     19static psS32 testStatsMaxF32(void);
     20static psS32 testStatsMaxS8(void);
     21static psS32 testStatsMaxU16(void);
     22static psS32 testStatsMaxF64(void);
     23
     24testDescription tests[] = {
     25                              {testStatsMaxF32, 518, "psVectorStats", 0, false},
     26                              {testStatsMaxS8, 518, "psVectorStats", 0, false},
     27                              {testStatsMaxU16, 518, "psVectorStats", 0, false},
     28                              {testStatsMaxF64, 518, "psVectorStats", 0, false},
     29                              {NULL}
     30                          };
     31
     32static psF32 samplesF32[N] = { 1.1, 2.2, -3.3, 4.4, 5.5, -6.6, 7.7, 8.8, -9.9, 10.0,
     33                               11.01, -12.02, 13.03, 14.04, -15.05 };
     34static psS8  samplesS8[N]  = {1, 2, -3, 4, 5, -6, 7, 8, -9, 10, 11, -12, 13, 14, -15};
     35static psU16 samplesU16[N] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
     36static psF64 samplesF64[N] = { 1.1, 2.2, -3.3, 4.4, 5.5, -6.6, 7.7, 8.8, -9.9, 10.0,
     37                               11.01, -12.02, 13.03, 14.04, -15.05 };
     38
     39static psF64 expectedMaxNoMaskF32                = 14.04;
     40static psF64 expectedMaxNoMaskS8                 = 14.00;
     41static psF64 expectedMaxNoMaskU16                = 15.00;
     42static psF64 expectedMaxNoMaskF64                = 14.04;
     43
     44static psF64 expectedMaxWithMaskF32              = 13.03;
     45static psF64 expectedMaxRangeNoMaskF32           = 10.00;
     46static psF64 expectedMaxRangeWithMaskF32         = 13.03;
     47
     48psS32 main(psS32 argc, char* argv[] )
     49{
     50    psLogSetLevel(PS_LOG_INFO);
     51
     52    return ( ! runTestSuite(stderr, "psVectorStats", tests, argc, argv) );
     53}
     54
     55psS32 testStatsMaxF32(void)
     56{
     57    psStats*  myStats    = NULL;
     58    psVector* myVector   = NULL;
     59    psVector* maskVector = NULL;
     60    psF64     max        = 0.0;
    2361
    2462    /*************************************************************************/
     
    3270
    3371    // Set the appropriate values for the vector data.
    34     for (i=0;i<N;i++) {
    35         myVector->data.F32[i] = (float) i;
     72    for (psS32 i = 0; i < N; i++) {
     73        myVector->data.F32[i] = samplesF32[i];
    3674    }
    3775
    3876    // Set the mask vector and calculate the expected maximum.
    39     for (i=0;i<N;i++) {
    40         if (myVector->data.F32[i] > realMaxNoMask) {
    41             realMaxNoMask = myVector->data.F32[i];
    42         }
    43 
    44         if (i < (N/2)) {
     77    for (psS32 i = 0; i < N; i++) {
     78        if (i < 13) {
    4579            maskVector->data.U8[i] = 0;
    46 
    47             if (myVector->data.F32[i] > realMaxWithMask) {
    48                 realMaxWithMask = myVector->data.F32[i];
    49             }
    5080        } else {
    5181            maskVector->data.U8[i] = 1;
    52             printf("Masking element %d\n", i);
    5382        }
    5483    }
     
    5786    /*  Call psVectorStats() with no vector mask.                    */
    5887    /*************************************************************************/
    59     printPositiveTestHeader(stdout,
    60                             "psStats functions",
    61                             "PS_STAT_MAX: no vector mask");
    62 
    63     myStats = psVectorStats(myStats, myVector, NULL, NULL, 0);
    64     max = myStats->max;
    65 
    66     printf("Called psVectorStats() on a vector with no elements masked.\n");
    67     printf("The expected max was %f; the calculated max was %f\n", realMaxNoMask, max);
    68     if (max == realMaxNoMask) {
    69         testStatus = true;
    70     } else {
    71         testStatus = false;
    72         globalTestStatus = false;
    73     }
    74     printFooter(stdout,
    75                 "psVector functions",
    76                 "PS_STAT_MAX: no vector mask",
    77                 testStatus);
     88    myStats = psVectorStats(myStats, myVector, NULL, NULL, 0);
     89    max = myStats->max;
     90
     91    if (fabs(max - expectedMaxNoMaskF32) > ERROR_TOL) {
     92        psError(PS_ERR_UNKNOWN,true,"Max no mask return value %lf not as expected %lf",
     93                max, expectedMaxNoMaskF32);
     94        return 1;
     95    }
    7896
    7997    /*************************************************************************/
    8098    /*  Call psVectorStats() with vector mask.                       */
    8199    /*************************************************************************/
    82     printPositiveTestHeader(stdout,
    83                             "psStats functions",
    84                             "PS_STAT_MAX: with vector mask");
    85 
    86100    myStats = psVectorStats(myStats, myVector, NULL, maskVector, 1);
    87101    max = myStats->max;
    88     printf("Called psVectorStats() on a vector with last N/2 elements masked.\n");
    89     printf("The expected max was %f; the calculated max was %f\n", realMaxWithMask, max);
    90     if (max == realMaxWithMask) {
    91         testStatus = true;
    92     } else {
    93         testStatus = false;
    94         globalTestStatus = false;
    95     }
    96 
    97     printFooter(stdout,
    98                 "psVector functions",
    99                 "PS_STAT_MAX: with vector mask",
    100                 testStatus);
    101 
    102     /*************************************************************************/
    103     /*  Deallocate data structures                                   */
    104     /*************************************************************************/
    105     printPositiveTestHeader(stdout,
    106                             "psStats functions",
    107                             "psStats(): deallocating memory");
     102    if (fabs(max - expectedMaxWithMaskF32) > ERROR_TOL) {
     103        psError(PS_ERR_UNKNOWN,true,"Max with mask return value %lf not as expected %lf",
     104                max, expectedMaxWithMaskF32);
     105        return 2;
     106    }
     107
     108    // Invoke function with data range with no mask
     109    myStats->options = PS_STAT_MAX | PS_STAT_USE_RANGE;
     110    myStats->max = 10.1;
     111    myStats->min = 0.0;
     112    myStats = psVectorStats(myStats, myVector, NULL, NULL, 0);
     113    max = myStats->max;
     114
     115    if(fabs(max - expectedMaxRangeNoMaskF32) > ERROR_TOL) {
     116        psError(PS_ERR_UNKNOWN,true,"Max with range no mask %lf not as expected %lf",
     117                max, expectedMaxRangeNoMaskF32);
     118        return 3;
     119    }
     120
     121    // Invoke function with data range and mask
     122    myStats->max = 14.0;
     123    myStats->min = 0.0;
     124    myStats = psVectorStats(myStats, myVector, NULL, maskVector, 1);
     125    max = myStats->max;
     126    if(fabs(max - expectedMaxRangeWithMaskF32) > ERROR_TOL) {
     127        psError(PS_ERR_UNKNOWN,true,"Max with range with mask %lf not as expected %lf",
     128                max, expectedMaxRangeWithMaskF32);
     129        return 3;
     130    }
     131
     132    // Invoke function with data range with no valid data
     133    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message");
     134    myStats->max = 100.00;
     135    myStats->min = 90.00;
     136    myStats = psVectorStats(myStats, myVector, NULL, NULL, 0);
     137    max = myStats->max;
     138
     139    if(!isnan(max)) {
     140        psError(PS_ERR_UNKNOWN,true,"Max with range with no valid elemenets did not return NAN");
     141        return 4;
     142    }
    108143
    109144    psFree(myStats);
     
    111146    psFree(maskVector);
    112147
    113     psMemCheckCorruption(1);
    114     memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
    115     if (0 != memLeaks) {
    116         psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
    117     }
    118 
    119     printFooter(stdout,
    120                 "psVector functions",
    121                 "psStats(): deallocating memory",
    122                 testStatus);
    123 
    124     return (!globalTestStatus);
    125 }
     148    return 0;
     149}
     150
     151psS32 testStatsMaxS8(void)
     152{
     153    psStats*  myStats    = NULL;
     154    psVector* myVector   = NULL;
     155    psF64     max        = 0.0;
     156
     157    /*************************************************************************/
     158    /*  Allocate and initialize data structures                      */
     159    /*************************************************************************/
     160    myStats = psStatsAlloc(PS_STAT_MAX);
     161    myVector = psVectorAlloc(N, PS_TYPE_S8);
     162    myVector->n = N;
     163
     164    // Set the appropriate values for the vector data.
     165    for (psS32 i = 0; i < N; i++) {
     166        myVector->data.S8[i] = samplesS8[i];
     167    }
     168
     169    /*************************************************************************/
     170    /*  Call psVectorStats() with no vector mask.                    */
     171    /*************************************************************************/
     172    myStats = psVectorStats(myStats, myVector, NULL, NULL, 0);
     173    max = myStats->max;
     174
     175    if (fabs(max - expectedMaxNoMaskS8) > ERROR_TOL) {
     176        psError(PS_ERR_UNKNOWN,true,"Max no mask return value %lf not as expected %lf",
     177                max, expectedMaxNoMaskS8);
     178        return 1;
     179    }
     180
     181    psFree(myStats);
     182    psFree(myVector);
     183
     184    return 0;
     185}
     186
     187psS32 testStatsMaxU16(void)
     188{
     189    psStats*  myStats    = NULL;
     190    psVector* myVector   = NULL;
     191    psF64     max        = 0.0;
     192
     193    /*************************************************************************/
     194    /*  Allocate and initialize data structures                      */
     195    /*************************************************************************/
     196    myStats = psStatsAlloc(PS_STAT_MAX);
     197    myVector = psVectorAlloc(N, PS_TYPE_U16);
     198    myVector->n = N;
     199
     200    // Set the appropriate values for the vector data.
     201    for (psS32 i = 0; i < N; i++) {
     202        myVector->data.U16[i] = samplesU16[i];
     203    }
     204
     205    /*************************************************************************/
     206    /*  Call psVectorStats() with no vector mask.                    */
     207    /*************************************************************************/
     208    myStats = psVectorStats(myStats, myVector, NULL, NULL, 0);
     209    max = myStats->max;
     210
     211    if (fabs(max - expectedMaxNoMaskU16) > ERROR_TOL) {
     212        psError(PS_ERR_UNKNOWN,true,"Max no mask return value %lf not as expected %lf",
     213                max, expectedMaxNoMaskU16);
     214        return 1;
     215    }
     216
     217    psFree(myStats);
     218    psFree(myVector);
     219
     220    return 0;
     221}
     222
     223psS32 testStatsMaxF64(void)
     224{
     225    psStats*  myStats    = NULL;
     226    psVector* myVector   = NULL;
     227    psF64     max        = 0.0;
     228
     229    /*************************************************************************/
     230    /*  Allocate and initialize data structures                      */
     231    /*************************************************************************/
     232    myStats = psStatsAlloc(PS_STAT_MAX);
     233    myVector = psVectorAlloc(N, PS_TYPE_F64);
     234    myVector->n = N;
     235
     236    // Set the appropriate values for the vector data.
     237    for (psS32 i = 0; i < N; i++) {
     238        myVector->data.F64[i] = samplesF64[i];
     239    }
     240
     241    /*************************************************************************/
     242    /*  Call psVectorStats() with no vector mask.                    */
     243    /*************************************************************************/
     244    myStats = psVectorStats(myStats, myVector, NULL, NULL, 0);
     245    max = myStats->max;
     246
     247    if (fabs(max - expectedMaxNoMaskF64) > ERROR_TOL) {
     248        psError(PS_ERR_UNKNOWN,true,"Max no mask return value %lf not as expected %lf",
     249                max, expectedMaxNoMaskF64);
     250        return 1;
     251    }
     252
     253    psFree(myStats);
     254    psFree(myVector);
     255
     256    return 0;
     257}
     258
  • trunk/psLib/test/dataManip/verified/tst_psStats01.stdout

    r1034 r3530  
    1 Masking element 5
    2 Masking element 6
    3 Masking element 7
    4 Masking element 8
    5 Masking element 9
    6 /***************************** TESTPOINT ******************************************\
    7 *             TestFile: tst_psStats01.c                                            *
    8 *            TestPoint: psStats functions{PS_STAT_MAX: no vector mask}             *
    9 *             TestType: Positive                                                   *
    10 \**********************************************************************************/
    11 
    12 Called psVectorStats() on a vector with no elements masked.
    13 The expected max was 9.000000; the calculated max was 9.000000
    14 
    15 ---> TESTPOINT PASSED (psVector functions{PS_STAT_MAX: no vector mask} | tst_psStats01.c)
    16 
    17 /***************************** TESTPOINT ******************************************\
    18 *             TestFile: tst_psStats01.c                                            *
    19 *            TestPoint: psStats functions{PS_STAT_MAX: with vector mask}           *
    20 *             TestType: Positive                                                   *
    21 \**********************************************************************************/
    22 
    23 Called psVectorStats() on a vector with last N/2 elements masked.
    24 The expected max was 4.000000; the calculated max was 4.000000
    25 
    26 ---> TESTPOINT PASSED (psVector functions{PS_STAT_MAX: with vector mask} | tst_psStats01.c)
    27 
    28 /***************************** TESTPOINT ******************************************\
    29 *             TestFile: tst_psStats01.c                                            *
    30 *            TestPoint: psStats functions{psStats(): deallocating memory}          *
    31 *             TestType: Positive                                                   *
    32 \**********************************************************************************/
    33 
    34 
    35 ---> TESTPOINT PASSED (psVector functions{psStats(): deallocating memory} | tst_psStats01.c)
    36 
Note: See TracChangeset for help on using the changeset viewer.