commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From celes...@apache.org
Subject svn commit: r1346523 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: ArrayRealVectorTest.java RealVectorAbstractTest.java RealVectorTest.java
Date Tue, 05 Jun 2012 18:46:30 GMT
Author: celestin
Date: Tue Jun  5 18:46:29 2012
New Revision: 1346523

URL: http://svn.apache.org/viewvc?rev=1346523&view=rev
Log:
MATH-795: factored out
  - testCombinePreconditionSameType()
  - testCombineSameType()
  - testCombinePreconditionMixedType()
  - testCombineMixedTypes()

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

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=1346523&r1=1346522&r2=1346523&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 18:46:29 2012
@@ -507,90 +507,6 @@ public class ArrayRealVectorTest extends
     }
 
     @Test(expected=DimensionMismatchException.class)
-    public void testCombinePreconditionSameType() {
-        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.combine(a, b, y);
-    }
-
-    @Test
-    public void testCombineSameType() {
-        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;
-        }
-        final double[] actual = x.combine(a, b, y).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 testCombinePreconditionMixedType() {
-        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.combine(a, b, y);
-    }
-
-    @Test
-    public void testCombineMixedTypes() {
-        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;
-        }
-        final double[] actual = x.combine(a, b, y).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 testCombineToSelfPreconditionSameType() {
         final double a = 1d;
         final double b = 2d;

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=1346523&r1=1346522&r2=1346523&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 18:46:29 2012
@@ -17,6 +17,7 @@
 package org.apache.commons.math3.linear;
 
 import java.util.Arrays;
+import java.util.Random;
 
 import junit.framework.Assert;
 
@@ -832,6 +833,91 @@ public abstract class RealVectorAbstract
         v.cosine(w);
     }
 
+    @Test(expected=DimensionMismatchException.class)
+    public void testCombinePreconditionSameType() {
+        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.combine(a, b, y);
+    }
+
+    @Test
+    public void testCombineSameType() {
+        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);
+        final double[] actual = x.combine(a, b, y).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 testCombinePreconditionMixedType() {
+        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.combine(a, b, y);
+    }
+
+    @Test
+    public void testCombineMixedTypes() {
+        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 = createAlien(dataY);
+
+        final double[] actual = x.combine(a, b, y).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
      */

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=1346523&r1=1346522&r2=1346523&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
Tue Jun  5 18:46:29 2012
@@ -241,48 +241,6 @@ public class RealVectorTest extends Real
     }
 
     @Test(expected=DimensionMismatchException.class)
-    public void testCombinePrecondition() {
-        final double a = 1d;
-        final double b = 2d;
-        double[] aux = new double[] { 3d, 4d, 5d };
-        final TestVectorImpl x = new TestVectorImpl(aux);
-        aux = new double[] { 6d, 7d };
-        final TestVectorImpl y = new TestVectorImpl(aux);
-        x.combine(a, b, y);
-    }
-
-    @Test
-    public void testCombine() {
-        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 TestVectorImpl(new double[dim]);
-        final RealVector y = new TestVectorImpl(new double[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;
-        }
-        final RealVector z = x.combine(a, b, y);
-        Assert.assertTrue(z != x);
-        final double[] actual = z.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 testCombineToSelfPrecondition() {
         final double a = 1d;
         final double b = 2d;



Mime
View raw message