Index: /trunk/psModules/test/tst_pmNonLinear.c
===================================================================
--- /trunk/psModules/test/tst_pmNonLinear.c	(revision 2127)
+++ /trunk/psModules/test/tst_pmNonLinear.c	(revision 2128)
@@ -3,8 +3,16 @@
  *  @brief Contains the tests for pmNonLinear.c:
  *
+ * test00: This code will create a simple polynomial, and call
+ * pmNonLinearityPolynomial() for a variety of image sizes [(1, 1), (1,
+ * N), (N, 1), (N, N)].  
+ *
+ * test01: This code will create simple table lookup vectors, and call
+ * pmNonLinearityPolynomial() for a variety of image sizes [(1, 1), (1,
+ * N), (N, 1), (N, N)].  
+ *
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-14 18:31:32 $
+ *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-14 20:49:53 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -15,6 +23,8 @@
 #include "pmNonLinear.h"
 static int test00(void);
+static int test01(void);
 testDescription tests[] = {
-                              {test00, 000, "pmNonLinear", 0, false},
+                              {test00, 000, "pmNonLinearityPolynomial", 0, false},
+                              {test01, 000, "pmNonLinearityLookup", 0, false},
                               {NULL}
                           };
@@ -26,17 +36,20 @@
 }
 
-#define NUM_ROWS 32
-#define NUM_COLS 32
-int test00( void )
+#define NUM_ROWS 8
+#define NUM_COLS 8
+int doNonLinearityPolynomialTest(int numCols, int numRows)
 {
     int i;
     int j;
-    psImage *myImage = psImageAlloc(NUM_COLS, NUM_ROWS, PS_TYPE_F32);
-    psReadout *myReadout = psReadoutAlloc(NUM_COLS, NUM_ROWS, myImage);
-    psPolynomial1D *myPoly = psPolynomial1DAlloc(1, PS_POLYNOMIAL_ORD);
+    float actual;
+    float expect;
+    int testStatus = 0;
+    psImage *myImage = psImageAlloc(numCols, numRows, PS_TYPE_F32);
+    psReadout *myReadout = psReadoutAlloc(numCols, numRows, myImage);
+    psPolynomial1D *myPoly = psPolynomial1DAlloc(2, PS_POLYNOMIAL_ORD);
     myPoly->coeff[1] = 1.0;
 
-    for (i=0;i<NUM_ROWS;i++) {
-        for (j=0;j<NUM_COLS;j++) {
+    for (i=0;i<numRows;i++) {
+        for (j=0;j<numCols;j++) {
             myReadout->image->data.F32[i][j] = (float) (i + j);
         }
@@ -45,7 +58,88 @@
     printPositiveTestHeader(stdout, "pmNonLinear", "Simple polynomial");
     myReadout = pmNonLinearityPolynomial(myReadout, myPoly);
+    for (i=0;i<numRows;i++) {
+        for (j=0;j<numCols;j++) {
+            expect = psPolynomial1DEval((float) (i + j), myPoly);
+            actual = myReadout->image->data.F32[i][j];
+            if (FLT_EPSILON < fabs(expect - actual)) {
+                printf("ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
+                testStatus = 1;
+            }
+        }
+    }
+
+
     psFree(myReadout);
+    psFree(myPoly);
     printFooter(stdout, "pmNonLinear", "Simple polynomial", true);
-    return 0;
+    return(testStatus);
 }
-//This code will use the psNonLinearLookup routines.
+
+int test00( void )
+{
+    int testStatus = 0;
+
+    testStatus |= doNonLinearityPolynomialTest(1, 1);
+    testStatus |= doNonLinearityPolynomialTest(NUM_COLS, 1);
+    testStatus |= doNonLinearityPolynomialTest(1, NUM_ROWS);
+    testStatus |= doNonLinearityPolynomialTest(NUM_COLS, NUM_ROWS);
+
+    return(testStatus);
+}
+
+int doNonLinearityLookupTest(int numCols, int numRows)
+{
+    int i;
+    int j;
+    float actual;
+    float expect;
+    int testStatus = 0;
+    int tableSize = PS_MAX(numCols, numRows)*2;
+    psImage *myImage = psImageAlloc(numCols, numRows, PS_TYPE_F32);
+    psReadout *myReadout = psReadoutAlloc(numCols, numRows, myImage);
+    psVector *in = psVectorAlloc(tableSize, PS_TYPE_F32);
+    psVector *out = psVectorAlloc(tableSize, PS_TYPE_F32);
+
+    for (i=0;i<numRows;i++) {
+        for (j=0;j<numCols;j++) {
+            myReadout->image->data.F32[i][j] = (float) (i + j);
+        }
+    }
+
+    for (i=0;i<tableSize;i++) {
+        in->data.F32[i] = (float) i;
+        out->data.F32[i] = (float) (2 * i);
+    }
+
+    printPositiveTestHeader(stdout, "pmNonLinear", "Simple polynomial");
+    myReadout = pmNonLinearityLookup(myReadout, in, out);
+    for (i=0;i<numRows;i++) {
+        for (j=0;j<numCols;j++) {
+            expect = (float) (2 * (i + j));
+            actual = myReadout->image->data.F32[i][j];
+            if (FLT_EPSILON < fabs(expect - actual)) {
+                printf("ERROR: image[%d][%d] is %f, should be %f\n", i, j, actual, expect);
+                testStatus = 1;
+            }
+        }
+    }
+
+
+    psFree(myReadout);
+    psFree(in);
+    psFree(out);
+    printFooter(stdout, "pmNonLinear", "Simple polynomial", true);
+    return(testStatus);
+}
+
+int test01( void )
+{
+    int testStatus = 0;
+
+    testStatus |= doNonLinearityLookupTest(1, 1);
+    testStatus |= doNonLinearityLookupTest(NUM_COLS, 1);
+    testStatus |= doNonLinearityLookupTest(1, NUM_ROWS);
+    testStatus |= doNonLinearityLookupTest (NUM_COLS, NUM_ROWS);
+
+    return(testStatus);
+}
