commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1182134 [3/3] - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/analysis/function/ main/java/org/apache/commons/math/analysis/interpolation/ main/java/org/apache/commons/math/analysis/polynomials/ main/java/org/apache/...
Date Tue, 11 Oct 2011 22:55:09 GMT
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java?rev=1182134&r1=1182133&r2=1182134&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
Tue Oct 11 22:55:08 2011
@@ -23,15 +23,12 @@ import java.util.Map;
 
 
 import org.apache.commons.math.TestUtils;
-import org.apache.commons.math.exception.DimensionMismatchException;
-import org.apache.commons.math.exception.NonMonotonicSequenceException;
 import org.apache.commons.math.exception.MathIllegalArgumentException;
 import org.apache.commons.math.exception.MathArithmeticException;
 import org.apache.commons.math.exception.NotFiniteNumberException;
 import org.apache.commons.math.exception.NullArgumentException;
 import org.apache.commons.math.exception.util.LocalizedFormats;
 import org.apache.commons.math.random.RandomDataImpl;
-import org.apache.commons.math.random.Well1024a;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -1337,142 +1334,6 @@ public final class MathUtilsTest {
     }
 
     @Test
-    public void testL1DistanceDouble() {
-        double[] p1 = { 2.5,  0.0 };
-        double[] p2 = { -0.5, 4.0 };
-        Assert.assertTrue(Precision.equals(7.0, MathUtils.distance1(p1, p2), 1));
-    }
-
-    @Test
-    public void testL1DistanceInt() {
-        int[] p1 = { 3, 0 };
-        int[] p2 = { 0, 4 };
-        Assert.assertEquals(7, MathUtils.distance1(p1, p2));
-    }
-
-    @Test
-    public void testL2DistanceDouble() {
-        double[] p1 = { 2.5,  0.0 };
-        double[] p2 = { -0.5, 4.0 };
-        Assert.assertTrue(Precision.equals(5.0, MathUtils.distance(p1, p2), 1));
-    }
-
-    @Test
-    public void testL2DistanceInt() {
-        int[] p1 = { 3, 0 };
-        int[] p2 = { 0, 4 };
-        Assert.assertTrue(Precision.equals(5, MathUtils.distance(p1, p2), 1));
-    }
-
-    @Test
-    public void testLInfDistanceDouble() {
-        double[] p1 = { 2.5,  0.0 };
-        double[] p2 = { -0.5, 4.0 };
-        Assert.assertTrue(Precision.equals(4.0, MathUtils.distanceInf(p1, p2), 1));
-    }
-
-    @Test
-    public void testLInfDistanceInt() {
-        int[] p1 = { 3, 0 };
-        int[] p2 = { 0, 4 };
-        Assert.assertEquals(4, MathUtils.distanceInf(p1, p2));
-    }
-
-    @Test
-    public void testCheckOrder() {
-        MathUtils.checkOrder(new double[] {-15, -5.5, -1, 2, 15},
-                             MathUtils.OrderDirection.INCREASING, true);
-        MathUtils.checkOrder(new double[] {-15, -5.5, -1, 2, 2},
-                             MathUtils.OrderDirection.INCREASING, false);
-        MathUtils.checkOrder(new double[] {3, -5.5, -11, -27.5},
-                             MathUtils.OrderDirection.DECREASING, true);
-        MathUtils.checkOrder(new double[] {3, 0, 0, -5.5, -11, -27.5},
-                             MathUtils.OrderDirection.DECREASING, false);
-
-        try {
-            MathUtils.checkOrder(new double[] {-15, -5.5, -1, -1, 2, 15},
-                                 MathUtils.OrderDirection.INCREASING, true);
-            Assert.fail("an exception should have been thrown");
-        } catch (NonMonotonicSequenceException e) {
-            // Expected
-        }
-        try {
-            MathUtils.checkOrder(new double[] {-15, -5.5, -1, -2, 2},
-                                 MathUtils.OrderDirection.INCREASING, false);
-            Assert.fail("an exception should have been thrown");
-        } catch (NonMonotonicSequenceException e) {
-            // Expected
-        }
-        try {
-            MathUtils.checkOrder(new double[] {3, 3, -5.5, -11, -27.5},
-                                 MathUtils.OrderDirection.DECREASING, true);
-            Assert.fail("an exception should have been thrown");
-        } catch (NonMonotonicSequenceException e) {
-            // Expected
-        }
-        try {
-            MathUtils.checkOrder(new double[] {3, -1, 0, -5.5, -11, -27.5},
-                                 MathUtils.OrderDirection.DECREASING, false);
-            Assert.fail("an exception should have been thrown");
-        } catch (NonMonotonicSequenceException e) {
-            // Expected
-        }
-        try {
-            MathUtils.checkOrder(new double[] {3, 0, -5.5, -11, -10},
-                                 MathUtils.OrderDirection.DECREASING, false);
-            Assert.fail("an exception should have been thrown");
-        } catch (NonMonotonicSequenceException e) {
-            // Expected
-        }
-    }
-
-    @Test
-    public void testIsMonotone() {
-        if(MathUtils.isMonotone(new double[] {-15, -5.5, -1, -1, 2,15},
-                             MathUtils.OrderDirection.INCREASING, true) ){
-            Assert.fail("an exception should have been thrown");
-        }
-
-        if(MathUtils.isMonotone(new double[] {-15, -5.5,-1,-2,2},
-                             MathUtils.OrderDirection.INCREASING, false)){
-            Assert.fail("an exception should have been thrown");
-        }
-
-        if(MathUtils.isMonotone(new double[] {3,3,-5.5,-11,-27.5},
-                             MathUtils.OrderDirection.DECREASING, true)){
-            Assert.fail("an exception should have been thrown");
-        }
-        if( MathUtils.isMonotone(new double[] {3,-1,0,-5.5,-11,-27.5},
-                             MathUtils.OrderDirection.DECREASING, false) ){
-        Assert.fail("an exception should have been thrown");
-        }
-
-    }
-
-    @Test
-    public void testIsMonotoneComparable() {
-        if(MathUtils.isMonotone(new Double[] {new Double(-15), new Double(-5.5), new Double(-1),
new Double(-1), new Double(2), new Double(15)},
-                             MathUtils.OrderDirection.INCREASING, true) ){
-            Assert.fail("an exception should have been thrown");
-        }
-
-        if(MathUtils.isMonotone(new Double[] {new Double(-15), new Double(-5.5), new Double(-1),
new Double(-2), new Double(2)},
-                             MathUtils.OrderDirection.INCREASING, false)){
-            Assert.fail("an exception should have been thrown");
-        }
-
-        if(MathUtils.isMonotone(new Double[] {new Double(3), new Double(3), new Double(-5.5),
new Double(-11), new Double(-27.5)},
-                             MathUtils.OrderDirection.DECREASING, true)){
-            Assert.fail("an exception should have been thrown");
-        }
-        if( MathUtils.isMonotone(new Double[] {new Double(3), new Double(-1), new Double(0),
new Double(-5.5), new Double(-11), new Double(-27.5)},
-                             MathUtils.OrderDirection.DECREASING, false) ){
-        Assert.fail("an exception should have been thrown");
-        }
-
-    }
-
-    @Test
     public void testCheckFinite() {
         try {
             MathUtils.checkFinite(Double.POSITIVE_INFINITY);
@@ -1514,179 +1375,6 @@ public final class MathUtilsTest {
     }
 
     @Test
-    public void testSortInPlace() {
-        final double[] x1 = {2,   5,  -3, 1,  4};
-        final double[] x2 = {4,  25,   9, 1, 16};
-        final double[] x3 = {8, 125, -27, 1, 64};
-
-        MathUtils.sortInPlace(x1, x2, x3);
-
-        Assert.assertEquals(-3,  x1[0], Math.ulp(1d));
-        Assert.assertEquals(9,   x2[0], Math.ulp(1d));
-        Assert.assertEquals(-27, x3[0], Math.ulp(1d));
-
-        Assert.assertEquals(1, x1[1], Math.ulp(1d));
-        Assert.assertEquals(1, x2[1], Math.ulp(1d));
-        Assert.assertEquals(1, x3[1], Math.ulp(1d));
-
-        Assert.assertEquals(2, x1[2], Math.ulp(1d));
-        Assert.assertEquals(4, x2[2], Math.ulp(1d));
-        Assert.assertEquals(8, x3[2], Math.ulp(1d));
-
-        Assert.assertEquals(4,  x1[3], Math.ulp(1d));
-        Assert.assertEquals(16, x2[3], Math.ulp(1d));
-        Assert.assertEquals(64, x3[3], Math.ulp(1d));
-
-        Assert.assertEquals(5,   x1[4], Math.ulp(1d));
-        Assert.assertEquals(25,  x2[4], Math.ulp(1d));
-        Assert.assertEquals(125, x3[4], Math.ulp(1d));
-    }
-    
-    @Test
-    /** Example in javadoc */
-    public void testSortInPlaceExample() {
-        final double[] x = {3, 1, 2};
-        final double[] y = {1, 2, 3};
-        final double[] z = {0, 5, 7};
-        MathUtils.sortInPlace(x, y, z);
-        final double[] sx = {1, 2, 3};
-        final double[] sy = {2, 3, 1};
-        final double[] sz = {5, 7, 0};
-        Assert.assertTrue(Arrays.equals(sx, x));
-        Assert.assertTrue(Arrays.equals(sy, y));
-        Assert.assertTrue(Arrays.equals(sz, z));
-    }
-    
-    @Test
-    public void testSortInPlaceFaliures() {
-        final double[] nullArray = null;
-        final double[] one = {1};
-        final double[] two = {1, 2};
-        final double[] onep = {2};
-        try {
-            MathUtils.sortInPlace(one, two);
-            Assert.fail("Expecting DimensionMismatchException");
-        } catch (DimensionMismatchException ex) {
-            // expected
-        }
-        try {
-            MathUtils.sortInPlace(one, nullArray);
-            Assert.fail("Expecting NullArgumentException");
-        } catch (NullArgumentException ex) {
-            // expected
-        }
-        try {
-            MathUtils.sortInPlace(one, onep, nullArray);
-            Assert.fail("Expecting NullArgumentException");
-        } catch (NullArgumentException ex) {
-            // expected
-        }
-    }
-
-    @Test
-    public void testCopyOfInt() {
-        final int[] source = { Integer.MIN_VALUE,
-                               -1, 0, 1, 3, 113, 4769,
-                               Integer.MAX_VALUE };
-        final int[] dest = MathUtils.copyOf(source);
-
-        Assert.assertEquals(dest.length, source.length);
-        for (int i = 0; i < source.length; i++) {
-            Assert.assertEquals(source[i], dest[i]);
-        }
-    }
-
-    @Test
-    public void testCopyOfInt2() {
-        final int[] source = { Integer.MIN_VALUE,
-                               -1, 0, 1, 3, 113, 4769,
-                               Integer.MAX_VALUE };
-        final int offset = 3;
-        final int[] dest = MathUtils.copyOf(source, source.length - offset);
-
-        Assert.assertEquals(dest.length, source.length - offset);
-        for (int i = 0; i < source.length - offset; i++) {
-            Assert.assertEquals(source[i], dest[i]);
-        }
-    }
-
-    @Test
-    public void testCopyOfInt3() {
-        final int[] source = { Integer.MIN_VALUE,
-                               -1, 0, 1, 3, 113, 4769,
-                               Integer.MAX_VALUE };
-        final int offset = 3;
-        final int[] dest = MathUtils.copyOf(source, source.length + offset);
-
-        Assert.assertEquals(dest.length, source.length + offset);
-        for (int i = 0; i < source.length; i++) {
-            Assert.assertEquals(source[i], dest[i]);
-        }
-        for (int i = source.length; i < source.length + offset; i++) {
-            Assert.assertEquals(0, dest[i], 0);
-        }
-    }
-
-    @Test
-    public void testCopyOfDouble() {
-        final double[] source = { Double.NEGATIVE_INFINITY,
-                                  -Double.MAX_VALUE,
-                                  -1, 0,
-                                  Double.MIN_VALUE,
-                                  Math.ulp(1d),
-                                  1, 3, 113, 4769,
-                                  Double.MAX_VALUE,
-                                  Double.POSITIVE_INFINITY };
-        final double[] dest = MathUtils.copyOf(source);
-
-        Assert.assertEquals(dest.length, source.length);
-        for (int i = 0; i < source.length; i++) {
-            Assert.assertEquals(source[i], dest[i], 0);
-        }
-    }
-
-    @Test
-    public void testCopyOfDouble2() {
-        final double[] source = { Double.NEGATIVE_INFINITY,
-                                  -Double.MAX_VALUE,
-                                  -1, 0,
-                                  Double.MIN_VALUE,
-                                  Math.ulp(1d),
-                                  1, 3, 113, 4769,
-                                  Double.MAX_VALUE,
-                                  Double.POSITIVE_INFINITY };
-        final int offset = 3;
-        final double[] dest = MathUtils.copyOf(source, source.length - offset);
-
-        Assert.assertEquals(dest.length, source.length - offset);
-        for (int i = 0; i < source.length - offset; i++) {
-            Assert.assertEquals(source[i], dest[i], 0);
-        }
-    }
-
-    @Test
-    public void testCopyOfDouble3() {
-        final double[] source = { Double.NEGATIVE_INFINITY,
-                                  -Double.MAX_VALUE,
-                                  -1, 0,
-                                  Double.MIN_VALUE,
-                                  Math.ulp(1d),
-                                  1, 3, 113, 4769,
-                                  Double.MAX_VALUE,
-                                  Double.POSITIVE_INFINITY };
-        final int offset = 3;
-        final double[] dest = MathUtils.copyOf(source, source.length + offset);
-
-        Assert.assertEquals(dest.length, source.length + offset);
-        for (int i = 0; i < source.length; i++) {
-            Assert.assertEquals(source[i], dest[i], 0);
-        }
-        for (int i = source.length; i < source.length + offset; i++) {
-            Assert.assertEquals(0, dest[i], 0);
-        }
-    }
-
-    @Test
     public void testCheckNotNull1() {
         try {
             Object obj = null;
@@ -1705,201 +1393,4 @@ public final class MathUtilsTest {
             // Expected.
         }
     }
-
-    @Test
-    public void testLinearCombination1() {
-        final double[] a = new double[] {
-            -1321008684645961.0 / 268435456.0,
-            -5774608829631843.0 / 268435456.0,
-            -7645843051051357.0 / 8589934592.0
-        };
-        final double[] b = new double[] {
-            -5712344449280879.0 / 2097152.0,
-            -4550117129121957.0 / 2097152.0,
-            8846951984510141.0 / 131072.0
-        };
-
-        final double abSumInline = MathUtils.linearCombination(a[0], b[0],
-                                                               a[1], b[1],
-                                                               a[2], b[2]);
-        final double abSumArray = MathUtils.linearCombination(a, b);
-
-        Assert.assertEquals(abSumInline, abSumArray, 0);
-    }
-
-    @Test
-    public void testLinearCombination2() {
-        // we compare accurate versus naive dot product implementations
-        // on regular vectors (i.e. not extreme cases like in the previous test)
-        Well1024a random = new Well1024a(553267312521321234l);
-
-        for (int i = 0; i < 10000; ++i) {
-            final double ux = 1e17 * random.nextDouble();
-            final double uy = 1e17 * random.nextDouble();
-            final double uz = 1e17 * random.nextDouble();
-            final double vx = 1e17 * random.nextDouble();
-            final double vy = 1e17 * random.nextDouble();
-            final double vz = 1e17 * random.nextDouble();
-            final double sInline = MathUtils.linearCombination(ux, vx,
-                                                               uy, vy,
-                                                               uz, vz);
-            final double sArray = MathUtils.linearCombination(new double[] {ux, uy, uz},
-                                                              new double[] {vx, vy, vz});
-            Assert.assertEquals(sInline, sArray, 0);
-        }
-    }
-
-    @Test
-    public void testLinearCombinationInfinite() {
-        final double[][] a = new double[][] {
-            { 1, 2, 3, 4},
-            { 1, Double.POSITIVE_INFINITY, 3, 4},
-            { 1, 2, Double.POSITIVE_INFINITY, 4},
-            { 1, Double.POSITIVE_INFINITY, 3, Double.NEGATIVE_INFINITY},
-            { 1, 2, 3, 4},
-            { 1, 2, 3, 4},
-            { 1, 2, 3, 4},
-            { 1, 2, 3, 4}
-        };
-        final double[][] b = new double[][] {
-            { 1, -2, 3, 4},
-            { 1, -2, 3, 4},
-            { 1, -2, 3, 4},
-            { 1, -2, 3, 4},
-            { 1, Double.POSITIVE_INFINITY, 3, 4},
-            { 1, -2, Double.POSITIVE_INFINITY, 4},
-            { 1, Double.POSITIVE_INFINITY, 3, Double.NEGATIVE_INFINITY},
-            { Double.NaN, -2, 3, 4}
-        };
-
-        Assert.assertEquals(-3,
-                            MathUtils.linearCombination(a[0][0], b[0][0],
-                                                        a[0][1], b[0][1]),
-                            1.0e-10);
-        Assert.assertEquals(6,
-                            MathUtils.linearCombination(a[0][0], b[0][0],
-                                                        a[0][1], b[0][1],
-                                                        a[0][2], b[0][2]),
-                            1.0e-10);
-        Assert.assertEquals(22,
-                            MathUtils.linearCombination(a[0][0], b[0][0],
-                                                        a[0][1], b[0][1],
-                                                        a[0][2], b[0][2],
-                                                        a[0][3], b[0][3]),
-                            1.0e-10);
-        Assert.assertEquals(22, MathUtils.linearCombination(a[0], b[0]), 1.0e-10);
-
-        Assert.assertEquals(Double.NEGATIVE_INFINITY,
-                            MathUtils.linearCombination(a[1][0], b[1][0],
-                                                        a[1][1], b[1][1]),
-                            1.0e-10);
-        Assert.assertEquals(Double.NEGATIVE_INFINITY,
-                            MathUtils.linearCombination(a[1][0], b[1][0],
-                                                        a[1][1], b[1][1],
-                                                        a[1][2], b[1][2]),
-                            1.0e-10);
-        Assert.assertEquals(Double.NEGATIVE_INFINITY,
-                            MathUtils.linearCombination(a[1][0], b[1][0],
-                                                        a[1][1], b[1][1],
-                                                        a[1][2], b[1][2],
-                                                        a[1][3], b[1][3]),
-                            1.0e-10);
-        Assert.assertEquals(Double.NEGATIVE_INFINITY, MathUtils.linearCombination(a[1], b[1]),
1.0e-10);
-
-        Assert.assertEquals(-3,
-                            MathUtils.linearCombination(a[2][0], b[2][0],
-                                                        a[2][1], b[2][1]),
-                            1.0e-10);
-        Assert.assertEquals(Double.POSITIVE_INFINITY,
-                            MathUtils.linearCombination(a[2][0], b[2][0],
-                                                        a[2][1], b[2][1],
-                                                        a[2][2], b[2][2]),
-                            1.0e-10);
-        Assert.assertEquals(Double.POSITIVE_INFINITY,
-                            MathUtils.linearCombination(a[2][0], b[2][0],
-                                                        a[2][1], b[2][1],
-                                                        a[2][2], b[2][2],
-                                                        a[2][3], b[2][3]),
-                            1.0e-10);
-        Assert.assertEquals(Double.POSITIVE_INFINITY, MathUtils.linearCombination(a[2], b[2]),
1.0e-10);
-
-        Assert.assertEquals(Double.NEGATIVE_INFINITY,
-                            MathUtils.linearCombination(a[3][0], b[3][0],
-                                                        a[3][1], b[3][1]),
-                            1.0e-10);
-        Assert.assertEquals(Double.NEGATIVE_INFINITY,
-                            MathUtils.linearCombination(a[3][0], b[3][0],
-                                                        a[3][1], b[3][1],
-                                                        a[3][2], b[3][2]),
-                            1.0e-10);
-        Assert.assertEquals(Double.NEGATIVE_INFINITY,
-                            MathUtils.linearCombination(a[3][0], b[3][0],
-                                                        a[3][1], b[3][1],
-                                                        a[3][2], b[3][2],
-                                                        a[3][3], b[3][3]),
-                            1.0e-10);
-        Assert.assertEquals(Double.NEGATIVE_INFINITY, MathUtils.linearCombination(a[3], b[3]),
1.0e-10);
-
-        Assert.assertEquals(Double.POSITIVE_INFINITY,
-                            MathUtils.linearCombination(a[4][0], b[4][0],
-                                                        a[4][1], b[4][1]),
-                            1.0e-10);
-        Assert.assertEquals(Double.POSITIVE_INFINITY,
-                            MathUtils.linearCombination(a[4][0], b[4][0],
-                                                        a[4][1], b[4][1],
-                                                        a[4][2], b[4][2]),
-                            1.0e-10);
-        Assert.assertEquals(Double.POSITIVE_INFINITY,
-                            MathUtils.linearCombination(a[4][0], b[4][0],
-                                                        a[4][1], b[4][1],
-                                                        a[4][2], b[4][2],
-                                                        a[4][3], b[4][3]),
-                            1.0e-10);
-        Assert.assertEquals(Double.POSITIVE_INFINITY, MathUtils.linearCombination(a[4], b[4]),
1.0e-10);
-
-        Assert.assertEquals(-3,
-                            MathUtils.linearCombination(a[5][0], b[5][0],
-                                                        a[5][1], b[5][1]),
-                            1.0e-10);
-        Assert.assertEquals(Double.POSITIVE_INFINITY,
-                            MathUtils.linearCombination(a[5][0], b[5][0],
-                                                        a[5][1], b[5][1],
-                                                        a[5][2], b[5][2]),
-                            1.0e-10);
-        Assert.assertEquals(Double.POSITIVE_INFINITY,
-                            MathUtils.linearCombination(a[5][0], b[5][0],
-                                                        a[5][1], b[5][1],
-                                                        a[5][2], b[5][2],
-                                                        a[5][3], b[5][3]),
-                            1.0e-10);
-        Assert.assertEquals(Double.POSITIVE_INFINITY, MathUtils.linearCombination(a[5], b[5]),
1.0e-10);
-
-        Assert.assertEquals(Double.POSITIVE_INFINITY,
-                            MathUtils.linearCombination(a[6][0], b[6][0],
-                                                        a[6][1], b[6][1]),
-                            1.0e-10);
-        Assert.assertEquals(Double.POSITIVE_INFINITY,
-                            MathUtils.linearCombination(a[6][0], b[6][0],
-                                                        a[6][1], b[6][1],
-                                                        a[6][2], b[6][2]),
-                            1.0e-10);
-        Assert.assertTrue(Double.isNaN(MathUtils.linearCombination(a[6][0], b[6][0],
-                                                                   a[6][1], b[6][1],
-                                                                   a[6][2], b[6][2],
-                                                                   a[6][3], b[6][3])));
-        Assert.assertTrue(Double.isNaN(MathUtils.linearCombination(a[6], b[6])));
-
-        Assert.assertTrue(Double.isNaN(MathUtils.linearCombination(a[7][0], b[7][0],
-                                                        a[7][1], b[7][1])));
-        Assert.assertTrue(Double.isNaN(MathUtils.linearCombination(a[7][0], b[7][0],
-                                                        a[7][1], b[7][1],
-                                                        a[7][2], b[7][2])));
-        Assert.assertTrue(Double.isNaN(MathUtils.linearCombination(a[7][0], b[7][0],
-                                                                   a[7][1], b[7][1],
-                                                                   a[7][2], b[7][2],
-                                                                   a[7][3], b[7][3])));
-        Assert.assertTrue(Double.isNaN(MathUtils.linearCombination(a[7], b[7])));
-
-    }
-
 }



Mime
View raw message