X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fmath%2FMatrixTest.java;fp=test%2Fjalview%2Fmath%2FMatrixTest.java;h=a4acbd00c335ad5176deaf5805b9aaaca95b40a7;hb=05d2ce87440717d47ba3dc6ef293e25e4543fdd1;hp=795b2fad0dd7a3685e1813b7d13eb923f9c227be;hpb=8b844f70b97629d597be49cb6ac0d83c8da007c9;p=jalview.git diff --git a/test/jalview/math/MatrixTest.java b/test/jalview/math/MatrixTest.java index 795b2fa..a4acbd0 100644 --- a/test/jalview/math/MatrixTest.java +++ b/test/jalview/math/MatrixTest.java @@ -1,9 +1,11 @@ package jalview.math; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; import java.util.Arrays; +import java.util.Random; import org.testng.annotations.Test; @@ -16,8 +18,8 @@ public class MatrixTest int cols = 1000; double[][] d1 = new double[rows][cols]; double[][] d2 = new double[cols][rows]; - Matrix m1 = new Matrix(d1, rows, cols); - Matrix m2 = new Matrix(d2, cols, rows); + Matrix m1 = new Matrix(d1); + Matrix m2 = new Matrix(d2); long start = System.currentTimeMillis(); m1.preMultiply(m2); long elapsed = System.currentTimeMillis() - start; @@ -28,8 +30,8 @@ public class MatrixTest @Test(groups = "Functional") public void testPreMultiply() { - Matrix m1 = new Matrix(new double[][] { { 2, 3, 4 } }, 1, 3); // 1x3 - Matrix m2 = new Matrix(new double[][] { { 5 }, { 6 }, { 7 } }, 3, 1); // 3x1 + Matrix m1 = new Matrix(new double[][] { { 2, 3, 4 } }); // 1x3 + Matrix m2 = new Matrix(new double[][] { { 5 }, { 6 }, { 7 } }); // 3x1 /* * 1x3 times 3x1 is 1x1 @@ -56,8 +58,7 @@ public class MatrixTest expectedExceptions = { IllegalArgumentException.class }) public void testPreMultiply_tooManyColumns() { - Matrix m1 = new Matrix(new double[][] { { 2, 3, 4 }, { 3, 4, 5 } }, 2, - 3); // 2x3 + Matrix m1 = new Matrix(new double[][] { { 2, 3, 4 }, { 3, 4, 5 } }); // 2x3 /* * 2x3 times 2x3 invalid operation - @@ -72,8 +73,7 @@ public class MatrixTest expectedExceptions = { IllegalArgumentException.class }) public void testPreMultiply_tooFewColumns() { - Matrix m1 = new Matrix(new double[][] { { 2, 3, 4 }, { 3, 4, 5 } }, 2, - 3); // 2x3 + Matrix m1 = new Matrix(new double[][] { { 2, 3, 4 }, { 3, 4, 5 } }); // 2x3 /* * 3x2 times 3x2 invalid operation - @@ -99,9 +99,8 @@ public class MatrixTest * (3020 30200) * (5040 50400) */ - Matrix m1 = new Matrix(new double[][] { { 2, 3 }, { 4, 5 } }, 2, 2); - Matrix m2 = new Matrix(new double[][] { { 10, 100 }, { 1000, 10000 } }, - 2, 2); + Matrix m1 = new Matrix(new double[][] { { 2, 3 }, { 4, 5 } }); + Matrix m2 = new Matrix(new double[][] { { 10, 100 }, { 1000, 10000 } }); Matrix m3 = m1.postMultiply(m2); assertEquals(Arrays.toString(m3.value[0]), "[3020.0, 30200.0]"); assertEquals(Arrays.toString(m3.value[1]), "[5040.0, 50400.0]"); @@ -118,8 +117,8 @@ public class MatrixTest * (2).(10 100 1000) = (20 200 2000) * (3) (30 300 3000) */ - m1 = new Matrix(new double[][] { { 2 }, { 3 } }, 2, 1); - m2 = new Matrix(new double[][] { { 10, 100, 1000 } }, 1, 3); + m1 = new Matrix(new double[][] { { 2 }, { 3 } }); + m2 = new Matrix(new double[][] { { 10, 100, 1000 } }); m3 = m1.postMultiply(m2); assertEquals(m3.rows, 2); assertEquals(m3.cols, 3); @@ -139,8 +138,8 @@ public class MatrixTest * [0, 0] = 2*5 + 3*6 + 4*7 = 56 * [0, 1] = 2*4 + 3*3 + 4*2 = 25 */ - m1 = new Matrix(new double[][] { { 2, 3, 4 } }, 1, 3); - m2 = new Matrix(new double[][] { { 5, 4 }, { 6, 3 }, { 7, 2 } }, 3, 2); + m1 = new Matrix(new double[][] { { 2, 3, 4 } }); + m2 = new Matrix(new double[][] { { 5, 4 }, { 6, 3 }, { 7, 2 } }); m3 = m1.postMultiply(m2); assertEquals(m3.rows, 1); assertEquals(m3.cols, 2); @@ -157,6 +156,26 @@ public class MatrixTest assertEquals(m3.value[0][1], 25d); } + @Test(groups = "Functional") + public void testCopy() + { + Random r = new Random(); + int rows = 5; + int cols = 11; + double[][] in = new double[rows][cols]; + + for (int i = 0; i < rows; i++) + { + for (int j = 0; j < cols; j++) + { + in[i][j] = r.nextDouble(); + } + } + Matrix m1 = new Matrix(in); + Matrix m2 = m1.copy(); + assertTrue(matrixEquals(m1, m2)); + } + /** * main method extracted from Matrix * @@ -175,7 +194,7 @@ public class MatrixTest } } - Matrix origmat = new Matrix(in, n, n); + Matrix origmat = new Matrix(in); // System.out.println(" --- Original matrix ---- "); // / origmat.print(System.out);