commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From celes...@apache.org
Subject svn commit: r1353388 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math3/linear: RealVectorAbstractTest.java RealVectorTest.java
Date Mon, 25 Jun 2012 05:57:15 GMT
Author: celestin
Date: Mon Jun 25 05:57:14 2012
New Revision: 1353388

URL: http://svn.apache.org/viewvc?rev=1353388&view=rev
Log:
MATH-795: factored out test of getL1Norm, getL1Distance, getLInfNorm, getLInfDistance.

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=1353388&r1=1353387&r2=1353388&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
Mon Jun 25 05:57:14 2012
@@ -643,6 +643,11 @@ public abstract class RealVectorAbstract
         doTestGetDistance(true);
     }
 
+    @Test(expected = DimensionMismatchException.class)
+    public void testGetDistanceDimensionMismatch() {
+        create(new double[4]).getDistance(createAlien(new double[5]));
+    }
+
     @Test
     public void testGetNorm() {
         final double x = getPreferredEntryValue();
@@ -657,6 +662,104 @@ public abstract class RealVectorAbstract
         Assert.assertEquals("", expected, actual, 0d);
     }
 
+    private void doTestGetL1Distance(final boolean mixed) {
+        final double x = getPreferredEntryValue();
+        final double[] data1 = new double[] { x, x, 1d, x, 2d, x, x, 3d, x };
+        final double[] data2 = new double[] { 4d, x, x, 5d, 6d, 7d, x, x, 8d };
+        final RealVector v1 = create(data1);
+        final RealVector v2;
+        if (mixed) {
+            v2 = createAlien(data2);
+        } else {
+            v2 = create(data2);
+        }
+        final double actual = v1.getL1Distance(v2);
+        double expected = 0d;
+        for (int i = 0; i < data1.length; i++) {
+            final double delta = data2[i] - data1[i];
+            expected += FastMath.abs(delta);
+        }
+        Assert.assertEquals("", expected, actual, 0d);
+    }
+
+    @Test
+    public void testGetL1DistanceSameType() {
+        doTestGetL1Distance(false);
+    }
+
+    @Test
+    public void testGetL1DistanceMixedTypes() {
+        doTestGetL1Distance(true);
+    }
+
+    @Test(expected = DimensionMismatchException.class)
+    public void testGetL1DistanceDimensionMismatch() {
+        create(new double[4]).getL1Distance(createAlien(new double[5]));
+    }
+
+    @Test
+    public void testGetL1Norm() {
+        final double x = getPreferredEntryValue();
+        final double[] data = new double[] { x, x, 1d, x, 2d, x, x, 3d, x };
+        final RealVector v = create(data);
+        final double actual = v.getL1Norm();
+        double expected = 0d;
+        for (int i = 0; i < data.length; i++) {
+            expected += FastMath.abs(data[i]);
+        }
+        Assert.assertEquals("", expected, actual, 0d);
+
+    }
+
+    private void doTestGetLInfDistance(final boolean mixed) {
+        final double x = getPreferredEntryValue();
+        final double[] data1 = new double[] { x, x, 1d, x, 2d, x, x, 3d, x };
+        final double[] data2 = new double[] { 4d, x, x, 5d, 6d, 7d, x, x, 8d };
+        final RealVector v1 = create(data1);
+        final RealVector v2;
+        if (mixed) {
+            v2 = createAlien(data2);
+        } else {
+            v2 = create(data2);
+        }
+        final double actual = v1.getLInfDistance(v2);
+        double expected = 0d;
+        for (int i = 0; i < data1.length; i++) {
+            final double delta = data2[i] - data1[i];
+            expected = FastMath.max(expected, FastMath.abs(delta));
+        }
+        Assert.assertEquals("", expected, actual, 0d);
+    }
+
+    @Test
+    public void testGetLInfDistanceSameType() {
+        doTestGetLInfDistance(false);
+    }
+
+    @Test
+    public void testGetLInfDistanceMixedTypes() {
+        doTestGetLInfDistance(true);
+    }
+
+    @Test(expected = DimensionMismatchException.class)
+    public void testGetLInfDistanceDimensionMismatch() {
+        create(new double[4]).getLInfDistance(createAlien(new double[5]));
+    }
+
+    @Test
+    public void testGetLInfNorm() {
+        final double x = getPreferredEntryValue();
+        final double[] data = new double[] { x, x, 1d, x, 2d, x, x, 3d, x };
+        final RealVector v = create(data);
+        final double actual = v.getLInfNorm();
+        double expected = 0d;
+        for (int i = 0; i < data.length; i++) {
+            expected = FastMath.max(expected, FastMath.abs(data[i]));
+        }
+        Assert.assertEquals("", expected, actual, 0d);
+
+    }
+
     @Test
     public void testDataInOut() {
         final RealVector v1 = create(vec1);
@@ -1052,39 +1155,6 @@ public abstract class RealVectorAbstract
 
         final RealVector v2_t = createAlien(vec2);
 
-        // emacs calc: [-4, 0, 3, 1, -6, 3] A --> 8.4261497731763586307
-        double d_getNorm = v5.getNorm();
-        Assert.assertEquals("compare values  ", 8.4261497731763586307,
-                            d_getNorm, normTolerance);
-
-        // emacs calc: [-4, 0, 3, 1, -6, 3] vN --> 17
-        double d_getL1Norm = v5.getL1Norm();
-        Assert.assertEquals("compare values  ", 17.0, d_getL1Norm,
-                            normTolerance);
-
-        // emacs calc: [-4, 0, 3, 1, -6, 3] vn --> 6
-        double d_getLInfNorm = v5.getLInfNorm();
-        Assert.assertEquals("compare values  ", 6.0, d_getLInfNorm,
-                            normTolerance);
-
-        // octave = ???
-        double d_getL1Distance = v1.getL1Distance(v2);
-        Assert.assertEquals("compare values  ", 9d, d_getL1Distance,
-                            normTolerance);
-
-        double d_getL1Distance_2 = v1.getL1Distance(v2_t);
-        Assert.assertEquals("compare values  ", 9d, d_getL1Distance_2,
-                            normTolerance);
-
-        // octave = ???
-        double d_getLInfDistance = v1.getLInfDistance(v2);
-        Assert.assertEquals("compare values  ", 3d, d_getLInfDistance,
-                            normTolerance);
-
-        double d_getLInfDistance_2 = v1.getLInfDistance(v2_t);
-        Assert.assertEquals("compare values  ", 3d, d_getLInfDistance_2,
-                            normTolerance);
-
         // octave dot(v1,v2)
         double dot = v1.dotProduct(v2);
         Assert.assertEquals("compare val ", 32d, dot, normTolerance);

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=1353388&r1=1353387&r2=1353388&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
Mon Jun 25 05:57:14 2012
@@ -327,6 +327,20 @@ public class RealVectorTest extends Real
     }
 
     @Test
+    @Ignore("Abstract class RealVector does not implement getL1Norm()")
+    @Override
+    public void testGetL1Norm() {
+        // Do nothing
+    }
+
+    @Test
+    @Ignore("Abstract class RealVector does not implement getLInfNorm()")
+    @Override
+    public void testGetLInfNorm() {
+        // Do nothing
+    }
+
+    @Test
     @Ignore
     @Override
     public void testBasicFunctions() {



Mime
View raw message