commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From celes...@apache.org
Subject svn commit: r1164618 - in /commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear: Array2DRowRealMatrixTest.java BlockRealMatrixTest.java SparseRealMatrixTest.java
Date Fri, 02 Sep 2011 16:40:19 GMT
Author: celestin
Date: Fri Sep  2 16:40:18 2011
New Revision: 1164618

URL: http://svn.apache.org/viewvc?rev=1164618&view=rev
Log:
Units tests of RealMatrix implementations: replaced reference to DecompositionSolver.solve(double[])
by DecompositionSolver.solve(RealVector) (see MATH-653)

Modified:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/BlockRealMatrixTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealMatrixTest.java

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java?rev=1164618&r1=1164617&r2=1164618&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/Array2DRowRealMatrixTest.java
Fri Sep  2 16:40:18 2011
@@ -230,38 +230,38 @@ public final class Array2DRowRealMatrixT
         Array2DRowRealMatrix mInv = new Array2DRowRealMatrix(testDataInv);
         Array2DRowRealMatrix mPlusInv = new Array2DRowRealMatrix(testDataPlusInv);
         Array2DRowRealMatrix identity = new Array2DRowRealMatrix(id);
-        
+
         TestUtils.assertEquals("m^0", m.power(0),
-            identity, entryTolerance);        
+            identity, entryTolerance);
         TestUtils.assertEquals("mInv^0", mInv.power(0),
-                identity, entryTolerance);        
+                identity, entryTolerance);
         TestUtils.assertEquals("mPlusInv^0", mPlusInv.power(0),
                 identity, entryTolerance);
-        
+
         TestUtils.assertEquals("m^1", m.power(1),
-                m, entryTolerance);        
+                m, entryTolerance);
         TestUtils.assertEquals("mInv^1", mInv.power(1),
-                mInv, entryTolerance);        
+                mInv, entryTolerance);
         TestUtils.assertEquals("mPlusInv^1", mPlusInv.power(1),
-                mPlusInv, entryTolerance); 
-        
+                mPlusInv, entryTolerance);
+
         RealMatrix C1 = m.copy();
         RealMatrix C2 = mInv.copy();
         RealMatrix C3 = mPlusInv.copy();
-        
+
         for (int i = 2; i <= 10; ++i) {
             C1 = C1.multiply(m);
             C2 = C2.multiply(mInv);
             C3 = C3.multiply(mPlusInv);
-            
+
             TestUtils.assertEquals("m^" + i, m.power(i),
-                    C1, entryTolerance);        
+                    C1, entryTolerance);
             TestUtils.assertEquals("mInv^" + i, mInv.power(i),
-                    C2, entryTolerance);        
+                    C2, entryTolerance);
             TestUtils.assertEquals("mPlusInv^" + i, mPlusInv.power(i),
-                    C3, entryTolerance);            
+                    C3, entryTolerance);
         }
-        
+
         try {
             Array2DRowRealMatrix mNotSquare = new Array2DRowRealMatrix(testData2T);
             mNotSquare.power(2);
@@ -269,7 +269,7 @@ public final class Array2DRowRealMatrixT
         } catch (NonSquareMatrixException ex) {
             // ignored
         }
-        
+
         try {
             m.power(-1);
             Assert.fail("Expecting IllegalArgumentException");
@@ -277,7 +277,7 @@ public final class Array2DRowRealMatrixT
             // ignored
         }
     }
-    
+
     /** test trace */
     @Test
     public void testTrace() {
@@ -437,12 +437,17 @@ public final class Array2DRowRealMatrixT
         // Solve example
         double[][] coefficientsData = {{2, 3, -2}, {-1, 7, 6}, {4, -3, -5}};
         RealMatrix coefficients = new Array2DRowRealMatrix(coefficientsData);
-        double[] constants = {1, -2, 1};
-        double[] solution = new LUDecompositionImpl(coefficients).getSolver().solve(constants);
-        Assert.assertEquals(2 * solution[0] + 3 * solution[1] -2 * solution[2], constants[0],
1E-12);
-        Assert.assertEquals(-1 * solution[0] + 7 * solution[1] + 6 * solution[2], constants[1],
1E-12);
-        Assert.assertEquals(4 * solution[0] - 3 * solution[1] -5 * solution[2], constants[2],
1E-12);
-
+        RealVector constants = new ArrayRealVector(new double[]{1, -2, 1}, false);
+        RealVector solution = new LUDecompositionImpl(coefficients).getSolver().solve(constants);
+        final double cst0 = constants.getEntry(0);
+        final double cst1 = constants.getEntry(1);
+        final double cst2 = constants.getEntry(2);
+        final double sol0 = solution.getEntry(0);
+        final double sol1 = solution.getEntry(1);
+        final double sol2 = solution.getEntry(2);
+        Assert.assertEquals(2 * sol0 + 3 * sol1 -2 * sol2, cst0, 1E-12);
+        Assert.assertEquals(-1 * sol0 + 7 * sol1 + 6 * sol2, cst1, 1E-12);
+        Assert.assertEquals(4 * sol0 - 3 * sol1 -5 * sol2, cst2, 1E-12);
     }
 
     // test submatrix accessors

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/BlockRealMatrixTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/BlockRealMatrixTest.java?rev=1164618&r1=1164617&r2=1164618&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/BlockRealMatrixTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/BlockRealMatrixTest.java
Fri Sep  2 16:40:18 2011
@@ -482,12 +482,17 @@ public final class BlockRealMatrixTest {
         // Solve example
         double[][] coefficientsData = {{2, 3, -2}, {-1, 7, 6}, {4, -3, -5}};
         RealMatrix coefficients = new BlockRealMatrix(coefficientsData);
-        double[] constants = {1, -2, 1};
-        double[] solution = new LUDecompositionImpl(coefficients).getSolver().solve(constants);
-        Assert.assertEquals(2 * solution[0] + 3 * solution[1] -2 * solution[2], constants[0],
1E-12);
-        Assert.assertEquals(-1 * solution[0] + 7 * solution[1] + 6 * solution[2], constants[1],
1E-12);
-        Assert.assertEquals(4 * solution[0] - 3 * solution[1] -5 * solution[2], constants[2],
1E-12);
-
+        RealVector constants = new ArrayRealVector(new double[]{1, -2, 1}, false);
+        RealVector solution = new LUDecompositionImpl(coefficients).getSolver().solve(constants);
+        final double cst0 = constants.getEntry(0);
+        final double cst1 = constants.getEntry(1);
+        final double cst2 = constants.getEntry(2);
+        final double sol0 = solution.getEntry(0);
+        final double sol1 = solution.getEntry(1);
+        final double sol2 = solution.getEntry(2);
+        Assert.assertEquals(2 * sol0 + 3 * sol1 -2 * sol2, cst0, 1E-12);
+        Assert.assertEquals(-1 * sol0 + 7 * sol1 + 6 * sol2, cst1, 1E-12);
+        Assert.assertEquals(4 * sol0 - 3 * sol1 -5 * sol2, cst2, 1E-12);
     }
 
     // test submatrix accessors

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealMatrixTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealMatrixTest.java?rev=1164618&r1=1164617&r2=1164618&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealMatrixTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/linear/SparseRealMatrixTest.java
Fri Sep  2 16:40:18 2011
@@ -387,14 +387,17 @@ public final class SparseRealMatrixTest 
         double[][] coefficientsData = { { 2, 3, -2 }, { -1, 7, 6 },
                 { 4, -3, -5 } };
         RealMatrix coefficients = createSparseMatrix(coefficientsData);
-        double[] constants = { 1, -2, 1 };
-        double[] solution = new LUDecompositionImpl(coefficients).getSolver().solve(constants);
-        Assert.assertEquals(2 * solution[0] + 3 * solution[1] - 2 * solution[2],
-                constants[0], 1E-12);
-        Assert.assertEquals(-1 * solution[0] + 7 * solution[1] + 6 * solution[2],
-                constants[1], 1E-12);
-        Assert.assertEquals(4 * solution[0] - 3 * solution[1] - 5 * solution[2],
-                constants[2], 1E-12);
+        RealVector constants = new ArrayRealVector(new double[]{ 1, -2, 1 }, false);
+        RealVector solution = new LUDecompositionImpl(coefficients).getSolver().solve(constants);
+        final double cst0 = constants.getEntry(0);
+        final double cst1 = constants.getEntry(1);
+        final double cst2 = constants.getEntry(2);
+        final double sol0 = solution.getEntry(0);
+        final double sol1 = solution.getEntry(1);
+        final double sol2 = solution.getEntry(2);
+        Assert.assertEquals(2 * sol0 + 3 * sol1 - 2 * sol2, cst0, 1E-12);
+        Assert.assertEquals(-1 * sol0 + 7 * sol1 + 6 * sol2, cst1, 1E-12);
+        Assert.assertEquals(4 * sol0 - 3 * sol1 - 5 * sol2, cst2, 1E-12);
 
     }
 



Mime
View raw message