Index: trunk/psLib/test/dataManip/tst_psMinimize06.c
===================================================================
--- trunk/psLib/test/dataManip/tst_psMinimize06.c	(revision 2155)
+++ trunk/psLib/test/dataManip/tst_psMinimize06.c	(revision 2197)
@@ -74,6 +74,96 @@
 }
 
-
-int main()
+psVector *myFunc2(psImage *myDeriv,
+                  psVector *myParams,
+                  psArray *myCoords)
+{
+    psVector *sum = psVectorAlloc(myCoords->n, PS_TYPE_F32);
+    int i;
+    int j;
+
+
+    if (myDeriv == NULL) {
+        myDeriv = psImageAlloc(myParams->n, myCoords->n, PS_TYPE_F32);
+        psError(__func__, "myDeriv is NULL.\n");
+    }
+
+    for (i=0;i<N;i++) {
+        sum->data.F32[i] = MIN_VALUE;
+        for (j=0;j<NUM_PARAMS;j++) {
+            sum->data.F32[i]+= (myParams->data.F32[j] - expectedParm[j]) *
+                               (myParams->data.F32[j] - expectedParm[j]);
+
+            myDeriv->data.F32[i][j] = (2.0 * myParams->data.F32[j]) -
+                                      (2.0 * expectedParm[j]);
+        }
+    }
+
+    return(sum);
+}
+
+int t01()
+{
+    int currentId = psMemGetId();
+    int memLeaks = 0;
+    int i = 0;
+    psArray *myCoords;
+    psVector *myParams;
+    psImage *myCovar;
+    psMinimization *min;
+    psVector *y;
+
+    psTraceSetLevel(".psLib", 0);
+    /**************************************************************************
+     *************************************************************************/
+    min = psMinimizationAlloc(NUM_ITERATIONS, ERR_TOL);
+    myCovar = psImageAlloc(NUM_PARAMS, NUM_PARAMS, PS_TYPE_F32);
+    myParams = psVectorAlloc(NUM_PARAMS, PS_TYPE_F32);
+    myCoords = psArrayAlloc(N);
+    y = psVectorAlloc(N, PS_TYPE_F32);
+
+    for (i=0;i<N;i++) {
+        myCoords->data[i] = (psPTR *) psVectorAlloc(2, PS_TYPE_F32);
+        ((psVector *) (myCoords->data[i]))->data.F32[0] = (float) (i+10);
+        ((psVector *) (myCoords->data[i]))->data.F32[1] = (float) (i+3);
+        y->data.F32[i] = (float) i;
+    }
+    for (i=0;i<NUM_PARAMS;i++) {
+        expectedParm[i] = 2.42 + (float) (2 * i);
+        myParams->data.F32[i] = (float) i;
+        myParams->data.F32[i] = expectedParm[i] * 1.3;
+        myParams->data.F32[i] = (float) (5 + i);
+        myParams->data.F32[i] = 0.0;
+    }
+
+    psMyMinimizeLMChi2(min,
+                       myCovar,
+                       myParams,
+                       NULL,
+                       myCoords,
+                       y,
+                       NULL,
+                       (psMyMinimizeLMChi2Func) myFunc2);
+
+    printf("\nThe chi-squared is %f\n", min->value);
+    for (i=0;i<NUM_PARAMS;i++) {
+        printf("Parameter %d at the minimum is %f (expected: %f)\n", i,
+               myParams->data.F32[i], expectedParm[i]);
+    }
+
+    psFree(min);
+    psFree(myCovar);
+    psFree(myParams);
+    psFree(myCoords);
+    psFree(y);
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,NULL);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+    return (!testStatus);
+}
+
+int t02()
 {
     int currentId = psMemGetId();
@@ -85,8 +175,8 @@
     psImage *myCovar;
     psMinimization *min;
-    psVector *x = psVectorAlloc(N, PS_TYPE_F32);
     psVector *y = psVectorAlloc(N, PS_TYPE_F32);
 
     psTraceSetLevel(".psLib", 0);
+    t02();
     /**************************************************************************
      *************************************************************************/
@@ -101,5 +191,4 @@
         ((psVector *) (myCoords->data[i]))->data.F32[0] = (float) (i+10);
         ((psVector *) (myCoords->data[i]))->data.F32[1] = (float) (i+3);
-        x->data.F32[i] = (float) i;
         y->data.F32[i] = (float) i;
     }
@@ -131,5 +220,4 @@
     psFree(myParamMask);
     psFree(min);
-    psFree(x);
     psFree(y);
     psFree(myCovar);
@@ -142,2 +230,8 @@
     return (!testStatus);
 }
+
+int main()
+{
+    t01();
+    //    t02();
+}
Index: trunk/psLib/test/dataManip/tst_psStats07.c
===================================================================
--- trunk/psLib/test/dataManip/tst_psStats07.c	(revision 2155)
+++ trunk/psLib/test/dataManip/tst_psStats07.c	(revision 2197)
@@ -10,10 +10,10 @@
 #include <math.h>
 
-#define N 200
+#define N 90
 #define MEAN 32.0
 #define STDEV 2.0
 #define ERROR_TOLERANCE 0.10
 
-int main()
+int t00()
 {
     psStats * myStats = NULL;
@@ -32,18 +32,11 @@
     float realMedianNoMask = MEAN;
     float realModeNoMask = MEAN;
-    float realStdevNoMask = STDEV * 0.33;
+    float realStdevNoMask = STDEV * 0.20;
     float realLQNoMask = MEAN - ( 0.6 * STDEV );
     float realUQNoMask = MEAN + ( 0.6 * STDEV );
     int realN50NoMask = N / 4;
     int realNfitNoMask = N / 4;
-    float realMeanWithMask = MEAN;
-    float realMedianWithMask = MEAN;
-    float realModeWithMask = MEAN;
-    float realStdevWithMask = STDEV;
-    float realLQWithMask = MEAN;
-    float realUQWithMask = MEAN;
-    int realN50WithMask = N / 4;
-    int realNfitWithMask = N / 4;
-
+
+    psTraceSetLevel(".psLib.dataManip.psStats", 10);
 
     /*************************************************************************/
@@ -232,7 +225,78 @@
                  "PS_STAT_ROBUST_STATS: robust Nfit: no vector mask",
                  testStatus );
-
-
-    return ( 0 );
+    return(testStatus);
+
+    /*************************************************************************/
+    /*  Deallocate data structures                                           */
+    /*************************************************************************/
+    printPositiveTestHeader( stdout,
+                             "psStats functions",
+                             "psStats(): deallocating memory" );
+
+    psFree( myStats );
+    psFree( myVector );
+    psFree( maskVector );
+
+    psMemCheckCorruption( 1 );
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
+    if ( 0 != memLeaks ) {
+        psAbort( __func__, "Memory Leaks! (%d leaks)", memLeaks );
+    }
+
+    printFooter( stdout,
+                 "psVector functions",
+                 "psStats(): deallocating memory",
+                 testStatus );
+
+    return ( !globalTestStatus );
+}
+
+
+int t01()
+{
+    psStats * myStats = NULL;
+    int testStatus = true;
+    int globalTestStatus = true;
+    int i = 0;
+    psVector *myVector = NULL;
+    psVector *maskVector = 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.
+    int count = 0;
+    int currentId = psMemGetId();
+    int memLeaks = 0;
+    float realMeanWithMask = MEAN;
+    float realMedianWithMask = MEAN;
+    float realModeWithMask = MEAN;
+    float realStdevWithMask = STDEV * 0.20;
+    float realLQWithMask = MEAN;
+    float realUQWithMask = MEAN;
+    int realN50WithMask = N / 4;
+    int realNfitWithMask = N / 4;
+
+    psTraceSetLevel(".psLib.dataManip.psStats", 10);
+
+    /*************************************************************************/
+    /*  Allocate and initialize data structures                              */
+    /*************************************************************************/
+    myStats = psStatsAlloc( PS_STAT_ROBUST_MEAN |
+                            PS_STAT_ROBUST_MEDIAN |
+                            PS_STAT_ROBUST_MODE |
+                            PS_STAT_ROBUST_STDEV |
+                            PS_STAT_ROBUST_QUARTILE );
+
+    maskVector = psVectorAlloc( N, PS_TYPE_U8 );
+    maskVector->n = N;
+    myVector = psGaussianDev( MEAN, STDEV, 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;
+        }
+    }
 
     /*************************************************************************/
@@ -422,2 +486,8 @@
     return ( !globalTestStatus );
 }
+
+int main()
+{
+    t00();
+    t01();
+}
