Big update to custom expression feature.
[debian/openrocket] / core / test / net / sf / openrocket / util / MathUtilTest.java
index 8b79aeca08536ad0b0002a6b8e8689fcd4faaaf5..6b9c1e1ad7841dd883da808e1ddfb6d2b0dcd773 100644 (file)
@@ -13,6 +13,23 @@ public class MathUtilTest {
        
        public static final double EPS = 0.00000000001;
        
+       /*
+       @Test 
+       public void rangeTest() {
+               double[] a;
+               
+               a = MathUtil.range(0, 10, 2);
+               assertEquals(0, a[0], 0);
+               assertEquals(10, a[5], 0);
+               assertEquals(6, a.length, 0);
+               
+               a = MathUtil.range(1, 2, 2);
+               assertEquals(1, a[0], 0);
+               assertEquals(1, a.length, 0);
+               
+       }
+       */
+       
        @Test
        public void miscMathTest() {
                
@@ -216,4 +233,64 @@ public class MathUtilTest {
                assertEquals(5.43, MathUtil.median(doubles), EPS);
        }
        
+       @Test
+       public void testInterpolate() {
+               double v;
+               List<Double> x;
+               List<Double> y;
+
+               x = new ArrayList<Double>();
+               y = new ArrayList<Double>();
+               y.add(1.0);
+               
+               v= MathUtil.interpolate(null, y, 0.0);
+               assertEquals("Failed to test for domain null", Double.NaN, v, EPS);
+               
+               v = MathUtil.interpolate(x, y, 0.0);
+               assertEquals("Failed to test for empty domain", Double.NaN, v, EPS);
+               
+               x = new ArrayList<Double>();
+               x.add(1.0);
+               y = new ArrayList<Double>();
+               
+               v = MathUtil.interpolate(x, null, 0.0);
+               assertEquals("Failed to test for range null", Double.NaN, v, EPS);
+               
+               v = MathUtil.interpolate(x, y, 0.0);
+               assertEquals("Failed to test for empty range", Double.NaN, v, EPS);
+               
+               x = new ArrayList<Double>();
+               x.add(1.0);
+               x.add(2.0);
+               y = new ArrayList<Double>();
+               y.add(15.0);
+               y.add(17.0);
+               
+               v = MathUtil.interpolate(x,y,0.0);
+               assertEquals("Failed to test t out of domain", Double.NaN, v, EPS);
+               
+               v = MathUtil.interpolate(x,y,5.0);
+               assertEquals("Failed to test t out of domain", Double.NaN, v, EPS);
+               
+               v = MathUtil.interpolate(x,y,1.0);
+               assertEquals("Failed to calculate left endpoint", 15.0, v, EPS);
+               v = MathUtil.interpolate(x,y,2.0);
+               assertEquals("Failed to calculate right endpoint", 17.0, v, EPS);
+               v = MathUtil.interpolate(x,y,1.5);
+               assertEquals("Failed to calculate center", 16.0, v, EPS);
+               
+               x = new ArrayList<Double>();
+               x.add(0.25);
+               x.add(0.5);
+               x.add(1.0);
+               x.add(2.0);
+               y = new ArrayList<Double>();
+               y.add(0.0);
+               y.add(0.0);
+               y.add(15.0);
+               y.add(17.0);
+               v = MathUtil.interpolate(x,y,1.5);
+               assertEquals("Failed to calculate center with longer list", 16.0, v, EPS);
+               
+       }
 }