commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From celes...@apache.org
Subject svn commit: r1346240 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: ArrayRealVectorTest.java RealVectorAbstractTest.java SparseRealVectorTest.java
Date Tue, 05 Jun 2012 05:10:56 GMT
Author: celestin
Date: Tue Jun  5 05:10:55 2012
New Revision: 1346240

URL: http://svn.apache.org/viewvc?rev=1346240&view=rev
Log:
MATH-795: factoring out testPredicates().

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=1346240&r1=1346239&r2=1346240&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
Tue Jun  5 05:10:55 2012
@@ -485,40 +485,18 @@ public class ArrayRealVectorTest extends
     }
 
     @Test
+    @Override
     public void testPredicates() {
+        super.testPredicates();
 
-        ArrayRealVector v = new ArrayRealVector(new double[] { 0, 1, 2 });
-
-        Assert.assertFalse(v.isNaN());
-        v.setEntry(1, Double.NaN);
-        Assert.assertTrue(v.isNaN());
-
-        Assert.assertFalse(v.isInfinite());
-        v.setEntry(0, Double.POSITIVE_INFINITY);
-        Assert.assertFalse(v.isInfinite());
-        v.setEntry(1, 1);
-        Assert.assertTrue(v.isInfinite());
-        v.setEntry(0, 1);
-        Assert.assertFalse(v.isInfinite());
-
-        v.setEntry(0, 0);
-        Assert.assertEquals(v, new ArrayRealVector(new double[] { 0, 1, 2 }));
-        Assert.assertNotSame(v, new ArrayRealVector(new double[] { 0, 1, 2 + FastMath.ulp(2)}));
-        Assert.assertNotSame(v, new ArrayRealVector(new double[] { 0, 1, 2, 3 }));
-
-        Assert.assertEquals(new ArrayRealVector(new double[] { Double.NaN, 1, 2 }).hashCode(),
-                     new ArrayRealVector(new double[] { 0, Double.NaN, 2 }).hashCode());
-
-        Assert.assertTrue(new ArrayRealVector(new double[] { Double.NaN, 1, 2 }).hashCode()
!=
-                   new ArrayRealVector(new double[] { 0, 1, 2 }).hashCode());
-
-        Assert.assertTrue(v.equals(v));
-        Assert.assertTrue(v.equals(v.copy()));
-        Assert.assertFalse(v.equals(null));
+        final ArrayRealVector v = (ArrayRealVector) create(new double[] { 0, 1, 2 });
         Assert.assertFalse(v.equals(v.getDataRef()));
-        Assert.assertFalse(v.equals(v.getSubVector(0, v.getDimension() - 1)));
-        Assert.assertTrue(v.equals(v.getSubVector(0, v.getDimension())));
 
+        Assert.assertEquals(create(new double[] { Double.NaN, 1, 2 }).hashCode(),
+                     create(new double[] { 0, Double.NaN, 2 }).hashCode());
+
+        Assert.assertTrue(create(new double[] { Double.NaN, 1, 2 }).hashCode() !=
+                   create(new double[] { 0, 1, 2 }).hashCode());
     }
 
     @Test

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=1346240&r1=1346239&r2=1346240&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
Tue Jun  5 05:10:55 2012
@@ -48,6 +48,7 @@ import org.apache.commons.math3.exceptio
 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.util.FastMath;
 import org.junit.Test;
 
 
@@ -713,6 +714,32 @@ public abstract class RealVectorAbstract
         }
     }
 
+    @Test
+    public void testPredicates() {
+        final RealVector v = create(new double[] { 0, 1, 2 });
+
+        Assert.assertFalse(v.isNaN());
+        v.setEntry(1, Double.NaN);
+        Assert.assertTrue(v.isNaN());
+
+        Assert.assertFalse(v.isInfinite());
+        v.setEntry(0, Double.POSITIVE_INFINITY);
+        Assert.assertFalse(v.isInfinite());
+        v.setEntry(1, 1);
+        Assert.assertTrue(v.isInfinite());
+
+        v.setEntry(0, 0);
+        Assert.assertEquals(v, create(new double[] { 0, 1, 2 }));
+        Assert.assertNotSame(v, create(new double[] { 0, 1, 2 + FastMath.ulp(2)}));
+        Assert.assertNotSame(v, create(new double[] { 0, 1, 2, 3 }));
+
+        Assert.assertTrue(v.equals(v));
+        Assert.assertTrue(v.equals(v.copy()));
+        Assert.assertFalse(v.equals(null));
+        Assert.assertFalse(v.equals(v.getSubVector(0, v.getDimension() - 1)));
+        Assert.assertTrue(v.equals(v.getSubVector(0, v.getDimension())));
+    }
+
     /*
      * 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=1346240&r1=1346239&r2=1346240&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
Tue Jun  5 05:10:55 2012
@@ -299,28 +299,6 @@ public class SparseRealVectorTest extend
     }
 
     @Test
-    public void testPredicates() {
-
-        OpenMapRealVector v = new OpenMapRealVector(new double[] { 0, 1, 2 });
-
-        Assert.assertFalse(v.isNaN());
-        v.setEntry(1, Double.NaN);
-        Assert.assertTrue(v.isNaN());
-
-        Assert.assertFalse(v.isInfinite());
-        v.setEntry(0, Double.POSITIVE_INFINITY);
-        Assert.assertFalse(v.isInfinite()); // NaN has higher priority than infinity
-        v.setEntry(1, 1);
-        Assert.assertTrue(v.isInfinite());
-
-        v.setEntry(0, 0);
-        Assert.assertEquals(v, new OpenMapRealVector(new double[] { 0, 1, 2 }));
-        Assert.assertNotSame(v, new OpenMapRealVector(new double[] { 0, 1, 2 + FastMath.ulp(2)}));
-        Assert.assertNotSame(v, new OpenMapRealVector(new double[] { 0, 1, 2, 3 }));
-
-    }
-
-    @Test
     public void testSerial()  {
         OpenMapRealVector v = new OpenMapRealVector(new double[] { 0, 1, 2 });
         Assert.assertEquals(v,TestUtils.serializeAndRecover(v));



Mime
View raw message