From 1dcf7a8a1ab8fd8fb5259c0aaca2a6c73ed056ad Mon Sep 17 00:00:00 2001 From: gmungoc Date: Wed, 5 Jul 2017 13:37:26 +0100 Subject: [PATCH] JAL-147 additions to unit test, check for negative array index --- src/jalview/datamodel/HiddenSequences.java | 3 ++- test/jalview/datamodel/HiddenSequencesTest.java | 10 ++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/jalview/datamodel/HiddenSequences.java b/src/jalview/datamodel/HiddenSequences.java index a57dc9c..98e9694 100755 --- a/src/jalview/datamodel/HiddenSequences.java +++ b/src/jalview/datamodel/HiddenSequences.java @@ -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; diff --git a/test/jalview/datamodel/HiddenSequencesTest.java b/test/jalview/datamodel/HiddenSequencesTest.java index 5b2bbd4..11b993d 100644 --- a/test/jalview/datamodel/HiddenSequencesTest.java +++ b/test/jalview/datamodel/HiddenSequencesTest.java @@ -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)); } /** -- 1.7.10.2