JAL-2379 made SparseMatrix.divide() so as to exactly match
[jalview.git] / test / jalview / math / SparseMatrixTest.java
index 5e32e18..3c2ccaa 100644 (file)
@@ -134,7 +134,7 @@ public class SparseMatrixTest
      * also check m2.preMultiply(m1) - should be same as m1.postMultiply(m2) 
      */
     MatrixI m4 = m2.preMultiply(m1);
-    assertMatricesMatch(m3, m4);
+    assertMatricesMatch(m3, m4, 0.00001d);
 
     /*
      * m1 has more rows than columns
@@ -154,7 +154,7 @@ public class SparseMatrixTest
     assertEquals(m3.getValue(1, 2), 3000d);
 
     m4 = m2.preMultiply(m1);
-    assertMatricesMatch(m3, m4);
+    assertMatricesMatch(m3, m4, 0.00001d);
 
     /*
      * m1 has more columns than rows
@@ -176,7 +176,7 @@ public class SparseMatrixTest
      * and check premultiply equivalent
      */
     m4 = m2.preMultiply(m1);
-    assertMatricesMatch(m3, m4);
+    assertMatricesMatch(m3, m4, 0.00001d);
   }
 
   @Test(groups = "Timing")
@@ -201,8 +201,7 @@ public class SparseMatrixTest
     /*
      * make a pseudo-random symmetric matrix as required for tred/tqli
      */
-    // TODO why does this fail for rows > 9??
-    int rows = 9;
+    int rows = 10;
     int cols = rows;
     double[][] d = getSparseValues(rows, cols, 3);
 
@@ -220,13 +219,13 @@ public class SparseMatrixTest
     }
     Matrix m1 = new Matrix(d);
     Matrix m2 = new SparseMatrix(d1);
-    assertMatricesMatch(m1, m2); // sanity check
+    assertMatricesMatch(m1, m2, 0.00001d); // sanity check
     m1.tred();
     m2.tred();
-    assertMatricesMatch(m1, m2);
+    assertMatricesMatch(m1, m2, 0.00001d);
   }
 
-  private void assertMatricesMatch(MatrixI m1, MatrixI m2)
+  private void assertMatricesMatch(MatrixI m1, MatrixI m2, double delta)
   {
     if (m1.height() != m2.height())
     {
@@ -248,7 +247,7 @@ public class SparseMatrixTest
         }
       }
     }
-    ArrayAsserts.assertArrayEquals(m1.getD(), m2.getD(), 0.00001d);
+    ArrayAsserts.assertArrayEquals(m1.getD(), m2.getD(), delta);
     ArrayAsserts.assertArrayEquals(m1.getE(), m2.getE(), 0.00001d);
   }
 
@@ -303,11 +302,11 @@ public class SparseMatrixTest
     // have to do tred() before doing tqli()
     m1.tred();
     m2.tred();
-    assertMatricesMatch(m1, m2);
+    assertMatricesMatch(m1, m2, 0.00001d);
 
     m1.tqli();
     m2.tqli();
-    assertMatricesMatch(m1, m2);
+    assertMatricesMatch(m1, m2, 0.00001d);
   }
 
   /**
@@ -409,9 +408,9 @@ public class SparseMatrixTest
     }
     Matrix m1 = new SparseMatrix(d);
     Matrix m2 = new SparseMatrix(d1);
-    assertMatricesMatch(m1, m2); // sanity check
+    assertMatricesMatch(m1, m2, 1.0e16); // sanity check
     m1.tred();
     m2.tred();
-    assertMatricesMatch(m1, m2);
+    assertMatricesMatch(m1, m2, 0.00001d);
   }
 }
\ No newline at end of file