Index: trunk/psLib/test/dataManip/tst_psMinimize04.c
===================================================================
--- trunk/psLib/test/dataManip/tst_psMinimize04.c	(revision 1907)
+++ trunk/psLib/test/dataManip/tst_psMinimize04.c	(revision 1945)
@@ -1,4 +1,14 @@
 /*****************************************************************************
-    This routine must ensure that the psVectorFitPolynomial1D works correctly.
+This routine must ensure that the psVectorFitPolynomial1D works correctly.
+We create a vectors of data points (x and y), and populate them with the
+values from an arbitrary function setData().  We then call
+psVectorFitPolynomial1D() with a regular polynomial data structure.  We then
+evaluate the polynomial with the coefficients generated above and determine
+if they are within an error tolerance of the expected values.
+ 
+    t00(): all input vectors are non-NULL.
+    t01(): yErr is NULL.
+    t02(): x, yErr is NULL.
+    t03(): x, y, yErr is NULL.
  *****************************************************************************/
 #include <stdio.h>
@@ -13,14 +23,15 @@
 #define NUM_DATA 10
 #define POLY_ORDER 5
-
-double setData(double A,
-               double B,
-               double C,
-               double x)
+#define A 3.0
+#define B 2.0
+#define C 3.0
+#define ERROR_TOLERANCE 0.10
+#define YERR 10.0
+double setData(double x)
 {
     return(A + (B * x) + (C * x * x));
 }
 
-int main()
+int t00()
 {
     psPolynomial1D *myPoly = NULL;
@@ -32,4 +43,6 @@
     int testStatus = true;
     int memLeaks = 0;
+    double expectData;
+    double actualData;
 
     myPoly = psPolynomial1DAlloc(POLY_ORDER+1, PS_POLYNOMIAL_ORD);
@@ -40,8 +53,12 @@
     for (i=0;i<NUM_DATA;i++) {
         x->data.F64[i] = (double) i;
-        y->data.F64[i] = setData(3.0, 2.0, 3.0, x->data.F64[i]);
-        yErr->data.F64[i] = 0.1;
+        y->data.F64[i] = setData(x->data.F64[i]);
+        yErr->data.F64[i] = YERR;
         printf("Original data %d: (%.1f %.1f)\n", i, x->data.F64[i], y->data.F64[i]);
     }
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): equal errors in yErr");
 
     psVectorFitPolynomial1D(myPoly, x, y, yErr);
@@ -52,15 +69,15 @@
 
     for (i=0;i<NUM_DATA;i++) {
-        printf("Fitted data %d: (%.1f %.1f)\n", i, x->data.F64[i],
-               setData(myPoly->coeff[0], myPoly->coeff[1],
-                       myPoly->coeff[2], x->data.F64[i]));
-    }
-
-
-    psMemCheckCorruption(1);
-    printFooter(stdout,
-                "psMinimize functions",
-                "psMinimize(): no masks",
-                testStatus);
+        expectData = setData(x->data.F64[i]);
+        actualData = psPolynomial1DEval(x->data.F64[i], myPoly);
+        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
+            printf("ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                   i, x->data.F64[i], actualData, expectData);
+            testStatus = false;
+        } else {
+            printf("Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                   i, x->data.F64[i], actualData, expectData);
+        }
+    }
 
     psMemCheckCorruption(1);
@@ -69,11 +86,173 @@
     psFree(y);
     psFree(yErr);
-
-    psMemCheckCorruption(1);
-    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
-    if (0 != memLeaks) {
-        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
-    }
-
-    return (!testStatus);
-}
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): equal errors in yErr",
+                testStatus);
+
+    return (!testStatus);
+}
+
+int t01()
+{
+    psPolynomial1D *myPoly = NULL;
+    psVector *x = NULL;
+    psVector *y = NULL;
+    int i = 0;
+    int currentId = psMemGetId();
+    int testStatus = true;
+    int memLeaks = 0;
+    double expectData;
+    double actualData;
+
+    myPoly = psPolynomial1DAlloc(POLY_ORDER+1, PS_POLYNOMIAL_ORD);
+    x = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
+    y = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
+
+    for (i=0;i<NUM_DATA;i++) {
+        x->data.F64[i] = (double) i;
+        y->data.F64[i] = setData(x->data.F64[i]);
+        printf("Original data %d: (%.1f %.1f)\n", i, x->data.F64[i], y->data.F64[i]);
+    }
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): yErr is NULL");
+
+    psVectorFitPolynomial1D(myPoly, x, y, NULL);
+
+    for (i=0;i<POLY_ORDER+1;i++) {
+        printf("Polynomial coefficient %d is %0.1f\n", i, myPoly->coeff[i]);
+    }
+
+    for (i=0;i<NUM_DATA;i++) {
+        expectData = setData(x->data.F64[i]);
+        actualData = psPolynomial1DEval(x->data.F64[i], myPoly);
+        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
+            printf("ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                   i, x->data.F64[i], actualData, expectData);
+            testStatus = false;
+        } else {
+            printf("Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                   i, x->data.F64[i], actualData, expectData);
+        }
+    }
+
+    psMemCheckCorruption(1);
+    psFree(myPoly);
+    psFree(x);
+    psFree(y);
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): yErr is NULL",
+                testStatus);
+
+    return (!testStatus);
+}
+
+int t02()
+{
+    psPolynomial1D *myPoly = NULL;
+    psVector *y = NULL;
+    int i = 0;
+    int currentId = psMemGetId();
+    int testStatus = true;
+    int memLeaks = 0;
+    double expectData;
+    double actualData;
+
+    myPoly = psPolynomial1DAlloc(POLY_ORDER+1, PS_POLYNOMIAL_ORD);
+    y = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
+
+    for (i=0;i<NUM_DATA;i++) {
+        y->data.F64[i] = setData((double) i);
+        printf("Original data %d: (%.1f)\n", i, y->data.F64[i]);
+    }
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): x, yErr is NULL");
+
+    psVectorFitPolynomial1D(myPoly, NULL, y, NULL);
+
+    for (i=0;i<POLY_ORDER+1;i++) {
+        printf("Polynomial coefficient %d is %0.1f\n", i, myPoly->coeff[i]);
+    }
+
+    for (i=0;i<NUM_DATA;i++) {
+        expectData = setData((double) i);
+        actualData = psPolynomial1DEval((double) i, myPoly);
+        if (fabs(actualData-expectData) > fabs(ERROR_TOLERANCE * expectData)) {
+            printf("ERROR: Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                   i, (double) i, actualData, expectData);
+            testStatus = false;
+        } else {
+            printf("Fitted data %d: (%.1f %.1f), expected was (%.1f)\n",
+                   i, (double) i, actualData, expectData);
+        }
+    }
+
+    psMemCheckCorruption(1);
+    psFree(myPoly);
+    psFree(y);
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): x, yErr is NULL",
+                testStatus);
+
+    return (!testStatus);
+}
+
+int t03()
+{
+    int currentId = psMemGetId();
+    int testStatus = true;
+    int memLeaks = 0;
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): all inputs are NULL");
+
+    psVectorFitPolynomial1D(NULL, NULL, NULL, NULL);
+
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): all inputs are NULL",
+                testStatus);
+
+    return (!testStatus);
+}
+
+
+int main()
+{
+    t00();
+    t01();
+    t02();
+    t03();
+}
