X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fschemes%2FAnnotationColourGradientTest.java;h=3c49ec2e6371098035436881c0873ed4fc0018bf;hb=57738a1f3c19b1c3a00bd3ac5108f8cd0af32f99;hp=8de90bf7fa8276bf151c2ffb9acd251d42765af4;hpb=96d47aa43e18fe1df80d602c5f8744da6ebd77bc;p=jalview.git diff --git a/test/jalview/schemes/AnnotationColourGradientTest.java b/test/jalview/schemes/AnnotationColourGradientTest.java index 8de90bf..3c49ec2 100644 --- a/test/jalview/schemes/AnnotationColourGradientTest.java +++ b/test/jalview/schemes/AnnotationColourGradientTest.java @@ -35,7 +35,7 @@ public class AnnotationColourGradientTest * Setup creates an annotation over 11 columns with values 0-10 and threshold * 5 */ - @BeforeClass + @BeforeClass(alwaysRun = true) public void setUp() { Annotation[] anns = new Annotation[WIDTH]; @@ -49,9 +49,9 @@ public class AnnotationColourGradientTest anns[col] = new Annotation("a", "a", 'a', col, colour); } - seq = new Sequence("", ""); - al = new Alignment(new SequenceI[]{ seq}); - + seq = new Sequence("Seq", ""); + al = new Alignment(new SequenceI[] { seq }); + /* * AlignmentAnnotation constructor works out min-max range */ @@ -124,6 +124,18 @@ public class AnnotationColourGradientTest Color result = testee.shadeCalculation(ann, col); assertEquals(result, expected, "for column " + col); } + + /* + * test for boundary case threshold == graphMax (JAL-3206) + */ + float thresh = ann.threshold.value; + ann.threshold.value = ann.graphMax; + Color result = testee.shadeCalculation(ann, WIDTH - 1); + assertEquals(result, maxColour); + testee.setThresholdIsMinMax(false); + result = testee.shadeCalculation(ann, WIDTH - 1); + assertEquals(result, maxColour); + ann.threshold.value = thresh; // reset } /** @@ -174,6 +186,18 @@ public class AnnotationColourGradientTest Color result = testee.shadeCalculation(ann, col); assertEquals(result, expected, "for column " + col); } + + /* + * test for boundary case threshold == graphMin (JAL-3206) + */ + float thresh = ann.threshold.value; + ann.threshold.value = ann.graphMin; + Color result = testee.shadeCalculation(ann, 0); + assertEquals(result, minColour); + testee.setThresholdIsMinMax(false); + result = testee.shadeCalculation(ann, 0); + assertEquals(result, minColour); + ann.threshold.value = thresh; // reset } /** @@ -184,20 +208,19 @@ public class AnnotationColourGradientTest { AnnotationColourGradient testee = new AnnotationColourGradient(ann, minColour, maxColour, AnnotationColourGradient.ABOVE_THRESHOLD); - testee = (AnnotationColourGradient) testee.getInstance(al, null); + testee = (AnnotationColourGradient) testee.getInstance(null, al); for (int col = 0; col < WIDTH; col++) { Color result = testee.findColour('a', col, seq); /* - * expect white below threshold of 5 + * expect white at or below threshold of 5 */ - Color expected = col < 5 ? Color.white : new Color(50 + 10 * col, - 200 - 10 * col, - 150 + 10 * col); + Color expected = col <= 5 ? Color.white + : new Color(50 + 10 * col, 200 - 10 * col, 150 + 10 * col); assertEquals(result, expected, "for column " + col); } - + /* * now make 6-10 the span of the colour range * (annotation value == column number in this test) @@ -206,13 +229,13 @@ public class AnnotationColourGradientTest for (int col = 0; col < WIDTH; col++) { /* - * colours for values >= threshold are graduated + * colours for values > threshold are graduated * range is 6-10 so steps of 100/5 = 20 */ int factor = col - THRESHOLD_FIVE; - Color expected = col < 5 ? Color.white : new Color(50 + 20 * factor, - 200 - 20 * factor, - 150 + 20 * factor); + Color expected = col <= 5 ? Color.white + : new Color(50 + 20 * factor, 200 - 20 * factor, + 150 + 20 * factor); Color result = testee.findColour('a', col, seq); assertEquals(result, expected, "for column " + col); } @@ -226,16 +249,16 @@ public class AnnotationColourGradientTest { AnnotationColourGradient testee = new AnnotationColourGradient(ann, minColour, maxColour, AnnotationColourGradient.BELOW_THRESHOLD); - testee = (AnnotationColourGradient) testee.getInstance(al, null); - + testee = (AnnotationColourGradient) testee.getInstance(null, al); + for (int col = 0; col < WIDTH; col++) { Color result = testee.findColour('a', col, seq); - Color expected = col > 5 ? Color.white : new Color(50 + 10 * col, - 200 - 10 * col, 150 + 10 * col); + Color expected = col >= 5 ? Color.white + : new Color(50 + 10 * col, 200 - 10 * col, 150 + 10 * col); assertEquals(result, expected, "for column " + col); } - + /* * now make 0-5 the span of the colour range * (annotation value == column number in this test) @@ -244,11 +267,11 @@ public class AnnotationColourGradientTest for (int col = 0; col < WIDTH; col++) { /* - * colours for values <= threshold are graduated + * colours for values < threshold are graduated * range is 0-5 so steps of 100/5 = 20 */ - Color expected = col > 5 ? Color.white : new Color(50 + 20 * col, - 200 - 20 * col, 150 + 20 * col); + Color expected = col >= 5 ? Color.white + : new Color(50 + 20 * col, 200 - 20 * col, 150 + 20 * col); Color result = testee.findColour('a', col, seq); assertEquals(result, expected, "for column " + col); } @@ -259,7 +282,7 @@ public class AnnotationColourGradientTest { AnnotationColourGradient testee = new AnnotationColourGradient(ann, minColour, maxColour, AnnotationColourGradient.NO_THRESHOLD); - testee = (AnnotationColourGradient) testee.getInstance(al, null); + testee = (AnnotationColourGradient) testee.getInstance(null, al); for (int col = 0; col < WIDTH; col++) { @@ -278,7 +301,7 @@ public class AnnotationColourGradientTest { AnnotationColourGradient testee = new AnnotationColourGradient(ann, minColour, maxColour, AnnotationColourGradient.NO_THRESHOLD); - testee = (AnnotationColourGradient) testee.getInstance(al, null); + testee = (AnnotationColourGradient) testee.getInstance(null, al); /* * flag corresponding to 'use original colours' checkbox @@ -294,7 +317,8 @@ public class AnnotationColourGradientTest { int hue = col * 20; Color c = col == 0 ? minColour : new Color(hue, hue, hue); - assertEquals(testee.findColour('a', col, seq), c, "for column " + col); + assertEquals(testee.findColour('a', col, seq), c, + "for column " + col); } } }