commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From celes...@apache.org
Subject svn commit: r1346740 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: RealVectorAbstractTest.java RealVectorTest.java
Date Wed, 06 Jun 2012 05:21:19 GMT
Author: celestin
Date: Wed Jun  6 05:21:18 2012
New Revision: 1346740

URL: http://svn.apache.org/viewvc?rev=1346740&view=rev
Log:
MATH-795:
  - some methods are not implemented by RealVector, so they should not be
tested: added @Ignore annotations in RealVectorTest.
  - in RealVectorAbstractTest, extracted
    + testAppendVector()
    + testAppendScalar()
from testDataInOut().

Modified:
    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

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=1346740&r1=1346739&r2=1346740&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
Wed Jun  6 05:21:18 2012
@@ -120,6 +120,56 @@ public abstract class RealVectorAbstract
     protected double entryTolerance = 10E-16;
     protected double normTolerance = 10E-14;
 
+    private void doTestAppendVector(final String message, final RealVector v1,
+        final RealVector v2, final double delta) {
+
+        final int n1 = v1.getDimension();
+        final int n2 = v2.getDimension();
+        final RealVector v = v1.append(v2);
+        Assert.assertEquals(message, n1 + n2, v.getDimension());
+        for (int i = 0; i < n1; i++) {
+            final String msg = message + ", entry #" + i;
+            Assert.assertEquals(msg, v1.getEntry(i), v.getEntry(i), delta);
+        }
+        for (int i = 0; i < n2; i++) {
+            final String msg = message + ", entry #" + (n1 + i);
+            Assert.assertEquals(msg, v2.getEntry(i), v.getEntry(n1 + i), delta);
+        }
+    }
+
+    @Test
+    public void testAppendVector() {
+        final double x = getPreferredEntryValue();
+        final double[] data1 = new double[] {x, 1d, 2d, x, x};
+        final double[] data2 = new double[] {x, x, 3d, x, 4d, x};
+
+        doTestAppendVector("same type", create(data1), create(data2), 0d);
+        doTestAppendVector("mixed types", create(data1), createAlien(data2), 0d);
+    }
+
+    private void doTestAppendScalar(final String message, final RealVector v,
+        final double d, final double delta) {
+
+        final int n = v.getDimension();
+        final RealVector w = v.append(d);
+        Assert.assertEquals(message, n + 1, w.getDimension());
+        for (int i = 0; i < n; i++) {
+            final String msg = message + ", entry #" + i;
+            Assert.assertEquals(msg, v.getEntry(i), w.getEntry(i), delta);
+        }
+        final String msg = message + ", entry #" + n;
+        Assert.assertEquals(msg, d, w.getEntry(n), delta);
+    }
+
+    @Test
+    public void testAppendScalar() {
+        final double x = getPreferredEntryValue();
+        final double[] data = new double[] {x, 1d, 2d, x, x};
+
+        doTestAppendScalar("same type", create(data), 1d, 0d);
+        doTestAppendScalar("mixed types", create(data), x, 0d);
+    }
+
     @Test
     public void testDataInOut() {
         final RealVector v1 = create(vec1);
@@ -127,22 +177,6 @@ public abstract class RealVectorAbstract
         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);

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=1346740&r1=1346739&r2=1346740&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
Wed Jun  6 05:21:18 2012
@@ -17,6 +17,7 @@
 
 package org.apache.commons.math3.linear;
 
+import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.Assert;
 import org.apache.commons.math3.analysis.UnivariateFunction;
@@ -185,6 +186,22 @@ public class RealVectorTest extends Real
         return new TestVectorImpl(data);
     }
 
+    @Test
+    @Ignore("Abstract class RealVector does not implement append(RealVector).")
+    @Override
+    public void testAppendVector() {
+        // Do nothing
+    }
+
+    @Test
+    @Ignore("Abstract class RealVector does not implement append(double)")
+    @Override
+    public void testAppendScalar() {
+        // Do nothing
+    }
+
+    @Test
+    @Ignore
     @Override
     public void testBasicFunctions() {
         /*
@@ -291,6 +308,7 @@ public class RealVectorTest extends Real
         }
     }
 
+    @Override
     @Test
     public void testAddToEntry() {
         final double[] v = new double[] { 1, 2, 3 };
@@ -304,6 +322,8 @@ public class RealVectorTest extends Real
         }
     }
 
+    @Test
+    @Ignore
     @Override
     public void testDataInOut() {
         /*
@@ -317,6 +337,8 @@ public class RealVectorTest extends Real
          */
     }
 
+    @Test
+    @Ignore
     @Override
     public void testPredicates() {
         /*
@@ -330,11 +352,10 @@ public class RealVectorTest extends Real
          */
     }
 
+    @Test
+    @Ignore("Abstract class RealVector is not serializable.")
     @Override
     public void testSerial() {
-        /*
-         * Abstract class RealVector is not serializable, so this test is skipped
-         * (@Test annotation ommitted).
-         */
+        // Do nothing
     }
 }



Mime
View raw message