From 29ee0c7591b0ce7b07abc34a219f532f9b914ac0 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Wed, 1 Mar 2017 15:19:09 +0000 Subject: [PATCH] JAL-1264 smarter way to skip autocalc'd annotations in asserts --- test/jalview/gui/AnnotationChooserTest.java | 118 ++++++++++++++------------- 1 file changed, 63 insertions(+), 55 deletions(-) diff --git a/test/jalview/gui/AnnotationChooserTest.java b/test/jalview/gui/AnnotationChooserTest.java index cf97711..fbdda09 100644 --- a/test/jalview/gui/AnnotationChooserTest.java +++ b/test/jalview/gui/AnnotationChooserTest.java @@ -60,11 +60,6 @@ import org.testng.annotations.Test; */ public class AnnotationChooserTest { - /* - * number of automatically computed annotation rows - * (Conservation, Quality, Consensus, Occupancy) - */ - private static final int AUTOCALCD = 4; @BeforeClass(alwaysRun = true) public void setUpJvOptionPane() @@ -363,8 +358,9 @@ public class AnnotationChooserTest AlignmentAnnotation[] anns = parentPanel.getAlignment() .getAlignmentAnnotation(); - assertTrue(anns[AUTOCALCD + 2].visible); // JMol for seq3 - assertTrue(anns[AUTOCALCD + 4].visible); // JMol for seq1 + int autocalc = countAutocalc(anns); + assertTrue(anns[autocalc + 2].visible); // JMol for seq3 + assertTrue(anns[autocalc + 4].visible); // JMol for seq1 setSelected(getTypeCheckbox("JMol"), true); assertTrue(anns[0].visible); // Conservation @@ -402,7 +398,8 @@ public class AnnotationChooserTest AlignmentAnnotation[] anns = parentPanel.getAlignment() .getAlignmentAnnotation(); - assertTrue(anns[AUTOCALCD + 4].visible); // JMol for seq1 + int autocalc = countAutocalc(anns); + assertTrue(anns[autocalc + 4].visible); // JMol for seq1 setSelected(getTypeCheckbox("JMol"), true); assertTrue(anns[0].visible); // Conservation @@ -443,20 +440,35 @@ public class AnnotationChooserTest // select JMol - all hidden setSelected(typeCheckbox, true); - assertFalse(anns[AUTOCALCD + 2].visible); // JMol for seq3 - assertFalse(anns[AUTOCALCD + 4].visible); // JMol for seq1 + int autocalc = countAutocalc(anns); + assertFalse(anns[autocalc + 2].visible); // JMol for seq3 + assertFalse(anns[autocalc + 4].visible); // JMol for seq1 // deselect JMol - all unhidden setSelected(typeCheckbox, false); - assertTrue(anns[0].visible); // Conservation - assertTrue(anns[1].visible); // Quality - assertTrue(anns[2].visible); // Consensus - assertTrue(anns[3].visible); // Occupancy - assertTrue(anns[4].visible); // IUPred for seq0 - assertTrue(anns[5].visible); // Beauty - assertTrue(anns[6].visible); // JMol for seq3 - assertTrue(anns[7].visible); // IUPRED for seq2 - assertTrue(anns[8].visible); // JMol for seq1 + for (AlignmentAnnotation ann : anns) + { + assertTrue(ann.visible); + } + } + + /** + * Returns a count of autocalculated annotations in the set provided + * + * @param anns + * @return + */ + private int countAutocalc(AlignmentAnnotation[] anns) + { + int count = 0; + for (AlignmentAnnotation ann : anns) + { + if (ann.autoCalculated) + { + count++; + } + } + return count; } /** @@ -519,19 +531,15 @@ public class AnnotationChooserTest setSelected(allSequencesCheckbox, true); setSelected(hideCheckbox, true); setSelected(getTypeCheckbox("JMol"), true); - assertFalse(anns[AUTOCALCD + 2].visible); // JMol for seq3 - assertFalse(anns[AUTOCALCD + 4].visible); // JMol for seq1 + int autocalc = countAutocalc(anns); + assertFalse(anns[autocalc + 2].visible); // JMol for seq3 + assertFalse(anns[autocalc + 4].visible); // JMol for seq1 // ...now show them... setSelected(showCheckbox, true); - assertTrue(anns[0].visible); // Conservation - assertTrue(anns[1].visible); // Quality - assertTrue(anns[2].visible); // Consensus - assertTrue(anns[3].visible); // Occupancy - assertTrue(anns[4].visible); // IUPred for seq0 - assertTrue(anns[5].visible); // Beauty - assertTrue(anns[6].visible); // JMol for seq3 - assertTrue(anns[7].visible); // IUPRED for seq2 - assertTrue(anns[8].visible); // JMol for seq1 + for (AlignmentAnnotation ann : anns) + { + assertTrue(ann.visible); + } } /** @@ -561,20 +569,16 @@ public class AnnotationChooserTest setSelected(hideCheckbox, true); setSelected(getTypeCheckbox("JMol"), true); - assertTrue(anns[AUTOCALCD + 2].visible); // JMol for seq3 - assertFalse(anns[AUTOCALCD + 4].visible); // JMol for seq1 + int autocalc = countAutocalc(anns); + assertTrue(anns[autocalc + 2].visible); // JMol for seq3 + assertFalse(anns[autocalc + 4].visible); // JMol for seq1 // ...now show them... setSelected(showCheckbox, true); - assertTrue(anns[0].visible); // Conservation - assertTrue(anns[1].visible); // Quality - assertTrue(anns[2].visible); // Consensus - assertTrue(anns[3].visible); // Occupancy - assertTrue(anns[4].visible); // IUPred for seq0 - assertTrue(anns[5].visible); // Beauty - assertTrue(anns[6].visible); // JMol for seq3 - assertTrue(anns[7].visible); // IUPRED for seq2 - assertTrue(anns[8].visible); // JMol for seq1 + for (AlignmentAnnotation ann : anns) + { + assertTrue(ann.visible); + } } /** @@ -603,8 +607,9 @@ public class AnnotationChooserTest final Checkbox typeCheckbox = getTypeCheckbox("JMol"); // select JMol - all shown setSelected(typeCheckbox, true); - assertTrue(anns[AUTOCALCD + 2].visible); // JMol for seq3 - assertTrue(anns[AUTOCALCD + 4].visible); // JMol for seq1 + int autocalc = countAutocalc(anns); + assertTrue(anns[autocalc + 2].visible); // JMol for seq3 + assertTrue(anns[autocalc + 4].visible); // JMol for seq1 // deselect JMol - all hidden setSelected(typeCheckbox, false); @@ -645,8 +650,9 @@ public class AnnotationChooserTest // select JMol - should remain visible setSelected(getTypeCheckbox("JMol"), true); - assertTrue(anns[AUTOCALCD + 2].visible); // JMol for seq3 - assertTrue(anns[AUTOCALCD + 4].visible); // JMol for seq1 + int autocalc = countAutocalc(anns); + assertTrue(anns[autocalc + 2].visible); // JMol for seq3 + assertTrue(anns[autocalc + 4].visible); // JMol for seq1 // deselect JMol - should be hidden for selected sequences only setSelected(getTypeCheckbox("JMol"), false); @@ -734,11 +740,12 @@ public class AnnotationChooserTest AlignmentAnnotation[] anns = parentPanel.getAlignment() .getAlignmentAnnotation(); - assertFalse(testee.isInActionScope(anns[AUTOCALCD])); - assertFalse(testee.isInActionScope(anns[AUTOCALCD + 1])); - assertFalse(testee.isInActionScope(anns[AUTOCALCD + 2])); - assertTrue(testee.isInActionScope(anns[AUTOCALCD + 3])); - assertTrue(testee.isInActionScope(anns[AUTOCALCD + 4])); + int autocalc = countAutocalc(anns); + assertFalse(testee.isInActionScope(anns[autocalc])); + assertFalse(testee.isInActionScope(anns[autocalc + 1])); + assertFalse(testee.isInActionScope(anns[autocalc + 2])); + assertTrue(testee.isInActionScope(anns[autocalc + 3])); + assertTrue(testee.isInActionScope(anns[autocalc + 4])); } /** @@ -759,11 +766,12 @@ public class AnnotationChooserTest AlignmentAnnotation[] anns = parentPanel.getAlignment() .getAlignmentAnnotation(); - assertTrue(testee.isInActionScope(anns[AUTOCALCD])); - assertTrue(testee.isInActionScope(anns[AUTOCALCD + 1])); - assertTrue(testee.isInActionScope(anns[AUTOCALCD + 2])); - assertFalse(testee.isInActionScope(anns[AUTOCALCD + 3])); - assertFalse(testee.isInActionScope(anns[AUTOCALCD + 4])); + int autocalc = countAutocalc(anns); + assertTrue(testee.isInActionScope(anns[autocalc])); + assertTrue(testee.isInActionScope(anns[autocalc + 1])); + assertTrue(testee.isInActionScope(anns[autocalc + 2])); + assertFalse(testee.isInActionScope(anns[autocalc + 3])); + assertFalse(testee.isInActionScope(anns[autocalc + 4])); } /** -- 1.7.10.2