lcsim/test/org/lcsim/math/interpolation
diff -N BilinearInterpolatorTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ BilinearInterpolatorTest.java 4 Jun 2008 05:16:39 -0000 1.1
@@ -0,0 +1,61 @@
+/*
+ * BilinearInterpolatorTest.java
+ * JUnit based test
+ *
+ * Created on June 3, 2008, 4:06 PM
+ *
+ * $Id: BilinearInterpolatorTest.java,v 1.1 2008/06/04 05:16:39 ngraf Exp $
+ */
+
+package org.lcsim.math.interpolation;
+
+import junit.framework.*;
+
+/**
+ *
+ * @author Norman Graf
+ */
+public class BilinearInterpolatorTest extends TestCase
+{
+
+ /**
+ * Test of interpolateValueAt method, of class org.lcsim.math.BilinearInterpolator.
+ */
+ public void testInterpolateValueAt()
+ {
+ double[] a = {-2, -1, 0, 1, 2};
+ double[] b = {-2, -1, 0, 1, 2};
+ double[][] vals = new double[a.length][b.length];
+
+ for(int i=0; i<a.length; ++i)
+ {
+ for(int j =0; j<b.length; ++j)
+ {
+ vals[i][j] = a[i]*a[i]+b[j]*b[j];
+ }
+ }
+
+ BilinearInterpolator instance = new BilinearInterpolator(a, b, vals);
+
+ double x = 0.0;
+ double y = 0.0;
+
+ for(int i=0; i<a.length; ++i)
+ {
+ for(int j=0; j<b.length; ++j)
+ {
+// System.out.println("a= "+a[i]+", b= "+b[j]+" , interpolates to "+instance.interpolateValueAt(a[i],b[j]));
+ assertEquals(instance.interpolateValueAt(a[i],b[j]), vals[i][j]);
+ }
+ }
+
+ for(double i=a[0]; i<a[a.length-1]; i+=.2)
+ {
+ for(double j=b[0]; j<b[b.length-1]; j+=.2)
+ {
+// System.out.format("( %4.2f , %4.2f ) interpolates to %4.2f%n",i, j, instance.interpolateValueAt(i,j));
+ assertEquals(i*i+j*j, instance.interpolateValueAt(i,j),.0001);
+ }
+ }
+ }
+}
\ No newline at end of file