X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fmath%2FSparseMatrixTest.java;fp=test%2Fjalview%2Fmath%2FSparseMatrixTest.java;h=321286caf1f309755f3c9586017e573877daafc1;hb=3459a8a691cb22508d7067f240b7254e588e77d3;hp=3c2ccaa21f8aac9f889c34cf1246e11c2b8e44d8;hpb=5b27f1062b2203c4c31702e205f4c78e1992063e;p=jalview.git diff --git a/test/jalview/math/SparseMatrixTest.java b/test/jalview/math/SparseMatrixTest.java index 3c2ccaa..321286c 100644 --- a/test/jalview/math/SparseMatrixTest.java +++ b/test/jalview/math/SparseMatrixTest.java @@ -1,3 +1,23 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$) + * Copyright (C) $$Year-Rel$$ The Jalview Authors + * + * This file is part of Jalview. + * + * Jalview is free software: you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 + * of the License, or (at your option) any later version. + * + * Jalview is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Jalview. If not, see . + * The Jalview Authors are detailed in the 'AUTHORS' file. + */ package jalview.math; import static org.testng.Assert.assertEquals; @@ -20,7 +40,8 @@ public class SparseMatrixTest public void testConstructor() { MatrixI m1 = new SparseMatrix( - new double[][] { { 2, 0, 4 }, { 0, 6, 0 } }); + new double[][] + { { 2, 0, 4 }, { 0, 6, 0 } }); assertEquals(m1.getValue(0, 0), 2d); assertEquals(m1.getValue(0, 1), 0d); assertEquals(m1.getValue(0, 2), 4d); @@ -33,7 +54,8 @@ public class SparseMatrixTest public void testTranspose() { MatrixI m1 = new SparseMatrix( - new double[][] { { 2, 0, 4 }, { 5, 6, 0 } }); + new double[][] + { { 2, 0, 4 }, { 5, 6, 0 } }); MatrixI m2 = m1.transpose(); assertTrue(m2 instanceof SparseMatrix); assertEquals(m2.height(), 3); @@ -45,6 +67,7 @@ public class SparseMatrixTest assertEquals(m2.getValue(2, 0), 4d); assertEquals(m2.getValue(2, 1), 0d); } + @Test(groups = "Functional") public void testPreMultiply() { @@ -80,11 +103,13 @@ public class SparseMatrixTest @Test( groups = "Functional", - expectedExceptions = { IllegalArgumentException.class }) + expectedExceptions = + { IllegalArgumentException.class }) public void testPreMultiply_tooManyColumns() { Matrix m1 = new SparseMatrix( - new double[][] { { 2, 3, 4 }, { 3, 4, 5 } }); // 2x3 + new double[][] + { { 2, 3, 4 }, { 3, 4, 5 } }); // 2x3 /* * 2x3 times 2x3 invalid operation - @@ -96,11 +121,13 @@ public class SparseMatrixTest @Test( groups = "Functional", - expectedExceptions = { IllegalArgumentException.class }) + expectedExceptions = + { IllegalArgumentException.class }) public void testPreMultiply_tooFewColumns() { Matrix m1 = new SparseMatrix( - new double[][] { { 2, 3, 4 }, { 3, 4, 5 } }); // 2x3 + new double[][] + { { 2, 3, 4 }, { 3, 4, 5 } }); // 2x3 /* * 3x2 times 3x2 invalid operation - @@ -109,7 +136,7 @@ public class SparseMatrixTest m1.preMultiply(m1); fail("Expected exception"); } - + @Test(groups = "Functional") public void testPostMultiply() { @@ -122,8 +149,9 @@ public class SparseMatrixTest * (5040 50400) */ MatrixI m1 = new SparseMatrix(new double[][] { { 2, 3 }, { 4, 5 } }); - MatrixI m2 = new SparseMatrix(new double[][] { { 10, 100 }, - { 1000, 10000 } }); + MatrixI m2 = new SparseMatrix( + new double[][] + { { 10, 100 }, { 1000, 10000 } }); MatrixI m3 = m1.postMultiply(m2); assertEquals(m3.getValue(0, 0), 3020d); assertEquals(m3.getValue(0, 1), 30200d); @@ -283,7 +311,7 @@ public class SparseMatrixTest int rows = 6; int cols = rows; double[][] d = getSparseValues(rows, cols, 3); - + /* * make a copy of the values so m1, m2 are not * sharing arrays! @@ -352,10 +380,11 @@ public class SparseMatrixTest @Test(groups = "Functional") public void testPreMultiply_sparseProduct() { - MatrixI m1 = new SparseMatrix(new double[][] { { 1 }, { 0 }, { 0 }, - { 0 }, { 0 } }); // 5x1 + MatrixI m1 = new SparseMatrix( + new double[][] + { { 1 }, { 0 }, { 0 }, { 0 }, { 0 } }); // 5x1 MatrixI m2 = new SparseMatrix(new double[][] { { 1, 1, 1, 1 } }); // 1x4 - + /* * m1.m2 makes a row of 4 1's, and 4 rows of zeros * 20% non-zero so not 'sparse' @@ -375,8 +404,9 @@ public class SparseMatrixTest @Test(groups = "Functional") public void testFillRatio() { - SparseMatrix m1 = new SparseMatrix(new double[][] { { 2, 0, 4, 1, 0 }, - { 0, 6, 0, 0, 0 } }); + SparseMatrix m1 = new SparseMatrix( + new double[][] + { { 2, 0, 4, 1, 0 }, { 0, 6, 0, 0, 0 } }); assertEquals(m1.getFillRatio(), 0.4f); } @@ -393,7 +423,7 @@ public class SparseMatrixTest int rows = 10; int cols = rows; double[][] d = getSparseValues(rows, cols, 3); - + /* * make a copy of the values so m1, m2 are not * sharing arrays!