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 |
|
|
25 |
|
import jalview.datamodel.AlignmentI; |
26 |
|
import jalview.io.DataSourceType; |
27 |
|
import jalview.io.FileLoader; |
28 |
|
|
29 |
|
import java.awt.Font; |
30 |
|
import java.awt.FontMetrics; |
31 |
|
|
32 |
|
import org.testng.annotations.Test; |
33 |
|
|
34 |
|
import junit.extensions.PA; |
35 |
|
|
|
|
| 85.4% |
Uncovered Elements: 22 (151) |
Complexity: 3 |
Complexity Density: 0.02 |
|
36 |
|
public class SeqCanvasTest |
37 |
|
{ |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (80) |
Complexity: 1 |
Complexity Density: 0.01 |
1PASS
|
|
42 |
1 |
@Test(groups = "Functional")... |
43 |
|
public void testCalculateWrappedGeometry_noAnnotations() |
44 |
|
{ |
45 |
1 |
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( |
46 |
|
"examples/uniref50.fa", DataSourceType.FILE); |
47 |
1 |
AlignViewport av = af.getViewport(); |
48 |
1 |
AlignmentI al = av.getAlignment(); |
49 |
1 |
assertEquals(al.getWidth(), 157); |
50 |
1 |
assertEquals(al.getHeight(), 15); |
51 |
1 |
av.getRanges().setStartEndSeq(0, 14); |
52 |
|
|
53 |
1 |
SeqCanvas testee = af.alignPanel.getSeqPanel().seqCanvas; |
54 |
|
|
55 |
1 |
av.setWrapAlignment(true); |
56 |
1 |
av.setFont(new Font("SansSerif", Font.PLAIN, 14), true); |
57 |
1 |
int charHeight = av.getCharHeight(); |
58 |
1 |
int charWidth = av.getCharWidth(); |
59 |
1 |
assertEquals(charHeight, 17); |
60 |
1 |
assertEquals(charWidth, 12); |
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
1 |
av.setShowAnnotation(false); |
66 |
1 |
av.setScaleAboveWrapped(true); |
67 |
1 |
av.setScaleLeftWrapped(true); |
68 |
1 |
av.setScaleRightWrapped(true); |
69 |
1 |
FontMetrics fm = testee.getFontMetrics(av.getFont()); |
70 |
1 |
int labelWidth = fm.stringWidth("000") + charWidth; |
71 |
1 |
assertEquals(labelWidth, 39); |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
1 |
int canvasWidth = 400; |
78 |
1 |
int canvasHeight = 300; |
79 |
1 |
int residueColumns = (canvasWidth - 2 * labelWidth) / charWidth; |
80 |
1 |
int wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
81 |
1 |
assertEquals(wrappedWidth, residueColumns); |
82 |
1 |
assertEquals(PA.getValue(testee, "labelWidthWest"), labelWidth); |
83 |
1 |
assertEquals(PA.getValue(testee, "labelWidthEast"), labelWidth); |
84 |
1 |
assertEquals(PA.getValue(testee, "wrappedSpaceAboveAlignment"), |
85 |
|
2 * charHeight); |
86 |
1 |
int repeatingHeight = (int) PA.getValue(testee, "wrappedRepeatHeightPx"); |
87 |
1 |
assertEquals(repeatingHeight, charHeight * (2 + al.getHeight())); |
88 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 1); |
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
95 |
1 |
canvasHeight = charHeight * (17 * 2 + 3); |
96 |
1 |
testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
97 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 3); |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
1 |
canvasHeight -= 1; |
104 |
1 |
testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
105 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 2); |
106 |
|
|
107 |
|
|
108 |
|
|
109 |
|
|
110 |
1 |
av.setScaleAboveWrapped(false); |
111 |
1 |
testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
112 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 3); |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
1 |
canvasHeight = charHeight * (16 * 2 + 2) - 1; |
119 |
1 |
testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
120 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 2); |
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
1 |
canvasWidth = 2 * labelWidth + 20 * charWidth; |
126 |
1 |
wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
127 |
|
canvasHeight); |
128 |
1 |
assertEquals(wrappedWidth, 20); |
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
1 |
canvasWidth -= 1; |
134 |
1 |
wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
135 |
|
canvasHeight); |
136 |
1 |
assertEquals(wrappedWidth, 19); |
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
1 |
av.setScaleLeftWrapped(false); |
143 |
1 |
wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
144 |
|
canvasHeight); |
145 |
1 |
assertEquals(wrappedWidth, 23); |
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
1 |
canvasWidth += 9; |
151 |
1 |
wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
152 |
|
canvasHeight); |
153 |
1 |
assertEquals(wrappedWidth, 23); |
154 |
1 |
canvasWidth += 1; |
155 |
1 |
wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
156 |
|
canvasHeight); |
157 |
1 |
assertEquals(wrappedWidth, 24); |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
1 |
av.setScaleRightWrapped(false); |
163 |
1 |
wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
164 |
|
canvasHeight); |
165 |
1 |
assertEquals(wrappedWidth, 27); |
166 |
|
|
167 |
|
|
168 |
|
|
169 |
|
|
170 |
1 |
canvasWidth += 8; |
171 |
1 |
wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
172 |
|
canvasHeight); |
173 |
1 |
assertEquals(wrappedWidth, 27); |
174 |
1 |
canvasWidth += 1; |
175 |
1 |
wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
176 |
|
canvasHeight); |
177 |
1 |
assertEquals(wrappedWidth, 28); |
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
1 |
av.setScaleLeftWrapped(true); |
183 |
1 |
wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
184 |
|
canvasHeight); |
185 |
1 |
assertEquals(wrappedWidth, 24); |
186 |
|
|
187 |
|
|
188 |
|
|
189 |
|
|
190 |
1 |
canvasWidth += 2; |
191 |
1 |
wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
192 |
|
canvasHeight); |
193 |
1 |
assertEquals(wrappedWidth, 24); |
194 |
1 |
canvasWidth += 1; |
195 |
1 |
wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, |
196 |
|
canvasHeight); |
197 |
1 |
assertEquals(wrappedWidth, 25); |
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
1 |
av.setScaleLeftWrapped(false); |
203 |
1 |
canvasWidth = al.getWidth() * charWidth; |
204 |
1 |
testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
205 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 1); |
206 |
|
} |
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (47) |
Complexity: 1 |
Complexity Density: 0.02 |
1PASS
|
|
212 |
1 |
@Test(groups = "Functional")... |
213 |
|
public void testCalculateWrappedGeometry_withAnnotations() |
214 |
|
{ |
215 |
1 |
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( |
216 |
|
"examples/uniref50.fa", DataSourceType.FILE); |
217 |
1 |
AlignViewport av = af.getViewport(); |
218 |
1 |
AlignmentI al = av.getAlignment(); |
219 |
1 |
assertEquals(al.getWidth(), 157); |
220 |
1 |
assertEquals(al.getHeight(), 15); |
221 |
|
|
222 |
1 |
av.setWrapAlignment(true); |
223 |
1 |
av.getRanges().setStartEndSeq(0, 14); |
224 |
1 |
av.setFont(new Font("SansSerif", Font.PLAIN, 14), true); |
225 |
1 |
int charHeight = av.getCharHeight(); |
226 |
1 |
int charWidth = av.getCharWidth(); |
227 |
1 |
assertEquals(charHeight, 17); |
228 |
1 |
assertEquals(charWidth, 12); |
229 |
|
|
230 |
1 |
SeqCanvas testee = af.alignPanel.getSeqPanel().seqCanvas; |
231 |
|
|
232 |
|
|
233 |
|
|
234 |
|
|
235 |
1 |
av.setShowAnnotation(true); |
236 |
1 |
av.setScaleAboveWrapped(true); |
237 |
1 |
av.setScaleLeftWrapped(true); |
238 |
1 |
av.setScaleRightWrapped(true); |
239 |
1 |
FontMetrics fm = testee.getFontMetrics(av.getFont()); |
240 |
1 |
int labelWidth = fm.stringWidth("000") + charWidth; |
241 |
1 |
assertEquals(labelWidth, 39); |
242 |
1 |
int annotationHeight = testee.getAnnotationHeight(); |
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
|
|
248 |
1 |
int canvasWidth = 400; |
249 |
1 |
int canvasHeight = 300; |
250 |
1 |
int residueColumns = (canvasWidth - 2 * labelWidth) / charWidth; |
251 |
1 |
int wrappedWidth = testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
252 |
1 |
assertEquals(wrappedWidth, residueColumns); |
253 |
1 |
assertEquals(PA.getValue(testee, "labelWidthWest"), labelWidth); |
254 |
1 |
assertEquals(PA.getValue(testee, "labelWidthEast"), labelWidth); |
255 |
1 |
assertEquals(PA.getValue(testee, "wrappedSpaceAboveAlignment"), |
256 |
|
2 * charHeight); |
257 |
1 |
int repeatingHeight = (int) PA.getValue(testee, "wrappedRepeatHeightPx"); |
258 |
1 |
assertEquals(repeatingHeight, charHeight * (2 + al.getHeight()) |
259 |
|
+ annotationHeight); |
260 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 1); |
261 |
|
|
262 |
|
|
263 |
|
|
264 |
|
|
265 |
|
|
266 |
|
|
267 |
1 |
canvasHeight = charHeight * (17 * 2 + 3) + 2 * annotationHeight; |
268 |
1 |
testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
269 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 3); |
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
|
275 |
1 |
canvasHeight -= 1; |
276 |
1 |
testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
277 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 2); |
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
1 |
av.setScaleAboveWrapped(false); |
283 |
1 |
testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
284 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 3); |
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
|
290 |
1 |
canvasHeight = charHeight * (16 * 2 + 2) + 2 * annotationHeight - 1; |
291 |
1 |
testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
292 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 2); |
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
|
297 |
1 |
canvasHeight += 1; |
298 |
1 |
testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
299 |
1 |
assertEquals(PA.getValue(testee, "wrappedVisibleWidths"), 3); |
300 |
|
} |
301 |
|
|
302 |
|
|
303 |
|
|
304 |
|
|
305 |
|
|
306 |
|
|
307 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 1 |
Complexity Density: 0.05 |
3FAIL
|
|
308 |
0 |
@Test(groups = "Functional")... |
309 |
|
public void testCalculateWrappedGeometry_fromScrolled() |
310 |
|
{ |
311 |
0 |
AlignFrame af = new FileLoader().LoadFileWaitTillLoaded( |
312 |
|
"examples/uniref50.fa", DataSourceType.FILE); |
313 |
0 |
AlignViewport av = af.getViewport(); |
314 |
0 |
AlignmentI al = av.getAlignment(); |
315 |
0 |
assertEquals(al.getWidth(), 157); |
316 |
0 |
assertEquals(al.getHeight(), 15); |
317 |
0 |
av.getRanges().setStartEndSeq(0, 3); |
318 |
0 |
av.setShowAnnotation(false); |
319 |
0 |
av.setScaleAboveWrapped(true); |
320 |
|
|
321 |
0 |
SeqCanvas testee = af.alignPanel.getSeqPanel().seqCanvas; |
322 |
|
|
323 |
0 |
av.setWrapAlignment(true); |
324 |
0 |
av.setFont(new Font("SansSerif", Font.PLAIN, 14), true); |
325 |
0 |
int charHeight = av.getCharHeight(); |
326 |
0 |
int charWidth = av.getCharWidth(); |
327 |
0 |
assertEquals(charHeight, 17); |
328 |
0 |
assertEquals(charWidth, 12); |
329 |
|
|
330 |
0 |
int canvasWidth = 400; |
331 |
0 |
int canvasHeight = 300; |
332 |
0 |
testee.calculateWrappedGeometry(canvasWidth, canvasHeight); |
333 |
|
|
334 |
0 |
assertEquals(av.getRanges().getEndSeq(), 3); |
335 |
0 |
int repeatingHeight = (int) PA.getValue(testee, |
336 |
|
"wrappedRepeatHeightPx"); |
337 |
0 |
assertEquals(repeatingHeight, charHeight * (2 + al.getHeight())); |
338 |
|
} |
339 |
|
} |