Index: trunk/psLib/test/math/tst_psStats07.c
===================================================================
--- trunk/psLib/test/math/tst_psStats07.c	(revision 6215)
+++ trunk/psLib/test/math/tst_psStats07.c	(revision 6304)
@@ -13,8 +13,9 @@
 #include <math.h>
 
-#define N 90
+#define NUM_DATA 10000
 #define MEAN 32.0
 #define STDEV 2.0
 #define ERROR_TOLERANCE 0.15
+#define PERCENT_OUTLIERS 10
 
 psS32 t00()
@@ -27,7 +28,4 @@
     psVector *myVector = NULL;
     psVector *maskVector = NULL;
-    // NOTE: These values were calculated by running the function on the data.
-    // They must be changed if we adjust the number of data points.
-    // We don't really know that they are correct.
     psS32 count = 0;
     psS32 currentId = psMemGetId();
@@ -35,19 +33,18 @@
     float realMeanNoMask = MEAN;
     float realMedianNoMask = MEAN;
-    //    float realModeNoMask = MEAN;
     float realStdevNoMask = STDEV;
     float realLQNoMask = MEAN - ( 0.6 * STDEV );
     float realUQNoMask = MEAN + ( 0.6 * STDEV );
-    psS32 realN50NoMask = N / 4;
+    psS32 realN50NoMask = NUM_DATA / 4;
 
     /*************************************************************************/
     /*  Allocate and initialize data structures                              */
     /*************************************************************************/
-    maskVector = psVectorAlloc( N, PS_TYPE_U8 );
-    maskVector->n = N;
-    myVector = p_psGaussianDev( MEAN, STDEV, N );
+    maskVector = psVectorAlloc( NUM_DATA, PS_TYPE_U8 );
+    maskVector->n = NUM_DATA;
+    myVector = p_psGaussianDev( MEAN, STDEV, NUM_DATA );
     // Set the mask vector and calculate the expected maximum.
-    for ( i = 0;i < N;i++ ) {
-        if ( i < ( N / 2 ) ) {
+    for ( i = 0;i < NUM_DATA;i++ ) {
+        if ( i < ( NUM_DATA / 2 ) ) {
             maskVector->data.U8[ i ] = 0;
             count++;
@@ -56,4 +53,8 @@
         }
     }
+
+    //
+    // We calculate the exact mean, median, stdev and quartiles with no mask.
+    //
     psStats *mySampleStats = psStatsAlloc( PS_STAT_SAMPLE_MEAN |
                                            PS_STAT_SAMPLE_MEDIAN |
@@ -67,4 +68,7 @@
     psFree(mySampleStats);
 
+    //
+    // We calculate the exact mean, median, stdev and quartiles with mask.
+    //
     psStats *mySampleStatsWithMask = psStatsAlloc( PS_STAT_SAMPLE_MEAN |
                                      PS_STAT_SAMPLE_MEDIAN |
@@ -84,6 +88,9 @@
                            PS_STAT_FITTED_STDEV);
     // Create a full outliers:
-    myVector->data.F32[N/4] = -1000.0 * MEAN;
-    myVector->data.F32[N/2] = 1000.0 * MEAN;
+    for (psS32 i = 0 ; i < NUM_DATA ; i++) {
+        if (PERCENT_OUTLIERS > (random() % 100)) {
+            myVector->data.F32[i] = 1000.0 * MEAN;
+        }
+    }
     /*************************************************************************/
     /*  Call psVectorStats() with no vector mask.                            */
@@ -130,24 +137,4 @@
                  "PS_STAT_ROBUST_STATS: robust Median: no vector mask",
                  testStatus );
-
-    /* XXX: Should we test mode?
-        printPositiveTestHeader( stdout,
-                                 "psStats functions",
-                                 "PS_STAT_ROBUST_STATS: robust Mode: no vector mask" );
-     
-     
-        printf( "The expected Mode was %.2f; the calculated Mode was %.2f\n",
-                realModeNoMask, myStats->robustMode );
-        if ( fabs( myStats->robustMode - realModeNoMask ) < ( ERROR_TOLERANCE * realModeNoMask ) ) {
-            testStatus = true;
-        } else {
-            testStatus = false;
-            globalTestStatus = false;
-        }
-        printFooter( stdout,
-                     "psVector functions",
-                     "PS_STAT_ROBUST_STATS: robust Mode: no vector mask",
-                     testStatus );
-    */
 
     printPositiveTestHeader( stdout,
@@ -268,9 +255,8 @@
     float realMeanWithMask = MEAN;
     float realMedianWithMask = MEAN;
-    //    float realModeWithMask = MEAN;
     float realStdevWithMask = STDEV;
     float realLQWithMask = MEAN;
     float realUQWithMask = MEAN;
-    psS32 realN50WithMask = N / 4;
+    psS32 realN50WithMask = NUM_DATA / 4;
     /*************************************************************************/
     /*  Allocate and initialize data structures                              */
@@ -282,14 +268,19 @@
                            PS_STAT_FITTED_STDEV);
 
-    maskVector = psVectorAlloc( N, PS_TYPE_U8 );
-    maskVector->n = N;
-    myVector = p_psGaussianDev( MEAN, STDEV, N );
+    maskVector = psVectorAlloc( NUM_DATA, PS_TYPE_U8 );
+    maskVector->n = NUM_DATA;
+    myVector = p_psGaussianDev( MEAN, STDEV, NUM_DATA );
     // Set the mask vector and calculate the expected maximum.
-    for ( i = 0;i < N;i++ ) {
-        if ( i < ( N / 2 ) ) {
+    for ( i = 0;i < NUM_DATA;i++ ) {
+        if ( i < ( NUM_DATA / 2 ) ) {
             maskVector->data.U8[ i ] = 0;
             count++;
         } else {
             maskVector->data.U8[ i ] = 1;
+        }
+    }
+    for (psS32 i = 0 ; i < NUM_DATA ; i++) {
+        if (PERCENT_OUTLIERS < (random() % 100)) {
+            myVector->data.F32[i] = 1000.0 * MEAN;
         }
     }
@@ -338,24 +329,4 @@
                  "PS_STAT_ROBUST_STATS: robust Median: with vector mask",
                  testStatus );
-
-
-    /* XXX: mode is not set?
-        printPositiveTestHeader( stdout,
-                                 "psStats functions",
-                                 "PS_STAT_ROBUST_STATS: robust Mode: with vector mask" );
-     
-        printf( "The expected Mode was %.2f; the calculated Mode was %.2f\n",
-                realModeWithMask, myStats->robustMode );
-        if ( fabs( myStats->robustMode - realModeWithMask ) < ( ERROR_TOLERANCE * realModeWithMask ) ) {
-            testStatus = true;
-        } else {
-            testStatus = false;
-            globalTestStatus = false;
-        }
-        printFooter( stdout,
-                     "psVector functions",
-                     "PS_STAT_ROBUST_STATS: robust Mode: with vector mask",
-                     testStatus );
-    */
 
 
@@ -469,24 +440,26 @@
     // We list pertinent psStats.c functions here for debugging ease.
     //
-    psTraceSetLevel(".", 0);
-    psTraceSetLevel("psGaussian", 0);
-    psTraceSetLevel("p_psGetStatValue", 0);
-    psTraceSetLevel("p_psVectorMax", 0);
-    psTraceSetLevel("p_psVectorMin", 0);
-    psTraceSetLevel("p_psVectorCheckNonEmpty", 0);
-    psTraceSetLevel("p_psNormalizeVectorRange", 0);
-    psTraceSetLevel("p_ps1DPolyMedian", 0);
-    psTraceSetLevel("fitQuadraticSearchForYThenReturnX", 0);
-    psTraceSetLevel("PsVectorDup", 0);
-    psTraceSetLevel("psMinimizeLMChi2Gauss1D", 0);
-    psTraceSetLevel("LinInterpolate", 0);
-    psTraceSetLevel("p_psVectorRobustStats", 0);
-    psTraceSetLevel("psStatsAlloc", 0);
-    psTraceSetLevel("psHistogramAlloc", 0);
-    psTraceSetLevel("psHistogramAllocGeneric", 0);
-    psTraceSetLevel("UpdateHistogramBins", 0);
-    psTraceSetLevel("psVectorHistogram", 0);
-    psTraceSetLevel("p_psConvertToF32", 0);
-    psTraceSetLevel("psVectorStats", 0);
+    #define TRACE_LEVEL 0
+
+    psTraceSetLevel(".", TRACE_LEVEL);
+    psTraceSetLevel("psGaussian", TRACE_LEVEL);
+    psTraceSetLevel("p_psGetStatValue", TRACE_LEVEL);
+    psTraceSetLevel("p_psVectorMax", TRACE_LEVEL);
+    psTraceSetLevel("p_psVectorMin", TRACE_LEVEL);
+    psTraceSetLevel("p_psVectorCheckNonEmpty", TRACE_LEVEL);
+    psTraceSetLevel("p_psNormalizeVectorRange", TRACE_LEVEL);
+    psTraceSetLevel("p_ps1DPolyMedian", TRACE_LEVEL);
+    psTraceSetLevel("fitQuadraticSearchForYThenReturnX", TRACE_LEVEL);
+    psTraceSetLevel("PsVectorDup", TRACE_LEVEL);
+    psTraceSetLevel("psMinimizeLMChi2Gauss1D", TRACE_LEVEL);
+    psTraceSetLevel("LinInterpolate", TRACE_LEVEL);
+    psTraceSetLevel("p_psVectorRobustStats", TRACE_LEVEL);
+    psTraceSetLevel("psStatsAlloc", TRACE_LEVEL);
+    psTraceSetLevel("psHistogramAlloc", TRACE_LEVEL);
+    psTraceSetLevel("psHistogramAllocGeneric", TRACE_LEVEL);
+    psTraceSetLevel("UpdateHistogramBins", TRACE_LEVEL);
+    psTraceSetLevel("psVectorHistogram", TRACE_LEVEL);
+    psTraceSetLevel("p_psConvertToF32", TRACE_LEVEL);
+    psTraceSetLevel("psVectorStats", TRACE_LEVEL);
     psBool rc0 = t00();
     psBool rc1 = t01();
