commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From celes...@apache.org
Subject svn commit: r1344571 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: ArrayRealVectorTest.java RealVectorAbstractTest.java RealVectorTest.java SparseRealVectorTest.java
Date Thu, 31 May 2012 05:51:16 GMT
Author: celestin
Date: Thu May 31 05:51:16 2012
New Revision: 1344571

URL: http://svn.apache.org/viewvc?rev=1344571&view=rev
Log:
MATH-795: factored out testDataInOut().

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/RealVectorTest.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=1344571&r1=1344570&r2=1344571&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
Thu May 31 05:51:16 2012
@@ -49,7 +49,6 @@ import org.apache.commons.math3.analysis
 import org.apache.commons.math3.exception.DimensionMismatchException;
 import org.apache.commons.math3.exception.MathArithmeticException;
 import org.apache.commons.math3.exception.MathIllegalArgumentException;
-import org.apache.commons.math3.exception.OutOfRangeException;
 import org.apache.commons.math3.util.FastMath;
 import org.junit.Assert;
 import org.junit.Test;
@@ -60,18 +59,6 @@ import org.junit.Test;
  * @version $Id$
  */
 public class ArrayRealVectorTest extends RealVectorAbstractTest {
-
-    //
-    protected double[][] ma1 = {{1d, 2d, 3d}, {4d, 5d, 6d}, {7d, 8d, 9d}};
-    protected double[] vec1 = {1d, 2d, 3d};
-    protected double[] vec2 = {4d, 5d, 6d};
-    protected double[] vec3 = {7d, 8d, 9d};
-    protected double[] vec4 = {1d, 2d, 3d, 4d, 5d, 6d, 7d, 8d, 9d};
-    protected double[] vec5 = { -4d, 0d, 3d, 1d, -6d, 3d};
-    protected double[] vec_null = {0d, 0d, 0d};
-    protected Double[] dvec1 = {1d, 2d, 3d, 4d, 5d, 6d, 7d, 8d, 9d};
-    protected double[][] mat1 = {{1d, 2d, 3d}, {4d, 5d, 6d},{ 7d, 8d, 9d}};
-
     // tolerances
     protected double entryTolerance = 10E-16;
     protected double normTolerance = 10E-14;
@@ -508,29 +495,12 @@ public class ArrayRealVectorTest extends
 
     }
 
+    @Override
     @Test
     public void testDataInOut() {
+        super.testDataInOut();
 
         ArrayRealVector v1 = new ArrayRealVector(vec1);
-        ArrayRealVector v2 = new ArrayRealVector(vec2);
-        ArrayRealVector v4 = new ArrayRealVector(vec4);
-        RealVectorTestImpl v2_t = new RealVectorTestImpl(vec2);
-
-        RealVector v_append_1 = v1.append(v2);
-        Assert.assertEquals("testData len", 6, v_append_1.getDimension());
-        Assert.assertEquals("testData is 4.0 ", 4.0, v_append_1.getEntry(3), 0);
-
-        RealVector v_append_2 = v1.append(2.0);
-        Assert.assertEquals("testData len", 4, v_append_2.getDimension());
-        Assert.assertEquals("testData is 2.0 ", 2.0, v_append_2.getEntry(3), 0);
-
-        RealVector v_append_4 = v1.append(v2_t);
-        Assert.assertEquals("testData len", 6, v_append_4.getDimension());
-        Assert.assertEquals("testData is 4.0 ", 4.0, v_append_4.getEntry(3), 0);
-
-        RealVector v_append_5 = v1.append((RealVector) v2);
-        Assert.assertEquals("testData len", 6, v_append_5.getDimension());
-        Assert.assertEquals("testData is 4.0 ", 4.0, v_append_5.getEntry(3), 0);
 
         RealVector v_copy = v1.copy();
         Assert.assertEquals("testData len", 3, v_copy.getDimension());
@@ -539,62 +509,6 @@ public class ArrayRealVectorTest extends
         double[] a_double = v1.toArray();
         Assert.assertEquals("testData len", 3, a_double.length);
         Assert.assertNotSame("testData not same object ", v1.getDataRef(), a_double);
-
-
-//      ArrayRealVector vout4 = (ArrayRealVector) v1.clone();
-//      Assert.assertEquals("testData len", 3, vout4.getDimension());
-//      Assert.assertEquals("testData not same object ", v1.getDataRef(), vout4.getDataRef());
-
-
-        RealVector vout5 = v4.getSubVector(3, 3);
-        Assert.assertEquals("testData len", 3, vout5.getDimension());
-        Assert.assertEquals("testData is 4.0 ", 5.0, vout5.getEntry(1), 0);
-        try {
-            v4.getSubVector(3, 7);
-            Assert.fail("OutOfRangeException expected");
-        } catch (OutOfRangeException ex) {
-            // expected behavior
-        }
-
-        ArrayRealVector v_set1 = v1.copy();
-        v_set1.setEntry(1, 11.0);
-        Assert.assertEquals("testData is 11.0 ", 11.0, v_set1.getEntry(1), 0);
-        try {
-            v_set1.setEntry(3, 11.0);
-            Assert.fail("OutOfRangeException expected");
-        } catch (OutOfRangeException ex) {
-            // expected behavior
-        }
-
-        ArrayRealVector v_set3 = v1.copy();
-        v_set3.set(13.0);
-        Assert.assertEquals("testData is 13.0 ", 13.0, v_set3.getEntry(2), 0);
-
-        try {
-            v_set3.getEntry(23);
-            Assert.fail("ArrayIndexOutOfBoundsException expected");
-        } catch (ArrayIndexOutOfBoundsException ex) {
-            // expected behavior
-        }
-
-        ArrayRealVector v_set4 = v4.copy();
-        v_set4.setSubVector(3, v2_t);
-        Assert.assertEquals("testData is 1.0 ", 4.0, v_set4.getEntry(3), 0);
-        Assert.assertEquals("testData is 7.0 ", 7.0, v_set4.getEntry(6), 0);
-        try {
-            v_set4.setSubVector(7, v2_t);
-            Assert.fail("OutOfRangeException expected");
-        } catch (OutOfRangeException ex) {
-            // expected behavior
-        }
-
-
-        ArrayRealVector vout10 = v1.copy();
-        ArrayRealVector vout10_2 = v1.copy();
-        Assert.assertEquals(vout10, vout10_2);
-        vout10_2.setEntry(0, 1.1);
-        Assert.assertNotSame(vout10, vout10_2);
-
     }
 
     @Test
@@ -1435,4 +1349,9 @@ public class ArrayRealVectorTest extends
     public RealVector create(final double[] data) {
         return new ArrayRealVector(data, true);
     }
+
+    @Override
+    public RealVector createAlien(double[] data) {
+        return new RealVectorTestImpl(data);
+    }
 }

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=1344571&r1=1344570&r2=1344571&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
Thu May 31 05:51:16 2012
@@ -26,9 +26,122 @@ import org.junit.Test;
 
 
 public abstract class RealVectorAbstractTest {
-
+    /**
+     * Creates a new instance of {@link RealVector}, with specified entries.
+     * The returned vector must be of the type currently tested.
+     *
+     * @param data the entries of the vector to be created
+     * @return a new {@link RealVector} of the type to be tested
+     */
     public abstract RealVector create(double[] data);
 
+    /**
+     * Creates a new instance of {@link RealVector}, with specified entries.
+     * The type of the returned vector must be different from the type currently
+     * tested.
+     *
+     * @param data the entries of the vector to be created
+     * @return a new {@link RealVector} of an alien type
+     */
+    public abstract RealVector createAlien(double[] data);
+
+    protected double[][] ma1 = {{1d, 2d, 3d}, {4d, 5d, 6d}, {7d, 8d, 9d}};
+    protected double[] vec1 = {1d, 2d, 3d};
+    protected double[] vec2 = {4d, 5d, 6d};
+    protected double[] vec3 = {7d, 8d, 9d};
+    protected double[] vec4 = {1d, 2d, 3d, 4d, 5d, 6d, 7d, 8d, 9d};
+    protected double[] vec5 = { -4d, 0d, 3d, 1d, -6d, 3d};
+    protected double[] vec_null = {0d, 0d, 0d};
+    protected Double[] dvec1 = {1d, 2d, 3d, 4d, 5d, 6d, 7d, 8d, 9d};
+    protected double[][] mat1 = {{1d, 2d, 3d}, {4d, 5d, 6d},{ 7d, 8d, 9d}};
+
+    @Test
+    public void testDataInOut() {
+        final RealVector v1 = create(vec1);
+        final RealVector v2 = create(vec2);
+        final RealVector v4 = create(vec4);
+        final RealVector v2_t = createAlien(vec2);
+
+        final RealVector v_append_1 = v1.append(v2);
+        Assert.assertEquals("testData len", 6, v_append_1.getDimension());
+        Assert.assertEquals("testData is 4.0 ", 4.0, v_append_1.getEntry(3), 0);
+
+        final RealVector v_append_2 = v1.append(2.0);
+        Assert.assertEquals("testData len", 4, v_append_2.getDimension());
+        Assert.assertEquals("testData is 2.0 ", 2.0, v_append_2.getEntry(3), 0);
+
+        final RealVector v_append_4 = v1.append(v2_t);
+        Assert.assertEquals("testData len", 6, v_append_4.getDimension());
+        Assert.assertEquals("testData is 4.0 ", 4.0, v_append_4.getEntry(3), 0);
+
+        final RealVector v_append_5 = v1.append(v2);
+        Assert.assertEquals("testData len", 6, v_append_5.getDimension());
+        Assert.assertEquals("testData is 4.0 ", 4.0, v_append_5.getEntry(3), 0);
+
+        final RealVector vout5 = v4.getSubVector(3, 3);
+        Assert.assertEquals("testData len", 3, vout5.getDimension());
+        Assert.assertEquals("testData is 4.0 ", 5.0, vout5.getEntry(1), 0);
+        try {
+            v4.getSubVector(3, 7);
+            Assert.fail("OutOfRangeException expected");
+        } catch (OutOfRangeException ex) {
+            // expected behavior
+        }
+
+        final RealVector v_set1 = v1.copy();
+        v_set1.setEntry(1, 11.0);
+        Assert.assertEquals("testData is 11.0 ", 11.0, v_set1.getEntry(1), 0);
+        try {
+            v_set1.setEntry(3, 11.0);
+            Assert.fail("OutOfRangeException expected");
+        } catch (OutOfRangeException ex) {
+            // expected behavior
+        }
+
+        final RealVector v_set2 = v4.copy();
+        v_set2.setSubVector(3, v1);
+        Assert.assertEquals("testData is 1.0 ", 1.0, v_set2.getEntry(3), 0);
+        Assert.assertEquals("testData is 7.0 ", 7.0, v_set2.getEntry(6), 0);
+        try {
+            v_set2.setSubVector(7, v1);
+            Assert.fail("OutOfRangeException expected");
+        } catch (OutOfRangeException ex) {
+            // expected behavior
+        }
+
+        final RealVector v_set3 = v1.copy();
+        v_set3.set(13.0);
+        Assert.assertEquals("testData is 13.0 ", 13.0, v_set3.getEntry(2), 0);
+
+        try {
+            v_set3.getEntry(23);
+            Assert.fail("OutOfRangeException expected");
+        } catch (OutOfRangeException ex) {
+            // expected behavior
+        }
+
+        final RealVector v_set4 = v4.copy();
+        v_set4.setSubVector(3, v2_t);
+        Assert.assertEquals("testData is 1.0 ", 4.0, v_set4.getEntry(3), 0);
+        Assert.assertEquals("testData is 7.0 ", 7.0, v_set4.getEntry(6), 0);
+        try {
+            v_set4.setSubVector(7, v2_t);
+            Assert.fail("OutOfRangeException expected");
+        } catch (OutOfRangeException ex) {
+            // expected behavior
+        }
+
+        final RealVector vout10 = v1.copy();
+        final RealVector vout10_2 = v1.copy();
+        Assert.assertEquals(vout10, vout10_2);
+        vout10_2.setEntry(0, 1.1);
+        Assert.assertNotSame(vout10, vout10_2);
+    }
+
+    /*
+     * TESTS OF THE VISITOR PATTERN
+     */
+
     /** The whole vector is visited. */
     @Test
     public void testWalkInDefaultOrderPreservingVisitor1() {

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java?rev=1344571&r1=1344570&r2=1344571&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear/RealVectorTest.java
Thu May 31 05:51:16 2012
@@ -335,4 +335,9 @@ public class RealVectorTest extends Real
     public RealVector create(final double[] data) {
         return new OpenMapRealVector(data);
     }
+
+    @Override
+    public RealVector createAlien(double[] data) {
+        return new TestVectorImpl(data);
+    }
 }

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=1344571&r1=1344570&r2=1344571&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
Thu May 31 05:51:16 2012
@@ -26,7 +26,6 @@ import org.apache.commons.math3.analysis
 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.exception.OutOfRangeException;
 import org.apache.commons.math3.analysis.function.Abs;
 import org.apache.commons.math3.analysis.function.Acos;
 import org.apache.commons.math3.analysis.function.Asin;
@@ -59,17 +58,6 @@ import org.apache.commons.math3.analysis
  */
 public class SparseRealVectorTest extends RealVectorAbstractTest {
 
-    //
-    protected double[][] ma1 = {{1d, 2d, 3d}, {4d, 5d, 6d}, {7d, 8d, 9d}};
-    protected double[] vec1 = {1d, 2d, 3d};
-    protected double[] vec2 = {4d, 5d, 6d};
-    protected double[] vec3 = {7d, 8d, 9d};
-    protected double[] vec4 = {1d, 2d, 3d, 4d, 5d, 6d, 7d, 8d, 9d};
-    protected double[] vec5 = { -4d, 0d, 3d, 1d, -6d, 3d};
-    protected double[] vec_null = {0d, 0d, 0d};
-    protected Double[] dvec1 = {1d, 2d, 3d, 4d, 5d, 6d, 7d, 8d, 9d};
-    protected double[][] mat1 = {{1d, 2d, 3d}, {4d, 5d, 6d},{ 7d, 8d, 9d}};
-
     // tolerances
     protected double entryTolerance = 10E-16;
     protected double normTolerance = 10E-14;
@@ -340,82 +328,6 @@ public class SparseRealVectorTest extend
     }
 
     @Test
-    public void testDataInOut() {
-
-        OpenMapRealVector v1 = new OpenMapRealVector(vec1);
-        OpenMapRealVector v2 = new OpenMapRealVector(vec2);
-        OpenMapRealVector v4 = new OpenMapRealVector(vec4);
-        SparseRealVectorTestImpl v2_t = new SparseRealVectorTestImpl(vec2);
-
-        RealVector v_append_1 = v1.append(v2);
-        Assert.assertEquals("testData len", 6, v_append_1.getDimension());
-        Assert.assertEquals("testData is 4.0 ", 4.0, v_append_1.getEntry(3), 0);
-
-        RealVector v_append_2 = v1.append(2.0);
-        Assert.assertEquals("testData len", 4, v_append_2.getDimension());
-        Assert.assertEquals("testData is 2.0 ", 2.0, v_append_2.getEntry(3), 0);
-
-        RealVector v_append_4 = v1.append(v2_t);
-        Assert.assertEquals("testData len", 6, v_append_4.getDimension());
-        Assert.assertEquals("testData is 4.0 ", 4.0, v_append_4.getEntry(3), 0);
-
-        RealVector vout5 = v4.getSubVector(3, 3);
-        Assert.assertEquals("testData len", 3, vout5.getDimension());
-        Assert.assertEquals("testData is 4.0 ", 5.0, vout5.getEntry(1), 0);
-        try {
-            v4.getSubVector(3, 7);
-            Assert.fail("OutOfRangeException expected");
-        } catch (OutOfRangeException ex) {
-            // expected behavior
-        }
-
-        OpenMapRealVector v_set1 = v1.copy();
-        v_set1.setEntry(1, 11.0);
-        Assert.assertEquals("testData is 11.0 ", 11.0, v_set1.getEntry(1), 0);
-        try {
-            v_set1.setEntry(3, 11.0);
-            Assert.fail("OutOfRangeException expected");
-        } catch (OutOfRangeException ex) {
-            // expected behavior
-        }
-
-        OpenMapRealVector v_set2 = v4.copy();
-        v_set2.setSubVector(3, v1);
-        Assert.assertEquals("testData is 1.0 ", 1.0, v_set2.getEntry(3), 0);
-        Assert.assertEquals("testData is 7.0 ", 7.0, v_set2.getEntry(6), 0);
-        try {
-            v_set2.setSubVector(7, v1);
-            Assert.fail("OutOfRangeException expected");
-        } catch (OutOfRangeException ex) {
-            // expected behavior
-        }
-
-        OpenMapRealVector v_set3 = v1.copy();
-        v_set3.set(13.0);
-        Assert.assertEquals("testData is 13.0 ", 13.0, v_set3.getEntry(2), 0);
-
-        try {
-            v_set3.getEntry(23);
-            Assert.fail("OutOfRangeException expected");
-        } catch (OutOfRangeException ex) {
-            // expected behavior
-        }
-
-        OpenMapRealVector v_set4 = v4.copy();
-        v_set4.setSubVector(3, v2_t);
-        Assert.assertEquals("testData is 1.0 ", 4.0, v_set4.getEntry(3), 0);
-        Assert.assertEquals("testData is 7.0 ", 7.0, v_set4.getEntry(6), 0);
-        try {
-            v_set4.setSubVector(7, v2_t);
-            Assert.fail("OutOfRangeException expected");
-        } catch (OutOfRangeException ex) {
-            // expected behavior
-        }
-
-
-    }
-
-    @Test
     public void testMapFunctions() {
         OpenMapRealVector v1 = new OpenMapRealVector(vec1);
 
@@ -960,4 +872,9 @@ public class SparseRealVectorTest extend
     public RealVector create(double[] data) {
         return new OpenMapRealVector(data);
     }
+
+    @Override
+    public RealVector createAlien(double[] data) {
+        return new SparseRealVectorTestImpl(data);
+    }
 }



Mime
View raw message