Index: trunk/psLib/test/math/tst_psStats09.c
===================================================================
--- trunk/psLib/test/math/tst_psStats09.c	(revision 6484)
+++ trunk/psLib/test/math/tst_psStats09.c	(revision 7131)
@@ -14,8 +14,8 @@
 
 #define NUM_DATA 1000
-#define VERBOSE 0
+#define VERBOSE 1
 #define PERCENT_OUTLIERS 2
 #define ERROR_TOLERANCE .10
-#define ERRORS 1000.0
+#define ERRORS 1.0
 #define SEED 1995
 
@@ -52,4 +52,12 @@
     printPositiveTestHeader(stdout, "psMathUtils functions", "psVectorStats Clipped Stats Routine");
 
+    psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 1); // Random number generator; using known seed
+    psVector *truth = psVectorAlloc(numData, PS_TYPE_F64);
+    truth->n = numData;
+    for (long i = 0; i < numData; i++) {
+        truth->data.F64[i] = psRandomGaussian(rng);
+    }
+    psFree(rng);
+
     if (expectedRC == true) {
         printf("This test should not generate any errors.\n");
@@ -65,10 +73,5 @@
     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;
-            in->n++;
-        }
-
+        in = psVectorCopy(in, truth, PS_TYPE_F32);
         if (VERBOSE) {
             for (psS32 i=0;i<numData;i++) {
@@ -80,9 +83,5 @@
     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;
-            in->n++;
-        }
+        in = psVectorCopy(in, truth, PS_TYPE_F64);
 
         if (VERBOSE) {
@@ -95,9 +94,5 @@
     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;
-            in->n++;
-        }
+        in = psVectorCopy(in, truth, PS_TYPE_S8);
 
         if (VERBOSE) {
@@ -110,9 +105,5 @@
     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;
-            in->n++;
-        }
+        in = psVectorCopy(in, truth, PS_TYPE_U16);
 
         if (VERBOSE) {
@@ -125,9 +116,5 @@
     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;
-            in->n++;
-        }
+        in = psVectorCopy(in, truth, PS_TYPE_S32);
 
         if (VERBOSE) {
@@ -252,4 +239,81 @@
     }
 
+
+    //
+    // We add a few outliers to the input data.
+    //
+    psVector *outliers = psVectorAlloc(numData, PS_TYPE_U8);
+    outliers->n = numData;
+    psVectorInit(outliers, 0);
+    if (flags & TST_IN_F32) {
+        for (psS32 i=0;i<numData;i++) {
+            if (PERCENT_OUTLIERS > (random() % 100)) {
+                in->data.F32[i] = 100.0;
+                outliers->data.U8[i] = 1;
+            }
+        }
+
+        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) {
+        for (psS32 i=0;i<numData;i++) {
+            if (PERCENT_OUTLIERS > (random() % 100)) {
+                in->data.F64[i] = 100.0;
+                outliers->data.U8[i] = 1;
+            }
+        }
+
+        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) {
+        for (psS32 i=0;i<numData;i++) {
+            if (PERCENT_OUTLIERS > (random() % 100)) {
+                in->data.S8[i] = 100;
+                outliers->data.U8[i] = 1;
+            }
+        }
+
+        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) {
+        for (psS32 i=0;i<numData;i++) {
+            if (PERCENT_OUTLIERS > (random() % 100)) {
+                in->data.U16[i] = 100;
+                outliers->data.U8[i] = 1;
+            }
+        }
+
+        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) {
+        for (psS32 i=0;i<numData;i++) {
+            if (PERCENT_OUTLIERS > (random() % 100)) {
+                in->data.S32[i] = 100;
+                outliers->data.U8[i] = 1;
+            }
+        }
+
+        if (VERBOSE) {
+            for (psS32 i=0;i<numData;i++) {
+                printf("Original in data %d: (%d)\n", i, in->data.S32[i]);
+            }
+        }
+    }
 
     //
@@ -261,5 +325,5 @@
     if (expectedRC == true) {
         psStats *myStats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV);
-        psStats *rc = psVectorStats(myStats, in, NULL, NULL, maskValue);
+        psStats *rc = psVectorStats(myStats, in, errors, outliers, 1);
         if (rc == NULL) {
             printf("TEST ERROR: the psVectorStats() function returned NULL.\n");
@@ -271,73 +335,5 @@
         psFree(myStats);
     }
-
-    //
-    // We add a few outliers to the input data.
-    //
-    if (flags & TST_IN_F32) {
-        for (psS32 i=0;i<numData;i++) {
-            if (PERCENT_OUTLIERS > (random() % 100)) {
-                in->data.F32[i] = (psF32) (10 * numData);
-            }
-        }
-
-        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) {
-        for (psS32 i=0;i<numData;i++) {
-            if (PERCENT_OUTLIERS > (random() % 100)) {
-                in->data.F64[i] = (psF64) (10 * numData);
-            }
-        }
-
-        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) {
-        for (psS32 i=0;i<numData;i++) {
-            if (PERCENT_OUTLIERS > (random() % 100)) {
-                in->data.S8[i] = (psS8) (10 * numData);
-            }
-        }
-
-        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) {
-        for (psS32 i=0;i<numData;i++) {
-            if (PERCENT_OUTLIERS > (random() % 100)) {
-                in->data.U16[i] = (psU16) (10 * numData);
-            }
-        }
-
-        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) {
-        for (psS32 i=0;i<numData;i++) {
-            if (PERCENT_OUTLIERS > (random() % 100)) {
-                in->data.S32[i] = (psS32) (10 * numData);
-            }
-        }
-
-        if (VERBOSE) {
-            for (psS32 i=0;i<numData;i++) {
-                printf("Original in data %d: (%d)\n", i, in->data.S32[i]);
-            }
-        }
-    }
+    psFree(outliers);
 
     //
@@ -345,4 +341,5 @@
     //
     psStats *myStats = psStatsAlloc(PS_STAT_CLIPPED_MEAN | PS_STAT_CLIPPED_STDEV);
+    myStats->clipSigma = 5.0;
     psStats *rc = psVectorStats(myStats, in, errors, mask, maskValue);
     if (rc == NULL) {
@@ -358,15 +355,15 @@
 
         if (fabs(myStats->clippedMean - sampleMean) > (ERROR_TOLERANCE * sampleMean)) {
-            printf("TEST ERROR: the clipped mean was %.2f, should have been %.2f\n", myStats->clippedMean, sampleMean);
+            printf("TEST ERROR: the clipped mean was %f, should have been %f\n", myStats->clippedMean, sampleMean);
             testStatus = false;
         } else if (VERBOSE) {
-            printf("GOOD: the clipped mean was %.2f, should have been %.2f\n", myStats->clippedMean, sampleMean);
+            printf("GOOD: the clipped mean was %f, should have been %f\n", myStats->clippedMean, sampleMean);
         }
 
         if (fabs(myStats->clippedStdev - sampleStdev) > (ERROR_TOLERANCE * sampleStdev)) {
-            printf("TEST ERROR: the clipped stdev was %.2f, should have been %.2f\n", myStats->clippedStdev, sampleStdev);
+            printf("TEST ERROR: the clipped stdev was %f, should have been %f\n", myStats->clippedStdev, sampleStdev);
             testStatus = false;
         } else if (VERBOSE) {
-            printf("GOOD: the clipped stdev was %.2f, should have been %.2f\n", myStats->clippedStdev, sampleStdev);
+            printf("GOOD: the clipped stdev was %f, should have been %f\n", myStats->clippedStdev, sampleStdev);
         }
 
@@ -374,4 +371,5 @@
 
     psFree(myStats);
+    psFree(truth);
     psFree(in);
     psFree(errors);
