1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.schemes; |
22 |
|
|
23 |
|
import static org.testng.Assert.assertEquals; |
24 |
|
|
25 |
|
import jalview.datamodel.Alignment; |
26 |
|
import jalview.datamodel.AlignmentAnnotation; |
27 |
|
import jalview.datamodel.AlignmentI; |
28 |
|
import jalview.datamodel.Annotation; |
29 |
|
import jalview.datamodel.GraphLine; |
30 |
|
import jalview.datamodel.Sequence; |
31 |
|
import jalview.datamodel.SequenceI; |
32 |
|
|
33 |
|
import java.awt.Color; |
34 |
|
|
35 |
|
import org.testng.annotations.BeforeClass; |
36 |
|
import org.testng.annotations.Test; |
37 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (142) |
Complexity: 27 |
Complexity Density: 0.28 |
|
38 |
|
public class AnnotationColourGradientTest |
39 |
|
{ |
40 |
|
final static int WIDTH = 11; |
41 |
|
|
42 |
|
final static int THRESHOLD_FIVE = 5; |
43 |
|
|
44 |
|
private AlignmentAnnotation ann; |
45 |
|
|
46 |
|
private SequenceI seq; |
47 |
|
|
48 |
|
private AlignmentI al; |
49 |
|
|
50 |
|
Color minColour = new Color(50, 200, 150); |
51 |
|
|
52 |
|
Color maxColour = new Color(150, 100, 250); |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
58 |
1 |
@BeforeClass(alwaysRun = true)... |
59 |
|
public void setUp() |
60 |
|
{ |
61 |
1 |
Annotation[] anns = new Annotation[WIDTH]; |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
12 |
for (int col = 0; col < WIDTH; col++) |
66 |
|
{ |
67 |
11 |
int hue = col * 20; |
68 |
11 |
Color colour = new Color(hue, hue, hue); |
69 |
11 |
anns[col] = new Annotation("a", "a", 'a', col, colour); |
70 |
|
} |
71 |
|
|
72 |
1 |
seq = new Sequence("Seq", ""); |
73 |
1 |
al = new Alignment(new SequenceI[] { seq }); |
74 |
|
|
75 |
|
|
76 |
|
|
77 |
|
|
78 |
1 |
ann = new AlignmentAnnotation("", "", anns); |
79 |
1 |
ann.setThreshold(new GraphLine(THRESHOLD_FIVE, "", Color.RED)); |
80 |
1 |
seq.addAlignmentAnnotation(ann); |
81 |
|
} |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
1PASS
|
|
83 |
1 |
@Test(groups = "Functional")... |
84 |
|
public void testShadeCalculation_noThreshold() |
85 |
|
{ |
86 |
1 |
AnnotationColourGradient testee = new AnnotationColourGradient(ann, |
87 |
|
minColour, maxColour, AnnotationColourGradient.NO_THRESHOLD); |
88 |
12 |
for (int col = 0; col < WIDTH; col++) |
89 |
|
{ |
90 |
11 |
Color result = testee.shadeCalculation(ann, col); |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
11 |
Color expected = new Color(50 + 10 * col, 200 - 10 * col, |
95 |
|
150 + 10 * col); |
96 |
11 |
assertEquals(result, expected, "for column " + col); |
97 |
|
} |
98 |
|
} |
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (29) |
Complexity: 4 |
Complexity Density: 0.17 |
1PASS
|
|
103 |
1 |
@Test(groups = "Functional")... |
104 |
|
public void testShadeCalculation_aboveThreshold() |
105 |
|
{ |
106 |
1 |
AnnotationColourGradient testee = new AnnotationColourGradient(ann, |
107 |
|
minColour, maxColour, AnnotationColourGradient.ABOVE_THRESHOLD); |
108 |
12 |
for (int col = 0; col < WIDTH; col++) |
109 |
|
{ |
110 |
11 |
Color result = testee.shadeCalculation(ann, col); |
111 |
|
|
112 |
|
|
113 |
|
|
114 |
|
|
115 |
11 |
Color expected = new Color(50 + 10 * col, 200 - 10 * col, |
116 |
|
150 + 10 * col); |
117 |
11 |
assertEquals(result, expected, "for column " + col); |
118 |
|
} |
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
1 |
testee.setThresholdIsMinMax(true); |
125 |
6 |
for (int col = 0; col < THRESHOLD_FIVE; col++) |
126 |
|
{ |
127 |
|
|
128 |
|
|
129 |
|
|
130 |
5 |
Color expected = new Color(50 + 10 * col, 200 - 10 * col, |
131 |
|
150 + 10 * col); |
132 |
5 |
Color result = testee.shadeCalculation(ann, col); |
133 |
5 |
assertEquals(result, expected, "for column " + col); |
134 |
|
} |
135 |
7 |
for (int col = THRESHOLD_FIVE; col < WIDTH; col++) |
136 |
|
{ |
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
6 |
int factor = col - THRESHOLD_FIVE; |
142 |
6 |
Color expected = new Color(50 + 20 * factor, 200 - 20 * factor, |
143 |
|
150 + 20 * factor); |
144 |
6 |
Color result = testee.shadeCalculation(ann, col); |
145 |
6 |
assertEquals(result, expected, "for column " + col); |
146 |
|
} |
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
1 |
float thresh = ann.threshold.value; |
152 |
1 |
ann.threshold.value = ann.graphMax; |
153 |
1 |
Color result = testee.shadeCalculation(ann, WIDTH - 1); |
154 |
1 |
assertEquals(result, maxColour); |
155 |
1 |
testee.setThresholdIsMinMax(false); |
156 |
1 |
result = testee.shadeCalculation(ann, WIDTH - 1); |
157 |
1 |
assertEquals(result, maxColour); |
158 |
1 |
ann.threshold.value = thresh; |
159 |
|
} |
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (28) |
Complexity: 4 |
Complexity Density: 0.18 |
1PASS
|
|
164 |
1 |
@Test(groups = "Functional")... |
165 |
|
public void testShadeCalculation_belowThreshold() |
166 |
|
{ |
167 |
1 |
AnnotationColourGradient testee = new AnnotationColourGradient(ann, |
168 |
|
minColour, maxColour, AnnotationColourGradient.BELOW_THRESHOLD); |
169 |
|
|
170 |
12 |
for (int col = 0; col < WIDTH; col++) |
171 |
|
{ |
172 |
11 |
Color result = testee.shadeCalculation(ann, col); |
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
11 |
Color expected = new Color(50 + 10 * col, 200 - 10 * col, |
178 |
|
150 + 10 * col); |
179 |
11 |
assertEquals(result, expected, "for column " + col); |
180 |
|
} |
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
|
186 |
1 |
testee.setThresholdIsMinMax(true); |
187 |
6 |
for (int col = THRESHOLD_FIVE + 1; col < WIDTH; col++) |
188 |
|
{ |
189 |
|
|
190 |
|
|
191 |
|
|
192 |
5 |
Color expected = new Color(50 + 10 * col, 200 - 10 * col, |
193 |
|
150 + 10 * col); |
194 |
5 |
Color result = testee.shadeCalculation(ann, col); |
195 |
5 |
assertEquals(result, expected, "for column " + col); |
196 |
|
} |
197 |
|
|
198 |
7 |
for (int col = 0; col <= THRESHOLD_FIVE; col++) |
199 |
|
{ |
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
6 |
Color expected = new Color(50 + 20 * col, 200 - 20 * col, |
205 |
|
150 + 20 * col); |
206 |
6 |
Color result = testee.shadeCalculation(ann, col); |
207 |
6 |
assertEquals(result, expected, "for column " + col); |
208 |
|
} |
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
1 |
float thresh = ann.threshold.value; |
214 |
1 |
ann.threshold.value = ann.graphMin; |
215 |
1 |
Color result = testee.shadeCalculation(ann, 0); |
216 |
1 |
assertEquals(result, minColour); |
217 |
1 |
testee.setThresholdIsMinMax(false); |
218 |
1 |
result = testee.shadeCalculation(ann, 0); |
219 |
1 |
assertEquals(result, minColour); |
220 |
1 |
ann.threshold.value = thresh; |
221 |
|
} |
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 5 |
Complexity Density: 0.42 |
1PASS
|
|
226 |
1 |
@Test(groups = "Functional")... |
227 |
|
public void testFindColour_aboveThreshold() |
228 |
|
{ |
229 |
1 |
AnnotationColourGradient testee = new AnnotationColourGradient(ann, |
230 |
|
minColour, maxColour, AnnotationColourGradient.ABOVE_THRESHOLD); |
231 |
1 |
testee = (AnnotationColourGradient) testee.getInstance(null, al); |
232 |
|
|
233 |
12 |
for (int col = 0; col < WIDTH; col++) |
234 |
|
{ |
235 |
11 |
Color result = testee.findColour('a', col, seq); |
236 |
|
|
237 |
|
|
238 |
|
|
239 |
11 |
Color expected = col <= 5 ? Color.white |
240 |
|
: new Color(50 + 10 * col, 200 - 10 * col, 150 + 10 * col); |
241 |
11 |
assertEquals(result, expected, "for column " + col); |
242 |
|
} |
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
|
248 |
1 |
testee.setThresholdIsMinMax(true); |
249 |
12 |
for (int col = 0; col < WIDTH; col++) |
250 |
|
{ |
251 |
|
|
252 |
|
|
253 |
|
|
254 |
|
|
255 |
11 |
int factor = col - THRESHOLD_FIVE; |
256 |
11 |
Color expected = col <= 5 ? Color.white |
257 |
|
: new Color(50 + 20 * factor, 200 - 20 * factor, |
258 |
|
150 + 20 * factor); |
259 |
11 |
Color result = testee.findColour('a', col, seq); |
260 |
11 |
assertEquals(result, expected, "for column " + col); |
261 |
|
} |
262 |
|
} |
263 |
|
|
264 |
|
|
265 |
|
|
266 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 5 |
Complexity Density: 0.45 |
1PASS
|
|
267 |
1 |
@Test(groups = "Functional")... |
268 |
|
public void testFindColour_belowThreshold() |
269 |
|
{ |
270 |
1 |
AnnotationColourGradient testee = new AnnotationColourGradient(ann, |
271 |
|
minColour, maxColour, AnnotationColourGradient.BELOW_THRESHOLD); |
272 |
1 |
testee = (AnnotationColourGradient) testee.getInstance(null, al); |
273 |
|
|
274 |
12 |
for (int col = 0; col < WIDTH; col++) |
275 |
|
{ |
276 |
11 |
Color result = testee.findColour('a', col, seq); |
277 |
11 |
Color expected = col >= 5 ? Color.white |
278 |
|
: new Color(50 + 10 * col, 200 - 10 * col, 150 + 10 * col); |
279 |
11 |
assertEquals(result, expected, "for column " + col); |
280 |
|
} |
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
|
286 |
1 |
testee.setThresholdIsMinMax(true); |
287 |
12 |
for (int col = 0; col < WIDTH; col++) |
288 |
|
{ |
289 |
|
|
290 |
|
|
291 |
|
|
292 |
|
|
293 |
11 |
Color expected = col >= 5 ? Color.white |
294 |
|
: new Color(50 + 20 * col, 200 - 20 * col, 150 + 20 * col); |
295 |
11 |
Color result = testee.findColour('a', col, seq); |
296 |
11 |
assertEquals(result, expected, "for column " + col); |
297 |
|
} |
298 |
|
} |
299 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
1PASS
|
|
300 |
1 |
@Test(groups = "Functional")... |
301 |
|
public void testFindColour_noThreshold() |
302 |
|
{ |
303 |
1 |
AnnotationColourGradient testee = new AnnotationColourGradient(ann, |
304 |
|
minColour, maxColour, AnnotationColourGradient.NO_THRESHOLD); |
305 |
1 |
testee = (AnnotationColourGradient) testee.getInstance(null, al); |
306 |
|
|
307 |
12 |
for (int col = 0; col < WIDTH; col++) |
308 |
|
{ |
309 |
11 |
Color result = testee.findColour('a', col, seq); |
310 |
|
|
311 |
|
|
312 |
|
|
313 |
11 |
Color expected = new Color(50 + 10 * col, 200 - 10 * col, |
314 |
|
150 + 10 * col); |
315 |
11 |
assertEquals(result, expected, "for column " + col); |
316 |
|
} |
317 |
|
} |
318 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
1PASS
|
|
319 |
1 |
@Test(groups = "Functional")... |
320 |
|
public void testFindColour_originalColours() |
321 |
|
{ |
322 |
1 |
AnnotationColourGradient testee = new AnnotationColourGradient(ann, |
323 |
|
minColour, maxColour, AnnotationColourGradient.NO_THRESHOLD); |
324 |
1 |
testee = (AnnotationColourGradient) testee.getInstance(null, al); |
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
1 |
testee.setPredefinedColours(true); |
331 |
|
|
332 |
|
|
333 |
|
|
334 |
|
|
335 |
|
|
336 |
12 |
for (int col = 0; col < WIDTH; col++) |
337 |
|
{ |
338 |
11 |
int hue = col * 20; |
339 |
11 |
Color c = col == 0 ? minColour : new Color(hue, hue, hue); |
340 |
11 |
assertEquals(testee.findColour('a', col, seq), c, |
341 |
|
"for column " + col); |
342 |
|
} |
343 |
|
} |
344 |
|
} |