| 1 |
package test.dr.math; |
| 2 |
|
| 3 |
import dr.math.matrixAlgebra.Vector; |
| 4 |
import junit.framework.TestCase; |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
public class MathTestCase extends TestCase { |
| 10 |
|
| 11 |
public MathTestCase() { |
| 12 |
} |
| 13 |
|
| 14 |
public MathTestCase(String name) { |
| 15 |
super(name); |
| 16 |
} |
| 17 |
|
| 18 |
protected void assertEquals(double[][] a, double[][] b, double accuracy) { |
| 19 |
assertEquals(a.length, b.length); |
| 20 |
for (int i = 0; i < a.length; ++i) { |
| 21 |
assertEquals(a[i], b[i], accuracy); |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
protected void assertEquals(double[] a, double[] b, double accuracy) { |
| 26 |
assertEquals(a.length, b.length); |
| 27 |
for (int i = 0; i < a.length; i++) { |
| 28 |
assertEquals(a[i], b[i], accuracy); |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
protected void printSquareMatrix(double[] A, int dim) { |
| 33 |
double[] row = new double[dim]; |
| 34 |
for (int i = 0; i < dim; i++) { |
| 35 |
System.arraycopy(A, i * dim, row, 0, dim); |
| 36 |
System.out.println(new Vector(row)); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
protected static double accumulate(double[] vector) { |
| 41 |
double total = 0; |
| 42 |
for (double x : vector) { |
| 43 |
total += x; |
| 44 |
} |
| 45 |
return total; |
| 46 |
} |
| 47 |
} |