Pull LinearInterpolator.main() into a JUnit test.
authorkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Tue, 10 Jul 2012 17:53:34 +0000 (17:53 +0000)
committerkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Tue, 10 Jul 2012 17:53:34 +0000 (17:53 +0000)
git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@880 180e2498-e6e9-4542-8430-84ac67f01cd8

core/src/net/sf/openrocket/util/LinearInterpolator.java
core/test/net/sf/openrocket/util/LinearInterpolatorTest.java [new file with mode: 0644]

index e94a39766e6237306e42f241549a6ccfc0394718..db422d52a6d2f103e08bd77e26773133202e95a3 100644 (file)
@@ -113,16 +113,4 @@ public class LinearInterpolator implements Cloneable {
                }
        }
 
-       
-       public static void main(String[] args) {
-               LinearInterpolator interpolator = new LinearInterpolator(
-                               new double[] {1, 1.5, 2, 4, 5},
-                               new double[] {0, 1,   0, 2, 2}
-               );
-               
-               for (double x=0; x < 6; x+=0.1) {
-                       System.out.printf("%.1f:  %.2f\n", x, interpolator.getValue(x));
-               }
-       }
-       
 }
diff --git a/core/test/net/sf/openrocket/util/LinearInterpolatorTest.java b/core/test/net/sf/openrocket/util/LinearInterpolatorTest.java
new file mode 100644 (file)
index 0000000..600f82b
--- /dev/null
@@ -0,0 +1,32 @@
+package net.sf.openrocket.util;
+
+import static org.junit.Assert.*;
+import org.junit.Test;
+
+public class LinearInterpolatorTest {
+
+       @Test
+       public void oldMainTest() {
+               LinearInterpolator interpolator = new LinearInterpolator(
+                               new double[] {1, 1.5, 2, 4, 5},
+                               new double[] {0, 1,   0, 2, 2}
+               );
+               
+               double[] answer = new double[] {
+                               /* x=0 */ 0.00, 0.00, 0.00,     0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00,
+                               /* x=1 */ 0.00, 0.20, 0.40, 0.60, 0.80, 1.00, 0.80, 0.60, 0.40, 0.20,
+                               /* x=2 */ 0.00, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90,
+                               /* x=3 */ 1.00, 1.10, 1.20, 1.30, 1.40, 1.50, 1.60, 1.70, 1.80, 1.90,
+                               /* x=4 */ 2.00, 2.00, 2.00, 2.00, 2.00, 2.00, 2.00, 2.00, 2.00, 2.00,
+                               /* x=5 */ 2.00, 2.00, 2.00, 2.00, 2.00, 2.00, 2.00, 2.00, 2.00, 2.00,
+                               /* x=6 */ 2.00
+               };
+               
+               double x = 0;
+               for (int i=0; i < answer.length; i++) {
+                       assertEquals( "Answer wrong for x = " + x , answer[i], interpolator.getValue(x), 0.01 );
+                       x+= 0.1;
+               }
+
+       }
+}