JAL-147 additions to unit test, check for negative array index
[jalview.git] / test / jalview / datamodel / HiddenSequencesTest.java
index a556458..11b993d 100644 (file)
@@ -181,7 +181,8 @@ public class HiddenSequencesTest
   {
     AlignmentI al = new Alignment(seqs);
     HiddenSequences hs = al.getHiddenSequences();
-    for (int i = 0; i < SEQ_COUNT; i++)
+    int height = al.getHeight();
+    for (int i = 0; i < height; i++)
     {
       assertEquals(i, hs.findIndexWithoutHiddenSeqs(i));
     }
@@ -194,7 +195,7 @@ public class HiddenSequencesTest
     /*
      * alignment is now seq0/2/3/4/7/8/9
      */
-    assertEquals(SEQ_COUNT - 3, al.getHeight());
+    assertEquals(height - 3, al.getHeight());
     assertEquals(0, hs.findIndexWithoutHiddenSeqs(0));
     assertEquals(0, hs.findIndexWithoutHiddenSeqs(1));
     assertEquals(1, hs.findIndexWithoutHiddenSeqs(2));
@@ -205,6 +206,19 @@ public class HiddenSequencesTest
     assertEquals(4, hs.findIndexWithoutHiddenSeqs(7));
     assertEquals(5, hs.findIndexWithoutHiddenSeqs(8));
     assertEquals(6, hs.findIndexWithoutHiddenSeqs(9));
+
+    /*
+     * hide first two sequences
+     */
+    hs.showAll(null);
+    hs.hideSequence(seqs[0]);
+    hs.hideSequence(seqs[1]);
+    assertEquals(-1, hs.findIndexWithoutHiddenSeqs(0));
+    assertEquals(-1, hs.findIndexWithoutHiddenSeqs(1));
+    for (int i = 2; i < height; i++)
+    {
+      assertEquals(i - 2, hs.findIndexWithoutHiddenSeqs(i));
+    }
   }
 
   /**
@@ -219,15 +233,15 @@ public class HiddenSequencesTest
 
     // test that without hidden rows, findIndexNFromRow returns
     // position n above provided position
-    int pos = hs.findIndexNAboveRow(3, 10);
+    int pos = hs.subtractVisibleRows(3, 10);
     assertEquals(7, pos);
 
     // 0 returns same position
-    pos = hs.findIndexNAboveRow(0, 10);
+    pos = hs.subtractVisibleRows(0, 10);
     assertEquals(10, pos);
 
     // overflow to top returns negative number
-    pos = hs.findIndexNAboveRow(3, 0);
+    pos = hs.subtractVisibleRows(3, 0);
     assertEquals(-3, pos);
 
     // test that with hidden rows above result row
@@ -237,11 +251,11 @@ public class HiddenSequencesTest
     hs.hideSequence(seqs[3]);
 
     // position n above provided position
-    pos = hs.findIndexNAboveRow(3, 10);
+    pos = hs.subtractVisibleRows(3, 10);
     assertEquals(7, pos);
 
     // 0 returns same position
-    pos = hs.findIndexNAboveRow(0, 10);
+    pos = hs.subtractVisibleRows(0, 10);
     assertEquals(10, pos);
 
     // test with one set of hidden rows between start and required position
@@ -249,13 +263,13 @@ public class HiddenSequencesTest
     hs.hideSequence(seqs[13]);
     hs.hideSequence(seqs[14]);
     hs.hideSequence(seqs[15]);
-    pos = hs.findIndexNAboveRow(8, 17);
+    pos = hs.subtractVisibleRows(8, 17);
     assertEquals(5, pos);
 
     // test with two sets of hidden rows between start and required position
     hs.hideSequence(seqs[20]);
     hs.hideSequence(seqs[21]);
-    pos = hs.findIndexNAboveRow(8, 23);
+    pos = hs.subtractVisibleRows(8, 23);
     assertEquals(9, pos);
 
     // repeat last 2 tests with no hidden columns to left of required position
@@ -266,13 +280,13 @@ public class HiddenSequencesTest
     hs.hideSequence(seqs[13]);
     hs.hideSequence(seqs[14]);
     hs.hideSequence(seqs[15]);
-    pos = hs.findIndexNAboveRow(8, 17);
+    pos = hs.subtractVisibleRows(8, 17);
     assertEquals(5, pos);
 
     // test with two sets of hidden rows between start and required position
     hs.hideSequence(seqs[20]);
     hs.hideSequence(seqs[21]);
-    pos = hs.findIndexNAboveRow(8, 23);
+    pos = hs.subtractVisibleRows(8, 23);
     assertEquals(9, pos);
 
   }