1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.gui; |
22 |
|
|
23 |
|
import static org.testng.Assert.assertEquals; |
24 |
|
import static org.testng.Assert.assertFalse; |
25 |
|
import static org.testng.Assert.assertNotNull; |
26 |
|
import static org.testng.Assert.assertNull; |
27 |
|
import static org.testng.Assert.assertTrue; |
28 |
|
|
29 |
|
import java.awt.Font; |
30 |
|
import java.awt.FontMetrics; |
31 |
|
|
32 |
|
import org.testng.annotations.BeforeMethod; |
33 |
|
import org.testng.annotations.Test; |
34 |
|
|
35 |
|
import jalview.bin.Cache; |
36 |
|
import jalview.datamodel.AlignmentI; |
37 |
|
import jalview.datamodel.SearchResults; |
38 |
|
import jalview.datamodel.SearchResultsI; |
39 |
|
import jalview.io.DataSourceType; |
40 |
|
import jalview.io.FileLoader; |
41 |
|
import junit.extensions.PA; |
42 |
|
|
|
|
| 87% |
Uncovered Elements: 22 (169) |
Complexity: 7 |
Complexity Density: 0.04 |
|
43 |
|
public class SeqCanvasTest |
44 |
|
{ |
45 |
|
private AlignFrame af; |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (80) |
Complexity: 1 |
Complexity Density: 0.01 |
1PASS
|
|
51 |
1 |
@Test(groups = "Functional")... |
52 |
|
public void testCalculateWrappedGeometry_noAnnotations() |
53 |
|
{ |
54 |
1 |
AlignViewport av = af.getViewport(); |
55 |
1 |
AlignmentI al = av.getAlignment(); |
56 |
1 |
assertEquals(al.getWidth(), 157); |
57 |
1 |
assertEquals(al.getHeight(), 15); |
58 |
1 |
av.getRanges().setStartEndSeq(0, 14); |
59 |
|
|
60 |
1 |
SeqCanvas testee = af.alignPanel.getSeqPanel().seqCanvas; |
61 |
|
|
62 |
1 |
av.setWrapAlignment(true); |
63 |
1 |
av.setFont(new Font("SansSerif", Font.PLAIN, 14), true); |
64 |
1 |
int charHeight = av.getCharHeight(); |
65 |
1 |
int charWidth = av.getCharWidth(); |
66 |
1 |
assertEquals(charHeight, 17); |
67 |
1 |
assertEquals(charWidth, 12); |
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
1 |
av.setShowAnnotation(false); |
73 |
1 |
av.setScaleAboveWrapped(true); |
74 |
1 |
av.setScaleLeftWrapped(true); |
75 |
1 |
av.setScaleRightWrapped(true); |
76 |
1 |
FontMetrics fm = testee.getFontMetrics(av.getFont()); |
77 |
1 |
int labelWidth = fm.stringWidth("000") + charWidth; |
78 |
|
|
79 |
1 |
assertTrue(labelWidth >= 36 && labelWidth <= 39); |
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
1 |
int canvasWidth = 400; |
86 |
1 |
int canvasHeight = 300; |
87 |
1 |
int residueColumns = (canvasWidth - 2 * labelWidth) / charWidth; |
88 |
1 |
int wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
89 |
|
canvasHeight); |
90 |
1 |
assertEquals(wrappedWidth, residueColumns); |
91 |
1 |
assertEquals(PA.getValue(testee, "labelWidthWest"), labelWidth); |
92 |
1 |
assertEquals(PA.getValue(testee, "labelWidthEast"), labelWidth); |
93 |
1 |
assertEquals(PA.getValue(testee, "wrappedSpaceAboveAlignment"), |
94 |
|
2 * charHeight); |
95 |
1 |
int repeatingHeight = (int) PA.getValue(testee, |
96 |
|
"wrappedRepeatHeightPx"); |
97 |
1 |
assertEquals(repeatingHeight, charHeight * (2 + al.getHeight())); |
98 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 1); |
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
1 |
canvasHeight = charHeight * (17 * 2 + 3); |
106 |
1 |
testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
107 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 3); |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
|
113 |
1 |
canvasHeight -= 1; |
114 |
1 |
testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
115 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 2); |
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
1 |
av.setScaleAboveWrapped(false); |
121 |
1 |
testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
122 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 3); |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
1 |
canvasHeight = charHeight * (16 * 2 + 2) - 1; |
129 |
1 |
testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
130 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 2); |
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
1 |
canvasWidth = 2 * labelWidth + 20 * charWidth; |
136 |
1 |
wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
137 |
|
canvasHeight); |
138 |
1 |
assertEquals(wrappedWidth, 20); |
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
|
143 |
1 |
canvasWidth -= 1; |
144 |
1 |
wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
145 |
|
canvasHeight); |
146 |
1 |
assertEquals(wrappedWidth, 19); |
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
|
152 |
1 |
av.setScaleLeftWrapped(false); |
153 |
1 |
wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
154 |
|
canvasHeight); |
155 |
|
|
156 |
1 |
assertTrue(wrappedWidth >= 22 && wrappedWidth <= 23); |
157 |
1 |
int difference = wrappedWidth - 23; |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
1 |
canvasWidth += 9; |
163 |
1 |
wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
164 |
|
canvasHeight); |
165 |
1 |
assertEquals(wrappedWidth, 23); |
166 |
1 |
canvasWidth += 1; |
167 |
1 |
wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
168 |
|
canvasHeight); |
169 |
1 |
assertEquals(wrappedWidth, 24 + difference); |
170 |
|
|
171 |
|
|
172 |
|
|
173 |
|
|
174 |
1 |
av.setScaleRightWrapped(false); |
175 |
1 |
wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
176 |
|
canvasHeight); |
177 |
1 |
assertEquals(wrappedWidth, 27 + difference); |
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
1 |
canvasWidth += 8; |
183 |
1 |
wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
184 |
|
canvasHeight); |
185 |
1 |
assertEquals(wrappedWidth, 27); |
186 |
1 |
canvasWidth += 1; |
187 |
1 |
wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
188 |
|
canvasHeight); |
189 |
1 |
assertEquals(wrappedWidth, 28 + difference); |
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
|
194 |
1 |
av.setScaleLeftWrapped(true); |
195 |
1 |
wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
196 |
|
canvasHeight); |
197 |
1 |
assertEquals(wrappedWidth, 24); |
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
1 |
canvasWidth += 2; |
203 |
1 |
wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
204 |
|
canvasHeight); |
205 |
1 |
assertEquals(wrappedWidth, 24); |
206 |
1 |
canvasWidth += 1; |
207 |
1 |
wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
208 |
|
canvasHeight); |
209 |
1 |
assertEquals(wrappedWidth, 25 + difference); |
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
1 |
av.setScaleLeftWrapped(false); |
215 |
1 |
canvasWidth = al.getWidth() * charWidth; |
216 |
1 |
testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
217 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 1); |
218 |
|
} |
219 |
|
|
220 |
|
|
221 |
|
|
222 |
|
|
223 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (46) |
Complexity: 1 |
Complexity Density: 0.02 |
1PASS
|
|
224 |
1 |
@Test(groups = "Functional")... |
225 |
|
public void testCalculateWrappedGeometry_withAnnotations() |
226 |
|
{ |
227 |
1 |
AlignViewport av = af.getViewport(); |
228 |
1 |
AlignmentI al = av.getAlignment(); |
229 |
1 |
assertEquals(al.getWidth(), 157); |
230 |
1 |
assertEquals(al.getHeight(), 15); |
231 |
|
|
232 |
1 |
av.setWrapAlignment(true); |
233 |
1 |
av.getRanges().setStartEndSeq(0, 14); |
234 |
1 |
av.setFont(new Font("SansSerif", Font.PLAIN, 14), true); |
235 |
1 |
int charHeight = av.getCharHeight(); |
236 |
1 |
int charWidth = av.getCharWidth(); |
237 |
1 |
assertEquals(charHeight, 17); |
238 |
1 |
assertEquals(charWidth, 12); |
239 |
|
|
240 |
1 |
SeqCanvas testee = af.alignPanel.getSeqPanel().seqCanvas; |
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
|
245 |
1 |
av.setShowAnnotation(true); |
246 |
1 |
av.setScaleAboveWrapped(true); |
247 |
1 |
av.setScaleLeftWrapped(true); |
248 |
1 |
av.setScaleRightWrapped(true); |
249 |
1 |
FontMetrics fm = testee.getFontMetrics(av.getFont()); |
250 |
1 |
int labelWidth = fm.stringWidth("000") + charWidth; |
251 |
|
|
252 |
1 |
assertTrue(labelWidth >= 36 && labelWidth <= 39); |
253 |
1 |
int annotationHeight = testee.getAnnotationHeight(); |
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
1 |
int canvasWidth = 400; |
260 |
1 |
int canvasHeight = 300; |
261 |
1 |
int residueColumns = (canvasWidth - 2 * labelWidth) / charWidth; |
262 |
1 |
int wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
263 |
|
canvasHeight); |
264 |
1 |
assertEquals(wrappedWidth, residueColumns); |
265 |
1 |
assertEquals(PA.getValue(testee, "labelWidthWest"), labelWidth); |
266 |
1 |
assertEquals(PA.getValue(testee, "labelWidthEast"), labelWidth); |
267 |
1 |
assertEquals(PA.getValue(testee, "wrappedSpaceAboveAlignment"), |
268 |
|
2 * charHeight); |
269 |
1 |
int repeatingHeight = (int) PA.getValue(testee, |
270 |
|
"wrappedRepeatHeightPx"); |
271 |
1 |
assertEquals(repeatingHeight, charHeight * (2 + al.getHeight()) |
272 |
|
+ SeqCanvas.SEQS_ANNOTATION_GAP + annotationHeight); |
273 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 1); |
274 |
|
|
275 |
|
|
276 |
|
|
277 |
|
|
278 |
|
|
279 |
|
|
280 |
1 |
canvasHeight = charHeight * (17 * 2 + 3) |
281 |
|
+ 2 * (annotationHeight + SeqCanvas.SEQS_ANNOTATION_GAP); |
282 |
1 |
testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
283 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 3); |
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
|
289 |
1 |
canvasHeight -= 1; |
290 |
1 |
testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
291 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 2); |
292 |
|
|
293 |
|
|
294 |
|
|
295 |
|
|
296 |
1 |
av.setScaleAboveWrapped(false); |
297 |
1 |
testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
298 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 3); |
299 |
|
|
300 |
|
|
301 |
|
|
302 |
|
|
303 |
|
|
304 |
1 |
canvasHeight = charHeight * (16 * 2 + 2) |
305 |
|
+ 2 * (annotationHeight + SeqCanvas.SEQS_ANNOTATION_GAP) - 1; |
306 |
1 |
testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
307 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 2); |
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
1 |
canvasHeight += 1; |
313 |
1 |
testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
314 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 3); |
315 |
|
} |
316 |
|
|
317 |
|
|
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
|
322 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
323 |
0 |
@Test(groups = "Functional_Failing")... |
324 |
|
public void testCalculateWrappedGeometry_fromScrolled() |
325 |
|
{ |
326 |
0 |
AlignViewport av = af.getViewport(); |
327 |
0 |
AlignmentI al = av.getAlignment(); |
328 |
0 |
assertEquals(al.getWidth(), 157); |
329 |
0 |
assertEquals(al.getHeight(), 15); |
330 |
0 |
av.getRanges().setStartEndSeq(0, 3); |
331 |
0 |
av.setFont(new Font("SansSerif", Font.PLAIN, 14), true); |
332 |
0 |
av.setWrapAlignment(true); |
333 |
0 |
av.setShowAnnotation(false); |
334 |
0 |
av.setScaleAboveWrapped(true); |
335 |
|
|
336 |
0 |
SeqCanvas testee = af.alignPanel.getSeqPanel().seqCanvas; |
337 |
|
|
338 |
0 |
int charHeight = av.getCharHeight(); |
339 |
0 |
int charWidth = av.getCharWidth(); |
340 |
0 |
assertEquals(charHeight, 17); |
341 |
0 |
assertEquals(charWidth, 12); |
342 |
|
|
343 |
0 |
int canvasWidth = 400; |
344 |
0 |
int canvasHeight = 300; |
345 |
0 |
testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
346 |
|
|
347 |
0 |
assertEquals(av.getRanges().getEndSeq(), 3); |
348 |
0 |
int repeatingHeight = (int) PA.getValue(testee, |
349 |
|
"wrappedRepeatHeightPx"); |
350 |
0 |
assertEquals(repeatingHeight, charHeight * (2 + al.getHeight())); |
351 |
|
} |
352 |
|
|
|
|
| 87.5% |
Uncovered Elements: 1 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
353 |
3 |
@BeforeMethod(alwaysRun = true)... |
354 |
|
public void setUp() |
355 |
|
{ |
356 |
3 |
Cache.loadProperties("test/jalview/io/testProps.jvprops"); |
357 |
3 |
Cache.applicationProperties.setProperty("SHOW_IDENTITY", |
358 |
|
Boolean.TRUE.toString()); |
359 |
3 |
af = new FileLoader().LoadFileWaitTillLoaded("examples/uniref50.fa", |
360 |
|
DataSourceType.FILE); |
361 |
|
|
362 |
|
|
363 |
|
|
364 |
|
|
365 |
3 |
do |
366 |
|
{ |
367 |
3 |
try |
368 |
|
{ |
369 |
3 |
Thread.sleep(50); |
370 |
|
} catch (InterruptedException x) |
371 |
|
{ |
372 |
|
} |
373 |
3 |
} while (af.getViewport().getCalcManager().isWorking()); |
374 |
|
} |
375 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
1PASS
|
|
376 |
1 |
@Test(groups = "Functional")... |
377 |
|
public void testClear_HighlightAndSelection() |
378 |
|
{ |
379 |
1 |
AlignViewport av = af.getViewport(); |
380 |
1 |
SearchResultsI highlight = new SearchResults(); |
381 |
1 |
highlight.addResult( |
382 |
|
av.getAlignment().getSequenceAt(1).getDatasetSequence(), 50, |
383 |
|
80); |
384 |
1 |
af.alignPanel.highlightSearchResults(highlight); |
385 |
1 |
af.avc.markHighlightedColumns(false, false, false); |
386 |
1 |
assertNotNull(av.getSearchResults(), |
387 |
|
"No highlight was created on alignment"); |
388 |
1 |
assertFalse(av.getColumnSelection().isEmpty(), |
389 |
|
"No selection was created from highlight"); |
390 |
1 |
af.deselectAllSequenceMenuItem_actionPerformed(null); |
391 |
1 |
assertTrue(av.getColumnSelection().isEmpty(), |
392 |
|
"No Selection should be present after deselecting all."); |
393 |
1 |
assertNull(av.getSearchResults(), |
394 |
|
"No higlighted search results should be present after deselecting all."); |
395 |
|
} |
396 |
|
} |