commons-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=1346723&view=rev
Log:
MATH-795: factored out
  - testCombineToSelfPreconditionSameType()
  - testCombineToSelfSameType()
  - testCombineToSelfPreconditionMixeType()
  - testCombineToSelfMixedTypes()

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

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=1346723&r1=1346722&r2=1346723&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
Wed Jun  6 03:19:18 2012
@@ -506,92 +506,6 @@ public class ArrayRealVectorTest extends
         Assert.assertEquals(0, new ArrayRealVector(new double[0], false).getDimension());
     }
 
-    @Test(expected=DimensionMismatchException.class)
-    public void testCombineToSelfPreconditionSameType() {
-        final double a = 1d;
-        final double b = 2d;
-        double[] aux = new double[] { 3d, 4d, 5d };
-        final RealVector x = new ArrayRealVector(aux, false);
-        aux = new double[] { 6d, 7d };
-        final RealVector y = new ArrayRealVector(aux, false);
-        x.combineToSelf(a, b, y);
-    }
-
-    @Test
-    public void testCombineToSelfSameType() {
-        final Random random = new Random(20110726);
-        final int dim = 10;
-        final double a = (2 * random.nextDouble() - 1);
-        final double b = (2 * random.nextDouble() - 1);
-        final RealVector x = new ArrayRealVector(dim);
-        final RealVector y = new ArrayRealVector(dim);
-        final double[] expected = new double[dim];
-        for (int i = 0; i < dim; i++) {
-            final double xi = 2 * random.nextDouble() - 1;
-            final double yi = 2 * random.nextDouble() - 1;
-            x.setEntry(i, xi);
-            y.setEntry(i, yi);
-            expected[i] = a * xi + b * yi;
-        }
-        Assert.assertSame(x, x.combineToSelf(a, b, y));
-        final double[] actual = x.toArray();
-        for (int i = 0; i < dim; i++) {
-            final double delta;
-            if (expected[i] == 0d) {
-                delta = Math.ulp(1d);
-            } else {
-                delta = Math.ulp(expected[i]);
-            }
-            Assert.assertEquals("elements [" + i + "] differ",
-                                expected[i],
-                                actual[i],
-                                delta);
-        }
-    }
-
-    @Test(expected=DimensionMismatchException.class)
-    public void testCombineToSelfPreconditionMixedType() {
-        final double a = 1d;
-        final double b = 2d;
-        double[] aux = new double[] { 3d, 4d, 5d };
-        final RealVector x = new ArrayRealVector(aux, false);
-        aux = new double[] { 6d, 7d };
-        final RealVector y = new OpenMapRealVector(aux);
-        x.combineToSelf(a, b, y);
-    }
-
-    @Test
-    public void testCombineToSelfMixedTypes() {
-        final Random random = new Random(20110726);
-        final int dim = 10;
-        final double a = (2 * random.nextDouble() - 1);
-        final double b = (2 * random.nextDouble() - 1);
-        final RealVector x = new ArrayRealVector(dim);
-        final RealVector y = new OpenMapRealVector(dim, 0d);
-        final double[] expected = new double[dim];
-        for (int i = 0; i < dim; i++) {
-            final double xi = 2 * random.nextDouble() - 1;
-            final double yi = 2 * random.nextDouble() - 1;
-            x.setEntry(i, xi);
-            y.setEntry(i, yi);
-            expected[i] = a * xi + b * yi;
-        }
-        Assert.assertSame(x, x.combineToSelf(a, b, y));
-        final double[] actual = x.toArray();
-        for (int i = 0; i < dim; i++) {
-            final double delta;
-            if (expected[i] == 0d) {
-                delta = Math.ulp(1d);
-            } else {
-                delta = Math.ulp(expected[i]);
-            }
-            Assert.assertEquals("elements [" + i + "] differ",
-                                expected[i],
-                                actual[i],
-                                delta);
-        }
-    }
-
     @Override
     public RealVector create(final double[] data) {
         return new ArrayRealVector(data, true);

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=1346723&r1=1346722&r2=1346723&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 03:19:18 2012
@@ -918,6 +918,92 @@ public abstract class RealVectorAbstract
         }
     }
 
+    @Test(expected=DimensionMismatchException.class)
+    public void testCombineToSelfPreconditionSameType() {
+        final double a = 1d;
+        final double b = 2d;
+        double[] aux = new double[] { 3d, 4d, 5d };
+        final RealVector x = create(aux);
+        aux = new double[] { 6d, 7d };
+        final RealVector y = create(aux);
+        x.combineToSelf(a, b, y);
+    }
+
+    @Test
+    public void testCombineToSelfSameType() {
+        final Random random = new Random(20110726);
+        final int dim = 10;
+        final double a = (2 * random.nextDouble() - 1);
+        final double b = (2 * random.nextDouble() - 1);
+        final double[] dataX = new double[dim];
+        final double[] dataY = new double[dim];
+        final double[] expected = new double[dim];
+        for (int i = 0; i < dim; i++) {
+            dataX[i] = 2 * random.nextDouble() - 1;
+            dataY[i] = 2 * random.nextDouble() - 1;
+            expected[i] = a * dataX[i] + b * dataY[i];
+        }
+        final RealVector x = create(dataX);
+        final RealVector y = create(dataY);
+        Assert.assertSame(x, x.combineToSelf(a, b, y));
+        final double[] actual = x.toArray();
+        for (int i = 0; i < dim; i++) {
+            final double delta;
+            if (expected[i] == 0d) {
+                delta = Math.ulp(1d);
+            } else {
+                delta = Math.ulp(expected[i]);
+            }
+            Assert.assertEquals("elements [" + i + "] differ",
+                                expected[i],
+                                actual[i],
+                                delta);
+        }
+    }
+
+    @Test(expected=DimensionMismatchException.class)
+    public void testCombineToSelfPreconditionMixedType() {
+        final double a = 1d;
+        final double b = 2d;
+        double[] aux = new double[] { 3d, 4d, 5d };
+        final RealVector x = create(aux);
+        aux = new double[] { 6d, 7d };
+        final RealVector y = createAlien(aux);
+        x.combineToSelf(a, b, y);
+    }
+
+    @Test
+    public void testCombineToSelfMixedTypes() {
+        final Random random = new Random(20110726);
+        final int dim = 10;
+        final double a = (2 * random.nextDouble() - 1);
+        final double b = (2 * random.nextDouble() - 1);
+        final double[] dataX = new double[dim];
+        final double[] dataY = new double[dim];
+        final double[] expected = new double[dim];
+        for (int i = 0; i < dim; i++) {
+            dataX[i] = 2 * random.nextDouble() - 1;
+            dataY[i] = 2 * random.nextDouble() - 1;
+            expected[i] = a * dataX[i] + b * dataY[i];
+        }
+        final RealVector x = create(dataX);
+        final RealVector y = create(dataY);
+        Assert.assertSame(x, x.combineToSelf(a, b, y));
+        final double[] actual = x.toArray();
+        for (int i = 0; i < dim; i++) {
+            final double delta;
+            if (expected[i] == 0d) {
+                delta = Math.ulp(1d);
+            } else {
+                delta = Math.ulp(expected[i]);
+            }
+            Assert.assertEquals("elements [" + i + "] differ",
+                                expected[i],
+                                actual[i],
+                                delta);
+        }
+    }
+
     /*
      * TESTS OF THE VISITOR PATTERN
      */



Mime
View raw message