Units tests of RealMatrix implementations: replaced reference to DecompositionSolver.solve(double[]) by DecompositionSolver.solve(RealVector) (see MATH-653)

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1164618 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Sebastien Brisard 2011-09-02 16:40:18 +00:00
parent c76d918c77
commit 118387e272
3 changed files with 49 additions and 36 deletions

View File

@ -437,12 +437,17 @@ public final class Array2DRowRealMatrixTest {
// Solve example // Solve example
double[][] coefficientsData = {{2, 3, -2}, {-1, 7, 6}, {4, -3, -5}}; double[][] coefficientsData = {{2, 3, -2}, {-1, 7, 6}, {4, -3, -5}};
RealMatrix coefficients = new Array2DRowRealMatrix(coefficientsData); RealMatrix coefficients = new Array2DRowRealMatrix(coefficientsData);
double[] constants = {1, -2, 1}; RealVector constants = new ArrayRealVector(new double[]{1, -2, 1}, false);
double[] solution = new LUDecompositionImpl(coefficients).getSolver().solve(constants); RealVector solution = new LUDecompositionImpl(coefficients).getSolver().solve(constants);
Assert.assertEquals(2 * solution[0] + 3 * solution[1] -2 * solution[2], constants[0], 1E-12); final double cst0 = constants.getEntry(0);
Assert.assertEquals(-1 * solution[0] + 7 * solution[1] + 6 * solution[2], constants[1], 1E-12); final double cst1 = constants.getEntry(1);
Assert.assertEquals(4 * solution[0] - 3 * solution[1] -5 * solution[2], constants[2], 1E-12); 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 // test submatrix accessors

View File

@ -482,12 +482,17 @@ public final class BlockRealMatrixTest {
// Solve example // Solve example
double[][] coefficientsData = {{2, 3, -2}, {-1, 7, 6}, {4, -3, -5}}; double[][] coefficientsData = {{2, 3, -2}, {-1, 7, 6}, {4, -3, -5}};
RealMatrix coefficients = new BlockRealMatrix(coefficientsData); RealMatrix coefficients = new BlockRealMatrix(coefficientsData);
double[] constants = {1, -2, 1}; RealVector constants = new ArrayRealVector(new double[]{1, -2, 1}, false);
double[] solution = new LUDecompositionImpl(coefficients).getSolver().solve(constants); RealVector solution = new LUDecompositionImpl(coefficients).getSolver().solve(constants);
Assert.assertEquals(2 * solution[0] + 3 * solution[1] -2 * solution[2], constants[0], 1E-12); final double cst0 = constants.getEntry(0);
Assert.assertEquals(-1 * solution[0] + 7 * solution[1] + 6 * solution[2], constants[1], 1E-12); final double cst1 = constants.getEntry(1);
Assert.assertEquals(4 * solution[0] - 3 * solution[1] -5 * solution[2], constants[2], 1E-12); 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 // test submatrix accessors

View File

@ -387,14 +387,17 @@ public final class SparseRealMatrixTest {
double[][] coefficientsData = { { 2, 3, -2 }, { -1, 7, 6 }, double[][] coefficientsData = { { 2, 3, -2 }, { -1, 7, 6 },
{ 4, -3, -5 } }; { 4, -3, -5 } };
RealMatrix coefficients = createSparseMatrix(coefficientsData); RealMatrix coefficients = createSparseMatrix(coefficientsData);
double[] constants = { 1, -2, 1 }; RealVector constants = new ArrayRealVector(new double[]{ 1, -2, 1 }, false);
double[] solution = new LUDecompositionImpl(coefficients).getSolver().solve(constants); RealVector solution = new LUDecompositionImpl(coefficients).getSolver().solve(constants);
Assert.assertEquals(2 * solution[0] + 3 * solution[1] - 2 * solution[2], final double cst0 = constants.getEntry(0);
constants[0], 1E-12); final double cst1 = constants.getEntry(1);
Assert.assertEquals(-1 * solution[0] + 7 * solution[1] + 6 * solution[2], final double cst2 = constants.getEntry(2);
constants[1], 1E-12); final double sol0 = solution.getEntry(0);
Assert.assertEquals(4 * solution[0] - 3 * solution[1] - 5 * solution[2], final double sol1 = solution.getEntry(1);
constants[2], 1E-12); 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);
} }