From 97ed5ac2c5c3544e4c48b30cfa10b8261561fe4a Mon Sep 17 00:00:00 2001 From: kruland2607 Date: Tue, 10 Jul 2012 18:42:35 +0000 Subject: [PATCH 1/1] Extract PolyInterpolator.main into Junit test case. git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@882 180e2498-e6e9-4542-8430-84ac67f01cd8 --- .../sf/openrocket/util/PolyInterpolator.java | 31 --- .../openrocket/util/PolyInterpolatorTest.java | 212 ++++++++++++++++++ 2 files changed, 212 insertions(+), 31 deletions(-) create mode 100644 core/test/net/sf/openrocket/util/PolyInterpolatorTest.java diff --git a/core/src/net/sf/openrocket/util/PolyInterpolator.java b/core/src/net/sf/openrocket/util/PolyInterpolator.java index f97d45c4..134f7178 100644 --- a/core/src/net/sf/openrocket/util/PolyInterpolator.java +++ b/core/src/net/sf/openrocket/util/PolyInterpolator.java @@ -228,35 +228,4 @@ public class PolyInterpolator { } } - - - - public static void main(String[] arg) { - - PolyInterpolator p0 = new PolyInterpolator( - new double[] {0.6, 1.1}, - new double[] {0.6, 1.1} - ); - double[] r0 = p0.interpolator(1.5, 1.6, 2, -3); - - PolyInterpolator p1 = new PolyInterpolator( - new double[] {0.6, 1.1}, - new double[] {0.6, 1.1}, - new double[] {0.6} - ); - double[] r1 = p1.interpolator(1.5, 1.6, 2, -3, 0); - - PolyInterpolator p2 = new PolyInterpolator( - new double[] {0.6, 1.1}, - new double[] {0.6, 1.1}, - new double[] {0.6, 1.1} - ); - double[] r2 = p2.interpolator(1.5, 1.6, 2, -3, 0, 0); - - - for (double x=0.6; x <= 1.11; x += 0.01) { - System.out.println(x + " " + eval(x,r0) + " " + eval(x,r1) + " " + eval(x,r2)); - } - - } } diff --git a/core/test/net/sf/openrocket/util/PolyInterpolatorTest.java b/core/test/net/sf/openrocket/util/PolyInterpolatorTest.java new file mode 100644 index 00000000..cb9201f1 --- /dev/null +++ b/core/test/net/sf/openrocket/util/PolyInterpolatorTest.java @@ -0,0 +1,212 @@ +package net.sf.openrocket.util; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class PolyInterpolatorTest { + + @Test + public void oldMainTest() { + { + PolyInterpolator p0 = new PolyInterpolator( + new double[] {0.6, 1.1}, + new double[] {0.6, 1.1} + ); + double[] r0 = p0.interpolator(1.5, 1.6, 2, -3); + double[] answer0 = new double[] { + /* x=0.60*/ 1.4999999999999987, + /* x=0.61*/ 1.5199143999999984, + /* x=0.62*/ 1.5396351999999984, + /* x=0.63*/ 1.5591287999999988, + /* x=0.64*/ 1.578361599999998, + /* x=0.65*/ 1.597299999999998, + /* x=0.66*/ 1.6159103999999977, + /* x=0.67*/ 1.6341591999999976, + /* x=0.68*/ 1.6520127999999976, + /* x=0.69*/ 1.669437599999997, + /* x=0.70*/ 1.6863999999999977, + /* x=0.71*/ 1.702866399999997, + /* x=0.72*/ 1.7188031999999964, + /* x=0.73*/ 1.7341767999999966, + /* x=0.74*/ 1.7489535999999957, + /* x=0.75*/ 1.7630999999999966, + /* x=0.76*/ 1.7765823999999952, + /* x=0.77*/ 1.7893671999999965, + /* x=0.78*/ 1.8014207999999958, + /* x=0.79*/ 1.8127095999999945, + /* x=0.80*/ 1.8231999999999942, + /* x=0.81*/ 1.8328583999999952, + /* x=0.82*/ 1.841651199999994, + /* x=0.83*/ 1.849544799999994, + /* x=0.84*/ 1.856505599999993, + /* x=0.85*/ 1.8624999999999927, + /* x=0.86*/ 1.8674943999999924, + /* x=0.87*/ 1.8714551999999918, + /* x=0.88*/ 1.8743487999999924, + /* x=0.89*/ 1.876141599999992, + /* x=0.90*/ 1.8767999999999914, + /* x=0.91*/ 1.8762903999999914, + /* x=0.92*/ 1.8745791999999906, + /* x=0.93*/ 1.8716327999999898, + /* x=0.94*/ 1.8674175999999907, + /* x=0.95*/ 1.8618999999999888, + /* x=0.96*/ 1.8550463999999902, + /* x=0.97*/ 1.8468231999999887, + /* x=0.98*/ 1.8371967999999885, + /* x=0.99*/ 1.826133599999988, + /* x=1.00*/ 1.8135999999999868, + /* x=1.01*/ 1.7995623999999868, + /* x=1.02*/ 1.783987199999987, + /* x=1.03*/ 1.7668407999999873, + /* x=1.04*/ 1.748089599999986, + /* x=1.05*/ 1.7276999999999854, + /* x=1.06*/ 1.7056383999999847, + /* x=1.07*/ 1.6818711999999838, + /* x=1.08*/ 1.6563647999999844, + /* x=1.09*/ 1.629085599999983, + /* x=1.10*/ 1.5999999999999837 + }; + double x=0.6; + for (int i=0; i