Index: trunk/psLib/test/math/tst_psStats09.c
===================================================================
--- trunk/psLib/test/math/tst_psStats09.c	(revision 5117)
+++ trunk/psLib/test/math/tst_psStats09.c	(revision 6304)
@@ -18,4 +18,249 @@
 #define MY_MEAN  30.0
 #define MY_RANGE 2.0
+#define VERBOSE 1
+
+#define TST_IN_NULL  0x00000000
+#define TST_IN_F32  0x00000000
+#define TST_IN_F64  0x00000000
+#define TST_IN_S8  0x00000000
+#define TST_IN_U16  0x00000000
+#define TST_IN_S32  0x00000000
+#define TST_ERRORS_NULL  0x00000000
+#define TST_ERRORS_F32  0x00000000
+#define TST_ERRORS_F64  0x00000000
+#define TST_ERRORS_S8  0x00000000
+#define TST_ERRORS_U16  0x00000000
+#define TST_ERRORS_S32  0x00000000
+#define TST_MASK_NULL  0x00000000
+#define TST_MASK_U8  0x00000000
+#define TST_MASK_S32  0x00000000
+
+psS32 genericClippedStatsTest(
+    unsigned int flags,
+    psS32 numData,
+    psU32 maskValue,
+    psBool expectedRC)
+{
+    psS32 currentId = psMemGetId();
+    psS32 testStatus = true;
+    psS32 memLeaks = 0;
+    psVector *in = NULL;
+    psVector *errors = NULL;
+    psVector *mask = NULL;
+    printPositiveTestHeader(stdout, "psMathUtils functions", "psVectorStats Clipped Stats Routine");
+
+    if (expectedRC == false) {
+        printf("This test should generate an error message, and return NULL.\n");
+    }
+
+    if (flags & TST_IN_NULL) {
+        printf("        using a NULL in vector\n");
+    }
+
+    if (flags & TST_IN_F32) {
+        printf("        using a psF32 in vector\n");
+        in = psVectorAlloc(numData, PS_TYPE_F32);
+        for (psS32 i=0;i<numData;i++) {
+            in->data.F32[i] = (psF32) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original in data %d: (%.1f)\n", i, in->data.F32[i]);
+            }
+        }
+    }
+
+    if (flags & TST_IN_F64) {
+        printf("        using a psF64 in vector\n");
+        in = psVectorAlloc(numData, PS_TYPE_F64);
+        for (psS32 i=0;i<numData;i++) {
+            in->data.F64[i] = (psF64) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original in data %d: (%.1f)\n", i, in->data.F64[i]);
+            }
+        }
+    }
+
+    if (flags & TST_IN_S8) {
+        printf("        using a psS8 in vector\n");
+        in = psVectorAlloc(numData, PS_TYPE_S8);
+        for (psS32 i=0;i<numData;i++) {
+            in->data.S8[i] = (psS8) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original in data %d: (%d)\n", i, in->data.S8[i]);
+            }
+        }
+    }
+
+    if (flags & TST_IN_U16) {
+        printf("        using a psU16 in vector\n");
+        in = psVectorAlloc(numData, PS_TYPE_U16);
+        for (psS32 i=0;i<numData;i++) {
+            in->data.U16[i] = (psU16) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original in data %d: (%d)\n", i, in->data.U16[i]);
+            }
+        }
+    }
+
+    if (flags & TST_IN_S32) {
+        printf("        using a psS32 in vector\n");
+        in = psVectorAlloc(numData, PS_TYPE_S32);
+        for (psS32 i=0;i<numData;i++) {
+            in->data.S32[i] = (psS32) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original in data %d: (%d)\n", i, in->data.S32[i]);
+            }
+        }
+    }
+
+
+    if (flags & TST_ERRORS_NULL) {
+        printf("        using a NULL errors vector\n");
+    }
+
+    if (flags & TST_ERRORS_F32) {
+        printf("        using a psF32 errors vector\n");
+        errors = psVectorAlloc(numData, PS_TYPE_F32);
+        for (psS32 i=0;i<numData;i++) {
+            errors->data.F32[i] = (psF32) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original errors data %d: (%.1f)\n", i, errors->data.F32[i]);
+            }
+        }
+    }
+
+    if (flags & TST_ERRORS_F64) {
+        printf("        using a psF64 errors vector\n");
+        errors = psVectorAlloc(numData, PS_TYPE_F64);
+        for (psS32 i=0;i<numData;i++) {
+            errors->data.F64[i] = (psF64) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original errors data %d: (%.1f)\n", i, errors->data.F64[i]);
+            }
+        }
+    }
+
+    if (flags & TST_ERRORS_S8) {
+        printf("        using a psS8 errors vector\n");
+        errors = psVectorAlloc(numData, PS_TYPE_S8);
+        for (psS32 i=0;i<numData;i++) {
+            errors->data.S8[i] = (psS8) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original errors data %d: (%d)\n", i, errors->data.S8[i]);
+            }
+        }
+    }
+
+    if (flags & TST_ERRORS_U16) {
+        printf("        using a psU16 errors vector\n");
+        errors = psVectorAlloc(numData, PS_TYPE_U16);
+        for (psS32 i=0;i<numData;i++) {
+            errors->data.U16[i] = (psU16) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original errors data %d: (%d)\n", i, errors->data.U16[i]);
+            }
+        }
+    }
+
+    if (flags & TST_ERRORS_S32) {
+        printf("        using a psS32 errors vector\n");
+        errors = psVectorAlloc(numData, PS_TYPE_S32);
+        for (psS32 i=0;i<numData;i++) {
+            errors->data.S32[i] = (psS32) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original errors data %d: (%d)\n", i, errors->data.S32[i]);
+            }
+        }
+    }
+
+
+    if (flags & TST_MASK_NULL) {
+        printf("        using a NULL mask vector\n");
+    }
+
+    if (flags & TST_MASK_U8) {
+        printf("        using a psU8 mask vector\n");
+        mask = psVectorAlloc(numData, PS_TYPE_U8);
+        for (psS32 i=0;i<numData;i++) {
+            mask->data.U8[i] = (psU8) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original mask data %d: (%d)\n", i, mask->data.U8[i]);
+            }
+        }
+    }
+
+    if (flags & TST_MASK_S32) {
+        printf("        using a psS32 mask vector\n");
+        mask = psVectorAlloc(numData, PS_TYPE_S32);
+        for (psS32 i=0;i<numData;i++) {
+            mask->data.S32[i] = (psS32) i;
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original mask data %d: (%d)\n", i, mask->data.S32[i]);
+            }
+        }
+    }
+
+    psStats *myStats = psStatsAlloc(PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV);
+    psStats *rc = psVectorStats(myStats, in, errors, mask, maskValue);
+
+    if (rc == NULL) {
+        if (expectedRC == true) {
+            printf("TEST ERROR: the psVectorStats() function returned NULL.\n");
+            testStatus = false;
+        }
+    } else {
+        if (expectedRC == false) {
+            printf("TEST ERROR: the psVectorStats() function returned non-NULL.\n");
+            testStatus = false;
+        }
+
+    }
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    return(testStatus);
+}
+
+
+
 
 psS32 main()
@@ -38,129 +283,3 @@
     psTraceSetLevel("psVectorStats", 0);
 
-    psStats *myStats    = NULL;
-    psS32 testStatus      = true;
-    psS32 globalTestStatus = true;
-    psS32 i               = 0;
-    psVector *maskVector= NULL;
-    psVector *myGaussData  = NULL;
-    // NOTE: These values were calculated by running the function on the data.
-    // A: They must be changed if we adjust the number of data points.
-    // B: We don't really know that they are correct.
-    //    float realclippedMeanNoMask  = 0.0;
-    //    float realclippedStdevNoMask = 0.0;
-    //    float realclippedMeanWithMask  = 0.0;
-    //    float realclippedStdevWithMask = 0.0;
-    psS32 count           = 0;
-    psS32 currentId       = psMemGetId();
-    psS32 memLeaks        = 0;
-
-    /*************************************************************************/
-    /*  Allocate and initialize data structures                      */
-    /*************************************************************************/
-    myStats = psStatsAlloc(PS_STAT_CLIPPED_MEAN |
-                           PS_STAT_CLIPPED_STDEV);
-
-    myGaussData = psVectorAlloc(N, PS_TYPE_F32);
-    myGaussData->n = myGaussData->nalloc;
-    for (i=0;i<N;i++) {
-        myGaussData->data.F32[i] = MY_MEAN - (MY_RANGE/1.9) +
-                                   (MY_RANGE) * ((float) i) / ((float) N);
-    }
-
-    maskVector = psVectorAlloc(N, PS_TYPE_U8);
-    maskVector->n = N;
-
-    // Set the mask vector and calculate the expected maximum.
-    for (i=0;i<N;i++) {
-        if (i < (N/2)) {
-            maskVector->data.U8[i] = 0;
-            count++;
-        } else {
-            maskVector->data.U8[i] = 1;
-        }
-    }
-
-    /*************************************************************************/
-    /*  Call psVectorStats() with no vector mask.                    */
-    /*************************************************************************/
-    printPositiveTestHeader(stdout,
-                            "psStats functions",
-                            "PS_STAT_CLIPPED_MEAN: no vector mask");
-
-    myStats = psVectorStats(myStats, myGaussData, NULL, NULL, 0);
-
-    printf("Called psVectorStats() on a vector with no elements masked.\n");
-    printf("The calculated clippedMean was %.2f\n", myStats->clippedMean);
-
-    printFooter(stdout,
-                "psVector functions",
-                "PS_STAT_CLIPPED_MEAN/STDEV: no vector mask",
-                testStatus);
-
-
-
-    printPositiveTestHeader(stdout,
-                            "psStats functions",
-                            "PS_STAT_CLIPPED_STDEV: no vector mask");
-
-    printf("Called psVectorStats() on a vector with no elements masked.\n");
-    printf("The calculated clippedStdev was %.2f\n", myStats->clippedStdev);
-
-    printFooter(stdout,
-                "psVector functions",
-                "PS_STAT_CLIPPED_MEAN/STDEV: no vector mask",
-                testStatus);
-
-    /*************************************************************************/
-    /*  Call psVectorStats() with vector mask.                       */
-    /*************************************************************************/
-    printPositiveTestHeader(stdout,
-                            "psStats functions",
-                            "PS_STAT_CLIPPED_MEAN: vector mask");
-
-    myStats = psVectorStats(myStats, myGaussData, NULL, maskVector, 1);
-
-    printf("Called psVectorStats() on a vector with elements masked.\n");
-    printf("The calculated clippedMean was %.2f\n", myStats->clippedMean);
-    printFooter(stdout,
-                "psVector functions",
-                "PS_STAT_CLIPPED_MEAN/STDEV: vector mask",
-                testStatus);
-
-
-
-    printPositiveTestHeader(stdout,
-                            "psStats functions",
-                            "PS_STAT_CLIPPED_STDEV: vector mask");
-
-    printf("Called psVectorStats() on a vector with elements masked.\n");
-    printf("The calculated clippedStdev was %.2f\n", myStats->clippedStdev);
-    printFooter(stdout,
-                "psVector functions",
-                "PS_STAT_CLIPPED_MEAN/STDEV: vector mask",
-                testStatus);
-
-    /*************************************************************************/
-    /*  Deallocate data structures                                   */
-    /*************************************************************************/
-    printPositiveTestHeader(stdout,
-                            "psStats functions",
-                            "psStats(): deallocating memory");
-
-    psFree(myStats);
-    psFree(myGaussData);
-    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);
 }
