Index: trunk/psLib/test/dataManip/tst_psMinimize04b.c
===================================================================
--- trunk/psLib/test/dataManip/tst_psMinimize04b.c	(revision 1919)
+++ trunk/psLib/test/dataManip/tst_psMinimize04b.c	(revision 1945)
@@ -11,5 +11,5 @@
 #include "psMinimize.h"
 #include <math.h>
-#define NUM_DATA 15
+#define NUM_DATA 20
 #define POLY_ORDER 10
 #define A 2.0
@@ -18,4 +18,6 @@
 #define D 4.0
 #define E 5.0
+#define ERROR_TOLERANCE 0.10
+#define IGNORE (ERROR_TOLERANCE * NUM_DATA)
 
 double setData(double x)
@@ -24,5 +26,5 @@
 }
 
-int main()
+int t00()
 {
     psPolynomial1D *myPoly = NULL;
@@ -31,8 +33,7 @@
     psVector *yErr = NULL;
     int i = 0;
-    //    int currentId = psMemGetId();
-    int testStatus = true;
-    int memLeaks = 0;
-    float sum=0.0;
+    int currentId = psMemGetId();
+    int testStatus = true;
+    int memLeaks = 0;
 
     myPoly = psPolynomial1DAlloc(POLY_ORDER+1, PS_POLYNOMIAL_CHEB);
@@ -47,22 +48,8 @@
     }
     p_psNormalizeVectorF64(x);
-    for (i=0;i<NUM_DATA;i++) {
-        //        printf("Original data %d: (%.1f %.1f)\n", i, x->data.F64[i], y->data.F64[i]);
-    }
-
-    sum=0.0;
-    for (i=0;i<NUM_DATA;i++)
-        sum+=y->data.F64[i];
-    printf("c0 is %f\n", 2.0 * sum/((float) NUM_DATA));
-
-    sum=0.0;
-    for (i=0;i<NUM_DATA;i++)
-        sum+=y->data.F64[i] * x->data.F64[i];
-    printf("c1 is %f\n", 2.0 * sum/((float) NUM_DATA));
-    sum=0.0;
-
-    for (i=0;i<NUM_DATA;i++)
-        sum+=y->data.F64[i] * ((2.0 * x->data.F64[i] * x->data.F64[i]) - 1.0);
-    printf("c2 is %f\n", 2.0 * sum/((float) NUM_DATA));
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): CHEB, equal errors in yErr");
 
     psVectorFitPolynomial1D(myPoly, x, y, yErr);
@@ -72,28 +59,186 @@
     }
 
-    for (i=0;i<NUM_DATA;i++) {
-        printf("Fitted data %d: (%.1f %.1f) should be %.1f\n", i, x->data.F64[i],
-               psPolynomial1DEval((float) x->data.F64[i], myPoly), y->data.F64[i]);
-    }
-
-
-    //    psMemCheckCorruption(1);
-    printFooter(stdout,
-                "psMinimize functions",
-                "psMinimize(): no masks",
-                testStatus);
-
-    //    psMemCheckCorruption(1);
+    // We don't test the first or last few data items.
+    for (i=IGNORE;i<NUM_DATA-IGNORE;i++) {
+        double expectData = y->data.F64[i];
+        double 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);
     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(): CHEB, 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;
+
+    myPoly = psPolynomial1DAlloc(POLY_ORDER+1, PS_POLYNOMIAL_CHEB);
+    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]);
+    }
+    p_psNormalizeVectorF64(x);
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): CHEB, yErr is NULL");
+
+    psVectorFitPolynomial1D(myPoly, x, y, NULL);
+
+    // We don't test the first or last few data items.
+    for (i=IGNORE;i<NUM_DATA-IGNORE;i++) {
+        double expectData = y->data.F64[i];
+        double 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(): CHEB, yErr is NULL",
+                testStatus);
+    return (!testStatus);
+}
+
+
+int t02()
+{
+    psPolynomial1D *myPoly = NULL;
+    psVector *x = NULL;
+    psVector *y = NULL;
+    int i = 0;
+    int currentId = psMemGetId();
+    int testStatus = true;
+    int memLeaks = 0;
+
+    myPoly = psPolynomial1DAlloc(POLY_ORDER+1, PS_POLYNOMIAL_CHEB);
+    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]);
+    }
+    p_psNormalizeVectorF64(x);
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): CHEB, x, yErr is NULL");
+
+    psVectorFitPolynomial1D(myPoly, NULL, y, NULL);
+
+    // We don't test the first or last few data items.
+    for (i=IGNORE;i<NUM_DATA-IGNORE;i++) {
+        double expectData = y->data.F64[i];
+        double 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(): CHEB, x, yErr is NULL",
+                testStatus);
+    return (!testStatus);
+}
+
+int t03()
+{
+    psPolynomial1D *myPoly = NULL;
+    int currentId = psMemGetId();
+    int testStatus = true;
+    int memLeaks = 0;
+
+    printPositiveTestHeader(stdout,
+                            "psMinimize functions",
+                            "psVectorFitPolynomial1D(): CHEB, yErr is NULL");
+
+    myPoly = psVectorFitPolynomial1D(NULL, NULL, NULL, NULL);
+    if (myPoly != NULL) {
+        printf("ERROR: psVectorFitPolynomial1D() returned a non-NULL polynomial.\n");
+        testStatus = false;
+    }
+
+    psMemCheckCorruption(1);
+    memLeaks = psMemCheckLeaks(currentId,NULL,stderr);
+    if (0 != memLeaks) {
+        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
+    }
+    printFooter(stdout,
+                "psMinimize functions",
+                "psVectorFitPolynomial1D(): CHEB, yErr is NULL",
+                testStatus);
+    return (!testStatus);
+}
+
+int main()
+{
+    t00();
+    t01();
+    t02();
+    t03();
+}
