Index: /trunk/psLib/test/dataManip/tst_psStats01.c
===================================================================
--- /trunk/psLib/test/dataManip/tst_psStats01.c	(revision 3529)
+++ /trunk/psLib/test/dataManip/tst_psStats01.c	(revision 3530)
@@ -1,24 +1,62 @@
-/*****************************************************************************
-    This routine must ensure that PS_STAT_MAX is correctly computed
-    by the procedure psVectorStats().
- *****************************************************************************/
-#include <stdio.h>
+/** @file  tst_psStats01.c
+*
+*  @brief Contains tests for psVectorStats with max calculations
+*
+*  @author George Gusciora, MHPCC
+*
+*  @version $Revision: 1.10 $  $Name: not supported by cvs2svn $
+*  @date $Date: 2005-03-28 22:50:59 $
+*
+* Copyright 2004-2005 Maui High Performance Computing Center, Univ. of Hawaii
+*/
+
 #include "pslib.h"
 #include "psTest.h"
-#define N 10
-
-psS32 main()
-{
-    psStats *myStats    = NULL;
-    psS32 testStatus      = true;
-    psS32 globalTestStatus = true;
-    psS32 i               = 0;
-    psVector *myVector  = NULL;
-    psVector *maskVector= NULL;
-    float max           = 0.0;
-    float realMaxNoMask   = 0.0;
-    float realMaxWithMask = 0.0;
-    psS32 currentId       = psMemGetId();
-    psS32 memLeaks        = 0;
+
+#define N 15
+#define ERROR_TOL  0.0001
+
+static psS32 testStatsMaxF32(void);
+static psS32 testStatsMaxS8(void);
+static psS32 testStatsMaxU16(void);
+static psS32 testStatsMaxF64(void);
+
+testDescription tests[] = {
+                              {testStatsMaxF32, 518, "psVectorStats", 0, false},
+                              {testStatsMaxS8, 518, "psVectorStats", 0, false},
+                              {testStatsMaxU16, 518, "psVectorStats", 0, false},
+                              {testStatsMaxF64, 518, "psVectorStats", 0, false},
+                              {NULL}
+                          };
+
+static psF32 samplesF32[N] = { 1.1, 2.2, -3.3, 4.4, 5.5, -6.6, 7.7, 8.8, -9.9, 10.0,
+                               11.01, -12.02, 13.03, 14.04, -15.05 };
+static psS8  samplesS8[N]  = {1, 2, -3, 4, 5, -6, 7, 8, -9, 10, 11, -12, 13, 14, -15};
+static psU16 samplesU16[N] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
+static psF64 samplesF64[N] = { 1.1, 2.2, -3.3, 4.4, 5.5, -6.6, 7.7, 8.8, -9.9, 10.0,
+                               11.01, -12.02, 13.03, 14.04, -15.05 };
+
+static psF64 expectedMaxNoMaskF32                = 14.04;
+static psF64 expectedMaxNoMaskS8                 = 14.00;
+static psF64 expectedMaxNoMaskU16                = 15.00;
+static psF64 expectedMaxNoMaskF64                = 14.04;
+
+static psF64 expectedMaxWithMaskF32              = 13.03;
+static psF64 expectedMaxRangeNoMaskF32           = 10.00;
+static psF64 expectedMaxRangeWithMaskF32         = 13.03;
+
+psS32 main(psS32 argc, char* argv[] )
+{
+    psLogSetLevel(PS_LOG_INFO);
+
+    return ( ! runTestSuite(stderr, "psVectorStats", tests, argc, argv) );
+}
+
+psS32 testStatsMaxF32(void)
+{
+    psStats*  myStats    = NULL;
+    psVector* myVector   = NULL;
+    psVector* maskVector = NULL;
+    psF64     max        = 0.0;
 
     /*************************************************************************/
@@ -32,23 +70,14 @@
 
     // Set the appropriate values for the vector data.
-    for (i=0;i<N;i++) {
-        myVector->data.F32[i] = (float) i;
+    for (psS32 i = 0; i < N; i++) {
+        myVector->data.F32[i] = samplesF32[i];
     }
 
     // Set the mask vector and calculate the expected maximum.
-    for (i=0;i<N;i++) {
-        if (myVector->data.F32[i] > realMaxNoMask) {
-            realMaxNoMask = myVector->data.F32[i];
-        }
-
-        if (i < (N/2)) {
+    for (psS32 i = 0; i < N; i++) {
+        if (i < 13) {
             maskVector->data.U8[i] = 0;
-
-            if (myVector->data.F32[i] > realMaxWithMask) {
-                realMaxWithMask = myVector->data.F32[i];
-            }
         } else {
             maskVector->data.U8[i] = 1;
-            printf("Masking element %d\n", i);
         }
     }
@@ -57,53 +86,59 @@
     /*  Call psVectorStats() with no vector mask.                    */
     /*************************************************************************/
-    printPositiveTestHeader(stdout,
-                            "psStats functions",
-                            "PS_STAT_MAX: no vector mask");
-
-    myStats = psVectorStats(myStats, myVector, NULL, NULL, 0);
-    max = myStats->max;
-
-    printf("Called psVectorStats() on a vector with no elements masked.\n");
-    printf("The expected max was %f; the calculated max was %f\n", realMaxNoMask, max);
-    if (max == realMaxNoMask) {
-        testStatus = true;
-    } else {
-        testStatus = false;
-        globalTestStatus = false;
-    }
-    printFooter(stdout,
-                "psVector functions",
-                "PS_STAT_MAX: no vector mask",
-                testStatus);
+    myStats = psVectorStats(myStats, myVector, NULL, NULL, 0);
+    max = myStats->max;
+
+    if (fabs(max - expectedMaxNoMaskF32) > ERROR_TOL) {
+        psError(PS_ERR_UNKNOWN,true,"Max no mask return value %lf not as expected %lf",
+                max, expectedMaxNoMaskF32);
+        return 1;
+    }
 
     /*************************************************************************/
     /*  Call psVectorStats() with vector mask.                       */
     /*************************************************************************/
-    printPositiveTestHeader(stdout,
-                            "psStats functions",
-                            "PS_STAT_MAX: with vector mask");
-
     myStats = psVectorStats(myStats, myVector, NULL, maskVector, 1);
     max = myStats->max;
-    printf("Called psVectorStats() on a vector with last N/2 elements masked.\n");
-    printf("The expected max was %f; the calculated max was %f\n", realMaxWithMask, max);
-    if (max == realMaxWithMask) {
-        testStatus = true;
-    } else {
-        testStatus = false;
-        globalTestStatus = false;
-    }
-
-    printFooter(stdout,
-                "psVector functions",
-                "PS_STAT_MAX: with vector mask",
-                testStatus);
-
-    /*************************************************************************/
-    /*  Deallocate data structures                                   */
-    /*************************************************************************/
-    printPositiveTestHeader(stdout,
-                            "psStats functions",
-                            "psStats(): deallocating memory");
+    if (fabs(max - expectedMaxWithMaskF32) > ERROR_TOL) {
+        psError(PS_ERR_UNKNOWN,true,"Max with mask return value %lf not as expected %lf",
+                max, expectedMaxWithMaskF32);
+        return 2;
+    }
+
+    // Invoke function with data range with no mask
+    myStats->options = PS_STAT_MAX | PS_STAT_USE_RANGE;
+    myStats->max = 10.1;
+    myStats->min = 0.0;
+    myStats = psVectorStats(myStats, myVector, NULL, NULL, 0);
+    max = myStats->max;
+
+    if(fabs(max - expectedMaxRangeNoMaskF32) > ERROR_TOL) {
+        psError(PS_ERR_UNKNOWN,true,"Max with range no mask %lf not as expected %lf",
+                max, expectedMaxRangeNoMaskF32);
+        return 3;
+    }
+
+    // Invoke function with data range and mask
+    myStats->max = 14.0;
+    myStats->min = 0.0;
+    myStats = psVectorStats(myStats, myVector, NULL, maskVector, 1);
+    max = myStats->max;
+    if(fabs(max - expectedMaxRangeWithMaskF32) > ERROR_TOL) {
+        psError(PS_ERR_UNKNOWN,true,"Max with range with mask %lf not as expected %lf",
+                max, expectedMaxRangeWithMaskF32);
+        return 3;
+    }
+
+    // Invoke function with data range with no valid data
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message");
+    myStats->max = 100.00;
+    myStats->min = 90.00;
+    myStats = psVectorStats(myStats, myVector, NULL, NULL, 0);
+    max = myStats->max;
+
+    if(!isnan(max)) {
+        psError(PS_ERR_UNKNOWN,true,"Max with range with no valid elemenets did not return NAN");
+        return 4;
+    }
 
     psFree(myStats);
@@ -111,15 +146,113 @@
     psFree(maskVector);
 
-    psMemCheckCorruption(1);
-    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
-    if (0 != memLeaks) {
-        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
-    }
-
-    printFooter(stdout,
-                "psVector functions",
-                "psStats(): deallocating memory",
-                testStatus);
-
-    return (!globalTestStatus);
-}
+    return 0;
+}
+
+psS32 testStatsMaxS8(void)
+{
+    psStats*  myStats    = NULL;
+    psVector* myVector   = NULL;
+    psF64     max        = 0.0;
+
+    /*************************************************************************/
+    /*  Allocate and initialize data structures                      */
+    /*************************************************************************/
+    myStats = psStatsAlloc(PS_STAT_MAX);
+    myVector = psVectorAlloc(N, PS_TYPE_S8);
+    myVector->n = N;
+
+    // Set the appropriate values for the vector data.
+    for (psS32 i = 0; i < N; i++) {
+        myVector->data.S8[i] = samplesS8[i];
+    }
+
+    /*************************************************************************/
+    /*  Call psVectorStats() with no vector mask.                    */
+    /*************************************************************************/
+    myStats = psVectorStats(myStats, myVector, NULL, NULL, 0);
+    max = myStats->max;
+
+    if (fabs(max - expectedMaxNoMaskS8) > ERROR_TOL) {
+        psError(PS_ERR_UNKNOWN,true,"Max no mask return value %lf not as expected %lf",
+                max, expectedMaxNoMaskS8);
+        return 1;
+    }
+
+    psFree(myStats);
+    psFree(myVector);
+
+    return 0;
+}
+
+psS32 testStatsMaxU16(void)
+{
+    psStats*  myStats    = NULL;
+    psVector* myVector   = NULL;
+    psF64     max        = 0.0;
+
+    /*************************************************************************/
+    /*  Allocate and initialize data structures                      */
+    /*************************************************************************/
+    myStats = psStatsAlloc(PS_STAT_MAX);
+    myVector = psVectorAlloc(N, PS_TYPE_U16);
+    myVector->n = N;
+
+    // Set the appropriate values for the vector data.
+    for (psS32 i = 0; i < N; i++) {
+        myVector->data.U16[i] = samplesU16[i];
+    }
+
+    /*************************************************************************/
+    /*  Call psVectorStats() with no vector mask.                    */
+    /*************************************************************************/
+    myStats = psVectorStats(myStats, myVector, NULL, NULL, 0);
+    max = myStats->max;
+
+    if (fabs(max - expectedMaxNoMaskU16) > ERROR_TOL) {
+        psError(PS_ERR_UNKNOWN,true,"Max no mask return value %lf not as expected %lf",
+                max, expectedMaxNoMaskU16);
+        return 1;
+    }
+
+    psFree(myStats);
+    psFree(myVector);
+
+    return 0;
+}
+
+psS32 testStatsMaxF64(void)
+{
+    psStats*  myStats    = NULL;
+    psVector* myVector   = NULL;
+    psF64     max        = 0.0;
+
+    /*************************************************************************/
+    /*  Allocate and initialize data structures                      */
+    /*************************************************************************/
+    myStats = psStatsAlloc(PS_STAT_MAX);
+    myVector = psVectorAlloc(N, PS_TYPE_F64);
+    myVector->n = N;
+
+    // Set the appropriate values for the vector data.
+    for (psS32 i = 0; i < N; i++) {
+        myVector->data.F64[i] = samplesF64[i];
+    }
+
+    /*************************************************************************/
+    /*  Call psVectorStats() with no vector mask.                    */
+    /*************************************************************************/
+    myStats = psVectorStats(myStats, myVector, NULL, NULL, 0);
+    max = myStats->max;
+
+    if (fabs(max - expectedMaxNoMaskF64) > ERROR_TOL) {
+        psError(PS_ERR_UNKNOWN,true,"Max no mask return value %lf not as expected %lf",
+                max, expectedMaxNoMaskF64);
+        return 1;
+    }
+
+    psFree(myStats);
+    psFree(myVector);
+
+    return 0;
+}
+
Index: /trunk/psLib/test/dataManip/verified/tst_psStats01.stderr
===================================================================
--- /trunk/psLib/test/dataManip/verified/tst_psStats01.stderr	(revision 3530)
+++ /trunk/psLib/test/dataManip/verified/tst_psStats01.stderr	(revision 3530)
@@ -0,0 +1,40 @@
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psStats01.c                                            *
+*            TestPoint: psVectorStats{psVectorStats}                               *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+<DATE><TIME>|<HOST>|I|testStatsMaxF32
+    Following should generate error message
+<DATE><TIME>|<HOST>|E|psVectorStats (FILE:LINENO)
+    Failed to calculate vector maximum
+
+---> TESTPOINT PASSED (psVectorStats{psVectorStats} | tst_psStats01.c)
+
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psStats01.c                                            *
+*            TestPoint: psVectorStats{psVectorStats}                               *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+
+---> TESTPOINT PASSED (psVectorStats{psVectorStats} | tst_psStats01.c)
+
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psStats01.c                                            *
+*            TestPoint: psVectorStats{psVectorStats}                               *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+
+---> TESTPOINT PASSED (psVectorStats{psVectorStats} | tst_psStats01.c)
+
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psStats01.c                                            *
+*            TestPoint: psVectorStats{psVectorStats}                               *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+
+---> TESTPOINT PASSED (psVectorStats{psVectorStats} | tst_psStats01.c)
+
Index: /trunk/psLib/test/dataManip/verified/tst_psStats01.stdout
===================================================================
--- /trunk/psLib/test/dataManip/verified/tst_psStats01.stdout	(revision 3529)
+++ /trunk/psLib/test/dataManip/verified/tst_psStats01.stdout	(revision 3530)
@@ -1,36 +1,0 @@
-Masking element 5
-Masking element 6
-Masking element 7
-Masking element 8
-Masking element 9
-/***************************** TESTPOINT ******************************************\
-*             TestFile: tst_psStats01.c                                            *
-*            TestPoint: psStats functions{PS_STAT_MAX: no vector mask}             *
-*             TestType: Positive                                                   *
-\**********************************************************************************/
-
-Called psVectorStats() on a vector with no elements masked.
-The expected max was 9.000000; the calculated max was 9.000000
-
----> TESTPOINT PASSED (psVector functions{PS_STAT_MAX: no vector mask} | tst_psStats01.c)
-
-/***************************** TESTPOINT ******************************************\
-*             TestFile: tst_psStats01.c                                            *
-*            TestPoint: psStats functions{PS_STAT_MAX: with vector mask}           *
-*             TestType: Positive                                                   *
-\**********************************************************************************/
-
-Called psVectorStats() on a vector with last N/2 elements masked.
-The expected max was 4.000000; the calculated max was 4.000000
-
----> TESTPOINT PASSED (psVector functions{PS_STAT_MAX: with vector mask} | tst_psStats01.c)
-
-/***************************** TESTPOINT ******************************************\
-*             TestFile: tst_psStats01.c                                            *
-*            TestPoint: psStats functions{psStats(): deallocating memory}          *
-*             TestType: Positive                                                   *
-\**********************************************************************************/
-
-
----> TESTPOINT PASSED (psVector functions{psStats(): deallocating memory} | tst_psStats01.c)
-
