You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ce...@apache.org on 2012/06/04 07:40:34 UTC

svn commit: r1345837 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: ArrayRealVectorTest.java RealVectorAbstractTest.java SparseRealVectorTest.java

Author: celestin
Date: Mon Jun  4 05:40:33 2012
New Revision: 1345837

URL: http://svn.apache.org/viewvc?rev=1345837&view=rev
Log:
MATH-795: factored out testOuterProduct() and testMisc().

Modified:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java?rev=1345837&r1=1345836&r2=1345837&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/ArrayRealVectorTest.java Mon Jun  4 05:40:33 2012
@@ -22,30 +22,6 @@ import java.util.Random;
 
 import org.apache.commons.math3.TestUtils;
 import org.apache.commons.math3.analysis.UnivariateFunction;
-import org.apache.commons.math3.analysis.function.Abs;
-import org.apache.commons.math3.analysis.function.Acos;
-import org.apache.commons.math3.analysis.function.Asin;
-import org.apache.commons.math3.analysis.function.Atan;
-import org.apache.commons.math3.analysis.function.Cbrt;
-import org.apache.commons.math3.analysis.function.Ceil;
-import org.apache.commons.math3.analysis.function.Cos;
-import org.apache.commons.math3.analysis.function.Cosh;
-import org.apache.commons.math3.analysis.function.Exp;
-import org.apache.commons.math3.analysis.function.Expm1;
-import org.apache.commons.math3.analysis.function.Floor;
-import org.apache.commons.math3.analysis.function.Inverse;
-import org.apache.commons.math3.analysis.function.Log;
-import org.apache.commons.math3.analysis.function.Log10;
-import org.apache.commons.math3.analysis.function.Log1p;
-import org.apache.commons.math3.analysis.function.Power;
-import org.apache.commons.math3.analysis.function.Rint;
-import org.apache.commons.math3.analysis.function.Signum;
-import org.apache.commons.math3.analysis.function.Sin;
-import org.apache.commons.math3.analysis.function.Sinh;
-import org.apache.commons.math3.analysis.function.Sqrt;
-import org.apache.commons.math3.analysis.function.Tan;
-import org.apache.commons.math3.analysis.function.Tanh;
-import org.apache.commons.math3.analysis.function.Ulp;
 import org.apache.commons.math3.exception.DimensionMismatchException;
 import org.apache.commons.math3.exception.MathArithmeticException;
 import org.apache.commons.math3.exception.MathIllegalArgumentException;
@@ -509,54 +485,6 @@ public class ArrayRealVectorTest extends
     }
 
     @Test
-    public void testBasicFunctions() {
-        super.testBasicFunctions();
-        ArrayRealVector v1 = new ArrayRealVector(vec1);
-        ArrayRealVector v2 = new ArrayRealVector(vec2);
-        ArrayRealVector v5 = new ArrayRealVector(vec5);
-        ArrayRealVector v_null = new ArrayRealVector(vec_null);
-
-        RealVectorTestImpl v2_t = new RealVectorTestImpl(vec2);
-
-    }
-
-    @Test
-    public void testMisc() {
-        ArrayRealVector v1 = new ArrayRealVector(vec1);
-        ArrayRealVector v4 = new ArrayRealVector(vec4);
-        RealVector v4_2 = new ArrayRealVector(vec4);
-
-        String out1 = v1.toString();
-        Assert.assertTrue("some output ",  out1.length()!=0);
-        /*
-         double[] dout1 = v1.copyOut();
-        Assert.assertEquals("testData len", 3, dout1.length);
-        Assert.assertNotSame("testData not same object ", v1.getDataRef(), dout1);
-         */
-        try {
-            v1.checkVectorDimensions(2);
-            Assert.fail("MathIllegalArgumentException expected");
-        } catch (MathIllegalArgumentException ex) {
-            // expected behavior
-        }
-
-       try {
-            v1.checkVectorDimensions(v4);
-            Assert.fail("MathIllegalArgumentException expected");
-        } catch (MathIllegalArgumentException ex) {
-            // expected behavior
-        }
-
-        try {
-            v1.checkVectorDimensions(v4_2);
-            Assert.fail("MathIllegalArgumentException expected");
-        } catch (MathIllegalArgumentException ex) {
-            // expected behavior
-        }
-
-    }
-
-    @Test
     public void testPredicates() {
 
         ArrayRealVector v = new ArrayRealVector(new double[] { 0, 1, 2 });
@@ -670,22 +598,6 @@ public class ArrayRealVectorTest extends
         v.cosine(w);
     }
 
-    @Test
-    public void testOuterProduct() {
-        final ArrayRealVector u = new ArrayRealVector(new double[] {1, 2, -3});
-        final ArrayRealVector v = new ArrayRealVector(new double[] {4, -2});
-
-        final RealMatrix uv = u.outerProduct(v);
-
-        final double tol = Math.ulp(1d);
-        Assert.assertEquals(4, uv.getEntry(0, 0), tol);
-        Assert.assertEquals(-2, uv.getEntry(0, 1), tol);
-        Assert.assertEquals(8, uv.getEntry(1, 0), tol);
-        Assert.assertEquals(-4, uv.getEntry(1, 1), tol);
-        Assert.assertEquals(-12, uv.getEntry(2, 0), tol);
-        Assert.assertEquals(6, uv.getEntry(2, 1), tol);
-    }
-
     @Test(expected=DimensionMismatchException.class)
     public void testCombinePreconditionSameType() {
         final double a = 1d;

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java?rev=1345837&r1=1345836&r2=1345837&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorAbstractTest.java Mon Jun  4 05:40:33 2012
@@ -45,9 +45,9 @@ import org.apache.commons.math3.analysis
 import org.apache.commons.math3.analysis.function.Tanh;
 import org.apache.commons.math3.analysis.function.Ulp;
 import org.apache.commons.math3.exception.MathArithmeticException;
+import org.apache.commons.math3.exception.MathIllegalArgumentException;
 import org.apache.commons.math3.exception.NumberIsTooSmallException;
 import org.apache.commons.math3.exception.OutOfRangeException;
-import org.apache.commons.math3.linear.ArrayRealVectorTest.RealVectorTestImpl;
 import org.junit.Test;
 
 
@@ -667,6 +667,52 @@ public abstract class RealVectorAbstract
         assertClose("compare vect", v_projection_2.toArray(), result_projection_2, normTolerance);
     }
 
+    @Test
+    public void testOuterProduct() {
+        final RealVector u = create(new double[] {1, 2, -3});
+        final RealVector v = create(new double[] {4, -2});
+
+        final RealMatrix uv = u.outerProduct(v);
+
+        final double tol = Math.ulp(1d);
+        Assert.assertEquals(4, uv.getEntry(0, 0), tol);
+        Assert.assertEquals(-2, uv.getEntry(0, 1), tol);
+        Assert.assertEquals(8, uv.getEntry(1, 0), tol);
+        Assert.assertEquals(-4, uv.getEntry(1, 1), tol);
+        Assert.assertEquals(-12, uv.getEntry(2, 0), tol);
+        Assert.assertEquals(6, uv.getEntry(2, 1), tol);
+    }
+
+    @Test
+    public void testMisc() {
+        RealVector v1 = create(vec1);
+        RealVector v4 = create(vec4);
+        RealVector v4_2 = create(vec4);
+
+        String out1 = v1.toString();
+        Assert.assertTrue("some output ",  out1.length()!=0);
+        try {
+            v1.checkVectorDimensions(2);
+            Assert.fail("MathIllegalArgumentException expected");
+        } catch (MathIllegalArgumentException ex) {
+            // expected behavior
+        }
+
+       try {
+            v1.checkVectorDimensions(v4);
+            Assert.fail("MathIllegalArgumentException expected");
+        } catch (MathIllegalArgumentException ex) {
+            // expected behavior
+        }
+
+        try {
+            v1.checkVectorDimensions(v4_2);
+            Assert.fail("MathIllegalArgumentException expected");
+        } catch (MathIllegalArgumentException ex) {
+            // expected behavior
+        }
+    }
+
     /*
      * TESTS OF THE VISITOR PATTERN
      */

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java?rev=1345837&r1=1345836&r2=1345837&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/SparseRealVectorTest.java Mon Jun  4 05:40:33 2012
@@ -25,31 +25,6 @@ import org.apache.commons.math3.TestUtil
 import org.apache.commons.math3.analysis.UnivariateFunction;
 import org.apache.commons.math3.util.FastMath;
 import org.apache.commons.math3.exception.MathIllegalArgumentException;
-import org.apache.commons.math3.exception.MathArithmeticException;
-import org.apache.commons.math3.analysis.function.Abs;
-import org.apache.commons.math3.analysis.function.Acos;
-import org.apache.commons.math3.analysis.function.Asin;
-import org.apache.commons.math3.analysis.function.Atan;
-import org.apache.commons.math3.analysis.function.Cbrt;
-import org.apache.commons.math3.analysis.function.Cosh;
-import org.apache.commons.math3.analysis.function.Cos;
-import org.apache.commons.math3.analysis.function.Exp;
-import org.apache.commons.math3.analysis.function.Expm1;
-import org.apache.commons.math3.analysis.function.Inverse;
-import org.apache.commons.math3.analysis.function.Log10;
-import org.apache.commons.math3.analysis.function.Log1p;
-import org.apache.commons.math3.analysis.function.Log;
-import org.apache.commons.math3.analysis.function.Sinh;
-import org.apache.commons.math3.analysis.function.Sin;
-import org.apache.commons.math3.analysis.function.Sqrt;
-import org.apache.commons.math3.analysis.function.Tanh;
-import org.apache.commons.math3.analysis.function.Tan;
-import org.apache.commons.math3.analysis.function.Floor;
-import org.apache.commons.math3.analysis.function.Ceil;
-import org.apache.commons.math3.analysis.function.Rint;
-import org.apache.commons.math3.analysis.function.Signum;
-import org.apache.commons.math3.analysis.function.Ulp;
-import org.apache.commons.math3.analysis.function.Power;
 
 /**
  * Test cases for the {@link OpenMapRealVector} class.
@@ -324,38 +299,6 @@ public class SparseRealVectorTest extend
     }
 
     @Test
-    public void testOuterProduct() {
-        final OpenMapRealVector u = new OpenMapRealVector(new double[] {1, 2, -3});
-        final OpenMapRealVector v = new OpenMapRealVector(new double[] {4, -2});
-
-        final RealMatrix uv = u.outerProduct(v);
-
-        final double tol = Math.ulp(1d);
-        Assert.assertEquals(4, uv.getEntry(0, 0), tol);
-        Assert.assertEquals(-2, uv.getEntry(0, 1), tol);
-        Assert.assertEquals(8, uv.getEntry(1, 0), tol);
-        Assert.assertEquals(-4, uv.getEntry(1, 1), tol);
-        Assert.assertEquals(-12, uv.getEntry(2, 0), tol);
-        Assert.assertEquals(6, uv.getEntry(2, 1), tol);
-    }
-
-    @Test
-    public void testMisc() {
-        OpenMapRealVector v1 = new OpenMapRealVector(vec1);
-
-        String out1 = v1.toString();
-        Assert.assertTrue("some output ",  out1.length()!=0);
-        try {
-            v1.checkVectorDimensions(2);
-            Assert.fail("MathIllegalArgumentException expected");
-        } catch (MathIllegalArgumentException ex) {
-            // expected behavior
-        }
-
-
-    }
-
-    @Test
     public void testPredicates() {
 
         OpenMapRealVector v = new OpenMapRealVector(new double[] { 0, 1, 2 });