| 11 | |
| 12 | |
| 13 | public class TestLinearSolver extends TestCase { |
| 14 | |
| 15 | public void checkSoln(final double[][] a, final double[] b, final double[] x, double tol) { |
| 16 | assertNotNull(x); |
| 17 | assertEquals(a[0].length,x.length); |
| 18 | final double[] ax = LinUtil.mult(a,x); |
| 19 | final int m = b.length; |
| 20 | for(int i=0;i<m;++i) { |
| 21 | assertTrue(Math.abs(b[i]-ax[i])<=tol); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | |
| 26 | public void testCGSolver() { |
| 27 | final double[][] a = new double[][] { {4, 1}, {1, 3} }; |
| 28 | final double[] b = new double[] {1, 2}; |
| 29 | final LinearSolver solver = new ConjugateGradientSolver(); |
| 30 | final double[] x = solver.solve(a, b); |
| 31 | checkSoln(a,b,x, 1.0e-6); |
| 32 | |
| 33 | } |
| 34 | |
| 35 | public void testDirectSolver() { |
| 36 | final double[][] a = new double[][] { {4, 1}, {1, 3} }; |
| 37 | final double[] b = new double[] {1, 2}; |
| 38 | final LinearSolver solver = new DirectSolver(); |
| 39 | final double[] x = solver.solve(a, b); |
| 40 | checkSoln(a,b,x, 1.0e-6); |
| 41 | } |
| 42 | |
| 43 | |
| 44 | public void testCholeskySolver() { |
| 45 | final double[][] a = new double[][] { {4, 1}, {1, 3} }; |
| 46 | final double[] b = new double[] {1, 2}; |
| 47 | final LinearSolver solver = new CholeskySolver(); |
| 48 | final double[] x = solver.solve(a, b); |
| 49 | checkSoln(a,b,x, 1.0e-4); |
| 50 | } |
| 51 | } |
nothing calls this directly
no outgoing calls
no test coverage detected