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