JAL-147 additions to unit test, check for negative array index
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 5 Jul 2017 12:37:26 +0000 (13:37 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 5 Jul 2017 12:37:26 +0000 (13:37 +0100)
src/jalview/datamodel/HiddenSequences.java
test/jalview/datamodel/HiddenSequencesTest.java

index a57dc9c..98e9694 100755 (executable)
@@ -157,9 +157,10 @@ public class HiddenSequences
     int absAlignmentIndex = alignment.findIndex(sequence);
     int alignmentIndex = adjustForHiddenSeqs(absAlignmentIndex);
 
-    if (hiddenSequences[alignmentIndex] != null)
+    if (alignmentIndex < 0 || hiddenSequences[alignmentIndex] != null)
     {
       System.out.println("ERROR!!!!!!!!!!!");
+      return;
     }
 
     hiddenSequences[alignmentIndex] = sequence;
index 5b2bbd4..11b993d 100644 (file)
@@ -208,15 +208,17 @@ public class HiddenSequencesTest
     assertEquals(6, hs.findIndexWithoutHiddenSeqs(9));
 
     /*
-     * hide first sequence only
+     * hide first two sequences
      */
     hs.showAll(null);
     hs.hideSequence(seqs[0]);
-    for (int i = 1; i < height; i++)
+    hs.hideSequence(seqs[1]);
+    assertEquals(-1, hs.findIndexWithoutHiddenSeqs(0));
+    assertEquals(-1, hs.findIndexWithoutHiddenSeqs(1));
+    for (int i = 2; i < height; i++)
     {
-      assertEquals(i - 1, hs.findIndexWithoutHiddenSeqs(i));
+      assertEquals(i - 2, hs.findIndexWithoutHiddenSeqs(i));
     }
-    assertEquals(-1, hs.findIndexWithoutHiddenSeqs(0));
   }
 
   /**