1 package jalview.schemes;
3 import static org.testng.Assert.assertEquals;
7 import jalview.datamodel.AlignmentAnnotation;
8 import jalview.datamodel.Annotation;
9 import jalview.datamodel.GraphLine;
11 import org.testng.annotations.BeforeClass;
12 import org.testng.annotations.Test;
14 public class AnnotationColourGradientTest
16 final static int WIDTH = 11;
18 final static int THRESHOLD = 5;
20 private AlignmentAnnotation ann;
22 Color minColour = new Color(50, 200, 150);
24 Color maxColour = new Color(150, 100, 250);
29 Annotation[] anns = new Annotation[WIDTH];
31 * set annotations with values 0-10
33 for (int col = 0; col < WIDTH; col++)
35 anns[col] = new Annotation("a", "a", 'a', col);
39 * AlignmentAnnotation constructor works out min-max range
41 ann = new AlignmentAnnotation("", "", anns);
42 ann.setThreshold(new GraphLine(THRESHOLD, "", Color.RED));
45 @Test(groups = "Functional")
46 public void testShadeCalculation_noThreshold()
48 AnnotationColourGradient testee = new AnnotationColourGradient(ann,
49 minColour, maxColour, AnnotationColourGradient.NO_THRESHOLD);
50 for (int col = 0; col < WIDTH; col++)
52 Color result = testee.shadeCalculation(ann, col);
54 * column <n> is n/10 of the way from minCol to maxCol
56 Color expected = new Color(50 + 10 * col, 200 - 10 * col,
58 assertEquals(result, expected, "for column " + col);
63 * Test the 'colour above threshold' case
65 @Test(groups = "Functional")
66 public void testShadeCalculation_aboveThreshold()
68 AnnotationColourGradient testee = new AnnotationColourGradient(ann,
69 minColour, maxColour, AnnotationColourGradient.ABOVE_THRESHOLD);
70 for (int col = 0; col < WIDTH; col++)
72 Color result = testee.shadeCalculation(ann, col);
74 * colour is derived regardless of the threshold value
75 * (the renderer that will suppress colouring if
76 * above/below threshold)
78 Color expected = new Color(50 + 10 * col, 200 - 10 * col,
80 assertEquals(result, expected, "for column " + col);
84 * now make 6-10 the span of the colour range
85 * (annotation value == column number in this test)
87 testee.setThresholdIsMinMax(true);
88 for (int col = 0; col < THRESHOLD; col++)
91 * colours below the threshold are computed as before
93 Color expected = new Color(50 + 10 * col, 200 - 10 * col,
95 Color result = testee.shadeCalculation(ann, col);
96 assertEquals(result, expected, "for column " + col);
98 for (int col = THRESHOLD; col < WIDTH; col++)
101 * colours for values >= threshold are graduated
102 * range is 6-10 so steps of 100/5 = 20
104 int factor = col - THRESHOLD;
105 Color expected = new Color(50 + 20 * factor, 200 - 20 * factor,
107 Color result = testee.shadeCalculation(ann, col);
108 assertEquals(result, expected, "for column " + col);
113 * Test the 'colour below threshold' case
115 @Test(groups = "Functional")
116 public void testShadeCalculation_belowThreshold()
119 * change threshold to 5 so we have an easy calculation of
120 * the min-max range 0-5
123 ann.setThreshold(new GraphLine(threshold, "", Color.RED));
124 AnnotationColourGradient testee = new AnnotationColourGradient(ann,
125 minColour, maxColour, AnnotationColourGradient.BELOW_THRESHOLD);
127 for (int col = 0; col < WIDTH; col++)
129 Color result = testee.shadeCalculation(ann, col);
131 * colour is derived regardless of the threshold value
132 * (the renderer that will suppress colouring if
133 * above/below threshold)
135 Color expected = new Color(50 + 10 * col, 200 - 10 * col,
137 assertEquals(result, expected, "for column " + col);
141 * now make 0-5 the span of the colour range
142 * (annotation value == column number in this test)
144 testee.setThresholdIsMinMax(true);
145 for (int col = threshold + 1; col < WIDTH; col++)
148 * colours above the threshold are computed as before
150 Color expected = new Color(50 + 10 * col, 200 - 10 * col,
152 Color result = testee.shadeCalculation(ann, col);
153 assertEquals(result, expected, "for column " + col);
156 for (int col = 0; col <= threshold; col++)
159 * colours for values <= threshold are graduated
160 * range is 0-5 so steps of 100/5 = 20
162 Color expected = new Color(50 + 20 * col, 200 - 20 * col,
164 Color result = testee.shadeCalculation(ann, col);
165 assertEquals(result, expected, "for column " + col);