Index: trunk/psLib/test/math/Makefile.am
===================================================================
--- trunk/psLib/test/math/Makefile.am	(revision 13308)
+++ trunk/psLib/test/math/Makefile.am	(revision 13337)
@@ -42,4 +42,5 @@
 	tap_psStats08 \
 	tap_psStats09 \
+	tap_psStats10 \
 	tap_psStatsTiming \
 	tap_psFunc01 \
Index: trunk/psLib/test/math/tap_psPolyFit1D.c
===================================================================
--- trunk/psLib/test/math/tap_psPolyFit1D.c	(revision 13308)
+++ trunk/psLib/test/math/tap_psPolyFit1D.c	(revision 13337)
@@ -109,6 +109,4 @@
     psVector *xTruth = psVectorAlloc(numData, PS_TYPE_F64);
     psVector *fTruth = psVectorAlloc(numData, PS_TYPE_F64);
-    xTruth->n = numData;
-    fTruth->n = numData;
     psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 1); // Using a known seed
     for (int i = 0; i < numData; i++) {
@@ -350,5 +348,248 @@
     psLogSetFormat("HLNM");
     psLogSetLevel(PS_LOG_INFO);
-    plan_tests(64);
+    plan_tests(104);
+
+
+    // psVectorFitPolynomial1D()
+    // Test various erroneous input paramater configurations
+    {
+        psMemId id = psMemGetId();
+        psPolynomial1D *myPoly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, POLY_ORDER);
+        psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *xS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *f = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *fS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *mask = psVectorAlloc(NUM_DATA, PS_TYPE_U8);
+        psVector *maskS8 = psVectorAlloc(NUM_DATA, PS_TYPE_S8);
+        psVector *fErr = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *fErrS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+
+
+        // Set psPolynomial1D to NULL, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial1D(NULL, mask, MASK_VALUE, f, fErr, x);
+            ok(rc == false, "psVectorFitPolynomial1D() returned FALSE with NULL psPolynomial1D");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set mask to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial1D(myPoly, maskS8, MASK_VALUE, f, fErr, x);
+            ok(rc == false, "psVectorFitPolynomial1D() returned FALSE with mask set to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set f psVector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial1D(myPoly, mask, MASK_VALUE, fS32, fErr, x);
+            ok(rc == false, "psVectorFitPolynomial1D() returned FALSE: Set f psVector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set fError vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial1D(myPoly, mask, MASK_VALUE, f, fErrS32, x);
+            ok(rc == false, "psVectorFitPolynomial1D() returned FALSE: Set fError vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set x vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial1D(myPoly, mask, MASK_VALUE, f, fErr, xS32);
+            ok(rc == false, "psVectorFitPolynomial1D() returned FALSE: Set x vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect mask psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            mask->n++;
+            bool rc = psVectorFitPolynomial1D(myPoly, mask, MASK_VALUE, f, fErr, x);
+            mask->n--;
+            ok(rc == false, "psVectorFitPolynomial1D() returned FALSE: Incorrect mask psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect f psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            f->n++;
+            bool rc = psVectorFitPolynomial1D(myPoly, mask, MASK_VALUE, f, fErr, x);
+            f->n--;
+            ok(rc == false, "psVectorFitPolynomial1D() returned FALSE: Incorrect f psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect fErr psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            fErr->n++;
+            bool rc = psVectorFitPolynomial1D(myPoly, mask, MASK_VALUE, f, fErr, x);
+            fErr->n--;
+            ok(rc == false, "psVectorFitPolynomial1D() returned FALSE: Incorrect fErr psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect x psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            x->n++;
+            bool rc = psVectorFitPolynomial1D(myPoly, mask, MASK_VALUE, f, fErr, x);
+            x->n--;
+            ok(rc == false, "psVectorFitPolynomial1D() returned FALSE: Incorrect x psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+        psFree(myPoly);
+        psFree(x);
+        psFree(xS32);
+        psFree(f);
+        psFree(fS32);
+        psFree(mask);
+        psFree(maskS8);
+        psFree(fErr);
+        psFree(fErrS32);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+
+    // psVectorClipFitPolynomial1D()
+    // Test various erroneous input paramater configurations
+    {
+        psMemId id = psMemGetId();
+        psPolynomial1D *myPoly = psPolynomial1DAlloc(PS_POLYNOMIAL_ORD, POLY_ORDER);
+        psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *xS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *f = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *fS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *mask = psVectorAlloc(NUM_DATA, PS_TYPE_U8);
+        psVector *maskS8 = psVectorAlloc(NUM_DATA, PS_TYPE_S8);
+        psVector *fErr = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *fErrS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
+
+
+        // Set psPolynomial1D to NULL, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial1D(NULL, stats, mask, MASK_VALUE, f, fErr, x);
+            ok(rc == false, "psVectorClipFitPolynomial1D() returned FALSE with NULL psPolynomial1D");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set psStats to NULL, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial1D(myPoly, NULL, mask, MASK_VALUE, f, fErr, x);
+            ok(rc == false, "psVectorClipFitPolynomial1D() returned FALSE with NULL psStats");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set mask to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial1D(myPoly, stats, maskS8, MASK_VALUE, f, fErr, x);
+            ok(rc == false, "psVectorClipFitPolynomial1D() returned FALSE with mask set to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set f psVector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial1D(myPoly, stats, mask, MASK_VALUE, fS32, fErr, x);
+            ok(rc == false, "psVectorClipFitPolynomial1D() returned FALSE: Set f psVector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set fError vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial1D(myPoly, stats, mask, MASK_VALUE, f, fErrS32, x);
+            ok(rc == false, "psVectorClipFitPolynomial1D() returned FALSE: Set fError vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set x vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial1D(myPoly, stats, mask, MASK_VALUE, f, fErr, xS32);
+            ok(rc == false, "psVectorClipFitPolynomial1D() returned FALSE: Set x vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect mask psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            mask->n++;
+            bool rc = psVectorClipFitPolynomial1D(myPoly, stats, mask, MASK_VALUE, f, fErr, x);
+            mask->n--;
+            ok(rc == false, "psVectorClipFitPolynomial1D() returned FALSE: Incorrect mask psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect f psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            f->n++;
+            bool rc = psVectorClipFitPolynomial1D(myPoly, stats, mask, MASK_VALUE, f, fErr, x);
+            f->n--;
+            ok(rc == false, "psVectorClipFitPolynomial1D() returned FALSE: Incorrect f psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect fErr psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            fErr->n++;
+            bool rc = psVectorClipFitPolynomial1D(myPoly, stats, mask, MASK_VALUE, f, fErr, x);
+            fErr->n--;
+            ok(rc == false, "psVectorClipFitPolynomial1D() returned FALSE: Incorrect fErr psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect x psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            x->n++;
+            bool rc = psVectorClipFitPolynomial1D(myPoly, stats, mask, MASK_VALUE, f, fErr, x);
+            x->n--;
+            ok(rc == false, "psVectorClipFitPolynomial1D() returned FALSE: Incorrect x psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+        psFree(myPoly);
+        psFree(x);
+        psFree(xS32);
+        psFree(f);
+        psFree(fS32);
+        psFree(mask);
+        psFree(maskS8);
+        psFree(fErr);
+        psFree(fErrS32);
+        psFree(stats);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
 
     //
Index: trunk/psLib/test/math/tap_psPolyFit2D.c
===================================================================
--- trunk/psLib/test/math/tap_psPolyFit2D.c	(revision 13308)
+++ trunk/psLib/test/math/tap_psPolyFit2D.c	(revision 13337)
@@ -364,5 +364,275 @@
     psLogSetFormat("HLNM");
     psLogSetLevel(PS_LOG_INFO);
-    plan_tests(44);
+    plan_tests(88);
+
+
+    // psVectorFitPolynomial2D()
+    // Test various erroneous input paramater configurations
+    {
+        psMemId id = psMemGetId();
+        psPolynomial2D *myPoly = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, POLY_ORDER_X, POLY_ORDER_Y);
+        psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *xS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *yS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *f = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *fS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *mask = psVectorAlloc(NUM_DATA, PS_TYPE_U8);
+        psVector *maskS8 = psVectorAlloc(NUM_DATA, PS_TYPE_S8);
+        psVector *fErr = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *fErrS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+
+
+        // Set psPolynomial2D to NULL, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial2D(NULL, mask, MASK_VALUE, f, fErr, x, y);
+            ok(rc == false, "psVectorFitPolynomial2D() returned FALSE with NULL psPolynomial2D");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set mask to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial2D(myPoly, maskS8, MASK_VALUE, f, fErr, x, y);
+            ok(rc == false, "psVectorFitPolynomial2D() returned FALSE with mask set to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set f psVector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial2D(myPoly, mask, MASK_VALUE, fS32, fErr, x, y);
+            ok(rc == false, "psVectorFitPolynomial2D() returned FALSE: Set f psVector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set fError vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial2D(myPoly, mask, MASK_VALUE, f, fErrS32, x, y);
+            ok(rc == false, "psVectorFitPolynomial2D() returned FALSE: Set fError vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set x vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial2D(myPoly, mask, MASK_VALUE, f, fErr, xS32, y);
+            ok(rc == false, "psVectorFitPolynomial2D() returned FALSE: Set x vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set y vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial2D(myPoly, mask, MASK_VALUE, f, fErr, x, yS32);
+            ok(rc == false, "psVectorFitPolynomial2D() returned FALSE: Set y vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect mask psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            mask->n++;
+            bool rc = psVectorFitPolynomial2D(myPoly, mask, MASK_VALUE, f, fErr, x, y);
+            mask->n--;
+            ok(rc == false, "psVectorFitPolynomial2D() returned FALSE: Incorrect mask psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect f psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            f->n++;
+            bool rc = psVectorFitPolynomial2D(myPoly, mask, MASK_VALUE, f, fErr, x, y);
+            f->n--;
+            ok(rc == false, "psVectorFitPolynomial2D() returned FALSE: Incorrect f psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect fErr psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            fErr->n++;
+            bool rc = psVectorFitPolynomial2D(myPoly, mask, MASK_VALUE, f, fErr, x, y);
+            fErr->n--;
+            ok(rc == false, "psVectorFitPolynomial2D() returned FALSE: Incorrect fErr psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect x psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            x->n++;
+            bool rc = psVectorFitPolynomial2D(myPoly, mask, MASK_VALUE, f, fErr, x, y);
+            x->n--;
+            ok(rc == false, "psVectorFitPolynomial2D() returned FALSE: Incorrect x psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+        psFree(myPoly);
+        psFree(x);
+        psFree(xS32);
+        psFree(y);
+        psFree(yS32);
+        psFree(f);
+        psFree(fS32);
+        psFree(mask);
+        psFree(maskS8);
+        psFree(fErr);
+        psFree(fErrS32);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+
+    // psVectorClipFitPolynomial2D()
+    // Test various erroneous input paramater configurations
+    {
+        psMemId id = psMemGetId();
+        psPolynomial2D *myPoly = psPolynomial2DAlloc(PS_POLYNOMIAL_ORD, POLY_ORDER_X, POLY_ORDER_Y);
+        psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *xS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *yS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *f = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *fS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *mask = psVectorAlloc(NUM_DATA, PS_TYPE_U8);
+        psVector *maskS8 = psVectorAlloc(NUM_DATA, PS_TYPE_S8);
+        psVector *fErr = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *fErrS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
+
+
+        // Set psPolynomial2D to NULL, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial2D(NULL, stats, mask, MASK_VALUE, f, fErr, x, y);
+            ok(rc == false, "psVectorClipFitPolynomial2D() returned FALSE with NULL psPolynomial2D");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set psStats to NULL, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial2D(myPoly, NULL, mask, MASK_VALUE, f, fErr, x, y);
+            ok(rc == false, "psVectorClipFitPolynomial2D() returned FALSE with NULL psStats");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set mask to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial2D(myPoly, stats, maskS8, MASK_VALUE, f, fErr, x, y);
+            ok(rc == false, "psVectorClipFitPolynomial2D() returned FALSE with mask set to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set f psVector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial2D(myPoly, stats, mask, MASK_VALUE, fS32, fErr, x, y);
+            ok(rc == false, "psVectorClipFitPolynomial2D() returned FALSE: Set f psVector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set fError vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial2D(myPoly, stats, mask, MASK_VALUE, f, fErrS32, x, y);
+            ok(rc == false, "psVectorClipFitPolynomial2D() returned FALSE: Set fError vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set x vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial2D(myPoly, stats, mask, MASK_VALUE, f, fErr, xS32, y);
+            ok(rc == false, "psVectorClipFitPolynomial2D() returned FALSE: Set x vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set y vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial2D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, yS32);
+            ok(rc == false, "psVectorClipFitPolynomial2D() returned FALSE: Set y vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect mask psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            mask->n++;
+            bool rc = psVectorClipFitPolynomial2D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y);
+            mask->n--;
+            ok(rc == false, "psVectorClipFitPolynomial2D() returned FALSE: Incorrect mask psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect f psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            f->n++;
+            bool rc = psVectorClipFitPolynomial2D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y);
+            f->n--;
+            ok(rc == false, "psVectorClipFitPolynomial2D() returned FALSE: Incorrect f psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect fErr psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            fErr->n++;
+            bool rc = psVectorClipFitPolynomial2D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y);
+            fErr->n--;
+            ok(rc == false, "psVectorClipFitPolynomial2D() returned FALSE: Incorrect fErr psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect x psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            x->n++;
+            bool rc = psVectorClipFitPolynomial2D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y);
+            x->n--;
+            ok(rc == false, "psVectorClipFitPolynomial2D() returned FALSE: Incorrect x psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+        psFree(myPoly);
+        psFree(x);
+        psFree(xS32);
+        psFree(y);
+        psFree(yS32);
+        psFree(f);
+        psFree(fS32);
+        psFree(mask);
+        psFree(maskS8);
+        psFree(fErr);
+        psFree(fErrS32);
+        psFree(stats);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
 
     //
Index: trunk/psLib/test/math/tap_psPolyFit3D.c
===================================================================
--- trunk/psLib/test/math/tap_psPolyFit3D.c	(revision 13308)
+++ trunk/psLib/test/math/tap_psPolyFit3D.c	(revision 13337)
@@ -414,5 +414,301 @@
     psLogSetFormat("HLNM");
     psLogSetLevel(PS_LOG_INFO);
-    plan_tests(52);
+    plan_tests(100);
+
+
+    // psVectorFitPolynomial3D()
+    // Test various erroneous input paramater configurations
+    {
+        psMemId id = psMemGetId();
+        psPolynomial3D *myPoly = psPolynomial3DAlloc(PS_POLYNOMIAL_ORD, POLY_ORDER_X, POLY_ORDER_Y, POLY_ORDER_Z);
+        psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *xS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *yS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *z = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *zS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *f = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *fS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *mask = psVectorAlloc(NUM_DATA, PS_TYPE_U8);
+        psVector *maskS8 = psVectorAlloc(NUM_DATA, PS_TYPE_S8);
+        psVector *fErr = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *fErrS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+
+
+        // Set psPolynomial3D to NULL, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial3D(NULL, mask, MASK_VALUE, f, fErr, x, y, z);
+            ok(rc == false, "psVectorFitPolynomial3D() returned FALSE with NULL psPolynomial3D");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set mask to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial3D(myPoly, maskS8, MASK_VALUE, f, fErr, x, y, z);
+            ok(rc == false, "psVectorFitPolynomial3D() returned FALSE with mask set to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set f psVector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial3D(myPoly, mask, MASK_VALUE, fS32, fErr, x, y, z);
+            ok(rc == false, "psVectorFitPolynomial3D() returned FALSE: Set f psVector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set fError vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial3D(myPoly, mask, MASK_VALUE, f, fErrS32, x, y, z);
+            ok(rc == false, "psVectorFitPolynomial3D() returned FALSE: Set fError vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set x vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial3D(myPoly, mask, MASK_VALUE, f, fErr, xS32, y, z);
+            ok(rc == false, "psVectorFitPolynomial3D() returned FALSE: Set x vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set y vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial3D(myPoly, mask, MASK_VALUE, f, fErr, x, yS32, z);
+            ok(rc == false, "psVectorFitPolynomial3D() returned FALSE: Set y vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set z vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial3D(myPoly, mask, MASK_VALUE, f, fErr, x, y, zS32);
+            ok(rc == false, "psVectorFitPolynomial3D() returned FALSE: Set z vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect mask psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            mask->n++;
+            bool rc = psVectorFitPolynomial3D(myPoly, mask, MASK_VALUE, f, fErr, x, y, z);
+            mask->n--;
+            ok(rc == false, "psVectorFitPolynomial3D() returned FALSE: Incorrect mask psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect f psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            f->n++;
+            bool rc = psVectorFitPolynomial3D(myPoly, mask, MASK_VALUE, f, fErr, x, y, z);
+            f->n--;
+            ok(rc == false, "psVectorFitPolynomial3D() returned FALSE: Incorrect f psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect fErr psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            fErr->n++;
+            bool rc = psVectorFitPolynomial3D(myPoly, mask, MASK_VALUE, f, fErr, x, y, z);
+            fErr->n--;
+            ok(rc == false, "psVectorFitPolynomial3D() returned FALSE: Incorrect fErr psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect x psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            x->n++;
+            bool rc = psVectorFitPolynomial3D(myPoly, mask, MASK_VALUE, f, fErr, x, y, z);
+            x->n--;
+            ok(rc == false, "psVectorFitPolynomial3D() returned FALSE: Incorrect x psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+        psFree(myPoly);
+        psFree(x);
+        psFree(xS32);
+        psFree(y);
+        psFree(yS32);
+        psFree(z);
+        psFree(zS32);
+        psFree(f);
+        psFree(fS32);
+        psFree(mask);
+        psFree(maskS8);
+        psFree(fErr);
+        psFree(fErrS32);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+
+    // psVectorClipFitPolynomial3D()
+    // Test various erroneous input paramater configurations
+    {
+        psMemId id = psMemGetId();
+        psPolynomial3D *myPoly = psPolynomial3DAlloc(PS_POLYNOMIAL_ORD, POLY_ORDER_X, POLY_ORDER_Y, POLY_ORDER_Z);
+        psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *xS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *yS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *z = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *zS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *f = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *fS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *mask = psVectorAlloc(NUM_DATA, PS_TYPE_U8);
+        psVector *maskS8 = psVectorAlloc(NUM_DATA, PS_TYPE_S8);
+        psVector *fErr = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *fErrS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
+
+
+        // Set psPolynomial3D to NULL, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial3D(NULL, stats, mask, MASK_VALUE, f, fErr, x, y, z);
+            ok(rc == false, "psVectorClipFitPolynomial3D() returned FALSE with NULL psPolynomial3D");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set psStats to NULL, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial3D(myPoly, NULL, mask, MASK_VALUE, f, fErr, x, y, z);
+            ok(rc == false, "psVectorClipFitPolynomial3D() returned FALSE with NULL psStats");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set mask to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial3D(myPoly, stats, maskS8, MASK_VALUE, f, fErr, x, y, z);
+            ok(rc == false, "psVectorClipFitPolynomial3D() returned FALSE with mask set to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set f psVector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial3D(myPoly, stats, mask, MASK_VALUE, fS32, fErr, x, y, z);
+            ok(rc == false, "psVectorClipFitPolynomial3D() returned FALSE: Set f psVector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set fError vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial3D(myPoly, stats, mask, MASK_VALUE, f, fErrS32, x, y, z);
+            ok(rc == false, "psVectorClipFitPolynomial3D() returned FALSE: Set fError vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set x vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial3D(myPoly, stats, mask, MASK_VALUE, f, fErr, xS32, y, z);
+            ok(rc == false, "psVectorClipFitPolynomial3D() returned FALSE: Set x vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set y vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial3D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, yS32, z);
+            ok(rc == false, "psVectorClipFitPolynomial3D() returned FALSE: Set y vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set z vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial3D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y, zS32);
+            ok(rc == false, "psVectorClipFitPolynomial3D() returned FALSE: Set z vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect mask psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            mask->n++;
+            bool rc = psVectorClipFitPolynomial3D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y, z);
+            mask->n--;
+            ok(rc == false, "psVectorClipFitPolynomial3D() returned FALSE: Incorrect mask psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect f psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            f->n++;
+            bool rc = psVectorClipFitPolynomial3D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y, z);
+            f->n--;
+            ok(rc == false, "psVectorClipFitPolynomial3D() returned FALSE: Incorrect f psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect fErr psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            fErr->n++;
+            bool rc = psVectorClipFitPolynomial3D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y, z);
+            fErr->n--;
+            ok(rc == false, "psVectorClipFitPolynomial3D() returned FALSE: Incorrect fErr psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect x psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            x->n++;
+            bool rc = psVectorClipFitPolynomial3D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y, z);
+            x->n--;
+            ok(rc == false, "psVectorClipFitPolynomial3D() returned FALSE: Incorrect x psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+        psFree(myPoly);
+        psFree(x);
+        psFree(xS32);
+        psFree(y);
+        psFree(yS32);
+        psFree(z);
+        psFree(zS32);
+        psFree(f);
+        psFree(fS32);
+        psFree(mask);
+        psFree(maskS8);
+        psFree(fErr);
+        psFree(fErrS32);
+        psFree(stats);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
 
     //
Index: trunk/psLib/test/math/tap_psPolyFit4D.c
===================================================================
--- trunk/psLib/test/math/tap_psPolyFit4D.c	(revision 13308)
+++ trunk/psLib/test/math/tap_psPolyFit4D.c	(revision 13337)
@@ -472,6 +472,328 @@
     psLogSetFormat("HLNM");
     psLogSetLevel(PS_LOG_INFO);
-    plan_tests(60);
-
+    plan_tests(112);
+
+
+    // psVectorFitPolynomial4D()
+    // Test various erroneous input paramater configurations
+    {
+        psMemId id = psMemGetId();
+        psPolynomial4D *myPoly = psPolynomial4DAlloc(PS_POLYNOMIAL_ORD, POLY_ORDER_X, POLY_ORDER_Y, POLY_ORDER_Z, POLY_ORDER_T);
+        psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *xS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *yS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *z = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *zS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *t = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *tS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *f = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *fS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *mask = psVectorAlloc(NUM_DATA, PS_TYPE_U8);
+        psVector *maskS8 = psVectorAlloc(NUM_DATA, PS_TYPE_S8);
+        psVector *fErr = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *fErrS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+
+
+        // Set psPolynomial4D to NULL, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial4D(NULL, mask, MASK_VALUE, f, fErr, x, y, z, t);
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE with NULL psPolynomial4D");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set mask to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial4D(myPoly, maskS8, MASK_VALUE, f, fErr, x, y, z, t);
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE with mask set to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set f psVector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, fS32, fErr, x, y, z, t);
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Set f psVector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set fError vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErrS32, x, y, z, t);
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Set fError vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set x vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, xS32, y, z, t);
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Set x vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set y vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, x, yS32, z, t);
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Set y vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set z vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, x, y, zS32, t);
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Set z vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set t vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, x, y, z, tS32);
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Set t vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect mask psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            mask->n++;
+            bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, x, y, z, t);
+            mask->n--;
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Incorrect mask psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect f psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            f->n++;
+            bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, x, y, z, t);
+            f->n--;
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Incorrect f psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect fErr psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            fErr->n++;
+            bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, x, y, z, t);
+            fErr->n--;
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Incorrect fErr psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect x psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            x->n++;
+            bool rc = psVectorFitPolynomial4D(myPoly, mask, MASK_VALUE, f, fErr, x, y, z, t);
+            x->n--;
+            ok(rc == false, "psVectorFitPolynomial4D() returned FALSE: Incorrect x psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+        psFree(myPoly);
+        psFree(x);
+        psFree(xS32);
+        psFree(y);
+        psFree(yS32);
+        psFree(z);
+        psFree(zS32);
+        psFree(t);
+        psFree(tS32);
+        psFree(f);
+        psFree(fS32);
+        psFree(mask);
+        psFree(maskS8);
+        psFree(fErr);
+        psFree(fErrS32);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+
+    // psVectorClipFitPolynomial4D()
+    // Test various erroneous input paramater configurations
+    {
+        psMemId id = psMemGetId();
+        psPolynomial4D *myPoly = psPolynomial4DAlloc(PS_POLYNOMIAL_ORD, POLY_ORDER_X, POLY_ORDER_Y, POLY_ORDER_Z, POLY_ORDER_T);
+        psVector *x = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *xS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *y = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *yS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *z = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *zS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *t = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *tS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *f = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *fS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psVector *mask = psVectorAlloc(NUM_DATA, PS_TYPE_U8);
+        psVector *maskS8 = psVectorAlloc(NUM_DATA, PS_TYPE_S8);
+        psVector *fErr = psVectorAlloc(NUM_DATA, PS_TYPE_F32);
+        psVector *fErrS32 = psVectorAlloc(NUM_DATA, PS_TYPE_S32);
+        psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
+
+
+        // Set psPolynomial4D to NULL, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial4D(NULL, stats, mask, MASK_VALUE, f, fErr, x, y, z, t);
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE with NULL psPolynomial4D");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set psStats to NULL, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y, z, t);
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE with NULL psStats");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set mask to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, maskS8, MASK_VALUE, f, fErr, x, y, z, t);
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE with mask set to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set f psVector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, mask, MASK_VALUE, fS32, fErr, x, y, z, t);
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE: Set f psVector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set fError vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, mask, MASK_VALUE, f, fErrS32, x, y, z, t);
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE: Set fError vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set x vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, mask, MASK_VALUE, f, fErr, xS32, y, z, t);
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE: Set x vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set y vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, yS32, z, t);
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE: Set y vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set z vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y, zS32, t);
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE: Set z vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Set t vector to incorrect type, should cause error
+        {
+            psMemId id = psMemGetId();
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y, z, tS32);
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE: Set t vector to incorrect type");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect mask psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            mask->n++;
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y, z, t);
+            mask->n--;
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE: Incorrect mask psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect f psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            f->n++;
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y, z, t);
+            f->n--;
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE: Incorrect f psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect fErr psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            fErr->n++;
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y, z, t);
+            fErr->n--;
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE: Incorrect fErr psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+
+        // Incorrect x psVector size, should cause error
+        {
+            psMemId id = psMemGetId();
+            x->n++;
+            bool rc = psVectorClipFitPolynomial4D(myPoly, stats, mask, MASK_VALUE, f, fErr, x, y, z, t);
+            x->n--;
+            ok(rc == false, "psVectorClipFitPolynomial4D() returned FALSE: Incorrect x psVector size");
+            ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+        }
+
+        psFree(myPoly);
+        psFree(x);
+        psFree(xS32);
+        psFree(y);
+        psFree(yS32);
+        psFree(z);
+        psFree(zS32);
+        psFree(t);
+        psFree(tS32);
+        psFree(f);
+        psFree(fS32);
+        psFree(mask);
+        psFree(maskS8);
+        psFree(fErr);
+        psFree(fErrS32);
+        psFree(stats);
+        ok(!psMemCheckLeaks (id, NULL, NULL, false), "no memory leaks");
+    }
+
+    
     //
     // F32 tests: Ordinary polys, non-clip fit
@@ -696,2 +1018,3 @@
 }
 
+
