1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.datamodel; |
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.assertNotSame; |
27 |
|
import static org.testng.Assert.assertNull; |
28 |
|
import static org.testng.Assert.assertSame; |
29 |
|
import static org.testng.Assert.assertTrue; |
30 |
|
import static org.testng.Assert.fail; |
31 |
|
|
32 |
|
import jalview.analysis.Conservation; |
33 |
|
import jalview.schemes.NucleotideColourScheme; |
34 |
|
import jalview.schemes.PIDColourScheme; |
35 |
|
|
36 |
|
import java.awt.Color; |
37 |
|
import java.util.ArrayList; |
38 |
|
import java.util.Collections; |
39 |
|
import java.util.List; |
40 |
|
|
41 |
|
import org.testng.annotations.Test; |
42 |
|
|
43 |
|
import junit.extensions.PA; |
44 |
|
|
|
|
| 98.4% |
Uncovered Elements: 3 (187) |
Complexity: 10 |
Complexity Density: 0.06 |
|
45 |
|
public class SequenceGroupTest |
46 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
47 |
1 |
@Test(groups = { "Functional" })... |
48 |
|
public void testAddSequence() |
49 |
|
{ |
50 |
1 |
SequenceGroup sg = new SequenceGroup(); |
51 |
1 |
assertTrue(sg.getSequences().isEmpty()); |
52 |
|
|
53 |
1 |
SequenceI seq1 = new Sequence("seq1", "abc"); |
54 |
1 |
SequenceI seq2 = new Sequence("seq2", "abc"); |
55 |
1 |
SequenceI seq3 = new Sequence(seq1); |
56 |
|
|
57 |
1 |
sg.addSequence(null, false); |
58 |
1 |
assertTrue(sg.getSequences().isEmpty()); |
59 |
1 |
sg.addSequence(seq1, false); |
60 |
1 |
assertEquals(sg.getSequences().size(), 1); |
61 |
1 |
assertTrue(sg.getSequences().contains(seq1)); |
62 |
|
|
63 |
1 |
sg.addSequence(seq1, false); |
64 |
1 |
assertEquals(sg.getSequences().size(), 1); |
65 |
1 |
assertTrue(sg.getSequences().contains(seq1)); |
66 |
1 |
sg.addSequence(seq2, false); |
67 |
1 |
sg.addSequence(seq2, false); |
68 |
1 |
sg.addSequence(seq3, false); |
69 |
1 |
assertEquals(sg.getSequences().size(), 3); |
70 |
1 |
assertTrue(sg.getSequences().contains(seq1)); |
71 |
1 |
assertTrue(sg.getSequences().contains(seq2)); |
72 |
1 |
assertTrue(sg.getSequences().contains(seq3)); |
73 |
|
} |
74 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
75 |
1 |
@Test(groups = { "Functional" })... |
76 |
|
public void testAddOrRemove() |
77 |
|
{ |
78 |
1 |
SequenceGroup sg = new SequenceGroup(); |
79 |
1 |
assertTrue(sg.getSequences().isEmpty()); |
80 |
|
|
81 |
1 |
SequenceI seq1 = new Sequence("seq1", "abc"); |
82 |
1 |
SequenceI seq2 = new Sequence("seq2", "abc"); |
83 |
1 |
SequenceI seq3 = new Sequence(seq1); |
84 |
|
|
85 |
1 |
sg.addOrRemove(seq1, false); |
86 |
1 |
assertEquals(sg.getSequences().size(), 1); |
87 |
1 |
sg.addOrRemove(seq2, false); |
88 |
1 |
assertEquals(sg.getSequences().size(), 2); |
89 |
1 |
sg.addOrRemove(seq3, false); |
90 |
1 |
assertEquals(sg.getSequences().size(), 3); |
91 |
1 |
assertTrue(sg.getSequences().contains(seq1)); |
92 |
1 |
assertTrue(sg.getSequences().contains(seq2)); |
93 |
1 |
assertTrue(sg.getSequences().contains(seq3)); |
94 |
1 |
sg.addOrRemove(seq1, false); |
95 |
1 |
assertEquals(sg.getSequences().size(), 2); |
96 |
1 |
assertFalse(sg.getSequences().contains(seq1)); |
97 |
|
} |
98 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
99 |
1 |
@Test(groups = { "Functional" })... |
100 |
|
public void testGetColourScheme() |
101 |
|
{ |
102 |
1 |
SequenceGroup sg = new SequenceGroup(); |
103 |
1 |
assertNotNull(sg.getGroupColourScheme()); |
104 |
1 |
assertNull(sg.getColourScheme()); |
105 |
|
|
106 |
1 |
sg.setGroupColourScheme(null); |
107 |
1 |
assertNull(sg.getColourScheme()); |
108 |
|
|
109 |
1 |
NucleotideColourScheme scheme = new NucleotideColourScheme(); |
110 |
1 |
sg.setColourScheme(scheme); |
111 |
1 |
assertSame(scheme, sg.getColourScheme()); |
112 |
|
} |
113 |
|
|
|
|
| 91.2% |
Uncovered Elements: 3 (34) |
Complexity: 4 |
Complexity Density: 0.12 |
1PASS
|
|
114 |
1 |
@Test(groups = { "Functional" })... |
115 |
|
public void testSetContext() |
116 |
|
{ |
117 |
1 |
SequenceGroup sg1 = new SequenceGroup(); |
118 |
1 |
SequenceGroup sg2 = new SequenceGroup(); |
119 |
1 |
SequenceGroup sg3 = new SequenceGroup(); |
120 |
1 |
assertNull(sg1.getContext()); |
121 |
1 |
sg1.setContext(null); |
122 |
1 |
assertNull(sg1.getContext()); |
123 |
1 |
try |
124 |
|
{ |
125 |
1 |
sg1.setContext(sg1); |
126 |
0 |
fail("Expected exception"); |
127 |
|
} catch (IllegalArgumentException e) |
128 |
|
{ |
129 |
|
|
130 |
1 |
assertNull(sg1.getContext()); |
131 |
|
} |
132 |
1 |
sg1.setContext(sg2); |
133 |
1 |
assertSame(sg2, sg1.getContext()); |
134 |
1 |
sg2.setContext(sg3); |
135 |
1 |
try |
136 |
|
{ |
137 |
1 |
sg3.setContext(sg1); |
138 |
0 |
fail("Expected exception"); |
139 |
|
} catch (IllegalArgumentException e) |
140 |
|
{ |
141 |
|
|
142 |
1 |
assertNull(sg3.getContext()); |
143 |
|
} |
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
1 |
PA.setValue(sg2, "context", sg2); |
150 |
1 |
try |
151 |
|
{ |
152 |
1 |
sg3.setContext(sg2, false); |
153 |
0 |
fail("Expected exception"); |
154 |
|
} catch (IllegalArgumentException e) |
155 |
|
{ |
156 |
|
|
157 |
1 |
assertNull(sg3.getContext()); |
158 |
|
} |
159 |
|
|
160 |
|
|
161 |
1 |
sg2 = new SequenceGroup(); |
162 |
1 |
sg1.setContext(null, false); |
163 |
1 |
assertFalse(sg1.isDefined()); |
164 |
|
|
165 |
1 |
sg1.setContext(sg2, false); |
166 |
1 |
assertFalse(sg1.isDefined()); |
167 |
|
|
168 |
1 |
sg1.setContext(sg2, true); |
169 |
1 |
assertTrue(sg1.isDefined()); |
170 |
|
|
171 |
|
|
172 |
1 |
sg1.setContext(null); |
173 |
1 |
assertTrue(sg1.isDefined()); |
174 |
|
|
175 |
1 |
sg1.setContext(null, false); |
176 |
1 |
sg1.setContext(sg2); |
177 |
1 |
assertFalse(sg1.isDefined()); |
178 |
|
} |
179 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (33) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
180 |
1 |
@Test(groups = { "Functional" })... |
181 |
|
public void testContains() |
182 |
|
{ |
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
|
|
188 |
1 |
SequenceI seq1 = new Sequence("seq1", "ABCDEF---GHI"); |
189 |
1 |
SequenceI seq2 = new Sequence("seq2", "---JKLMNO---"); |
190 |
1 |
AlignmentI a = new Alignment(new SequenceI[] { seq1, seq2 }); |
191 |
|
|
192 |
|
|
193 |
|
|
194 |
1 |
SequenceGroup sg1 = new SequenceGroup(); |
195 |
1 |
sg1.addSequence(seq1, false); |
196 |
1 |
sg1.setStartRes(3); |
197 |
1 |
sg1.setEndRes(5); |
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
202 |
1 |
assertTrue(sg1.contains(seq1)); |
203 |
1 |
assertFalse(sg1.contains(seq2)); |
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
|
209 |
1 |
assertFalse(sg1.contains(seq1, 2)); |
210 |
1 |
assertFalse(sg1.contains(seq1, 6)); |
211 |
1 |
assertFalse(sg1.contains(seq2, 5)); |
212 |
1 |
assertTrue(sg1.contains(seq1, 3)); |
213 |
1 |
assertTrue(sg1.contains(seq1, 4)); |
214 |
1 |
assertTrue(sg1.contains(seq1, 5)); |
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
1 |
SequenceGroup sg2 = new SequenceGroup(); |
222 |
1 |
sg2.addSequence(seq1, false); |
223 |
1 |
sg2.addSequence(seq2, false); |
224 |
1 |
sg2.setStartRes(4); |
225 |
1 |
sg2.setEndRes(7); |
226 |
1 |
a.addGroup(sg2); |
227 |
|
|
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
232 |
1 |
assertTrue(sg2.contains(seq1, 4)); |
233 |
1 |
assertTrue(sg2.contains(seq1, 5)); |
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
|
238 |
1 |
assertTrue(sg2.contains(seq2, 4)); |
239 |
1 |
assertTrue(sg2.contains(seq2, 5)); |
240 |
1 |
assertTrue(sg2.contains(seq2, 6)); |
241 |
1 |
assertTrue(sg2.contains(seq2, 7)); |
242 |
1 |
assertFalse(sg2.contains(seq2, 3)); |
243 |
1 |
assertFalse(sg2.contains(seq2, 8)); |
244 |
1 |
sg2.setEndRes(8); |
245 |
1 |
assertTrue(sg2.contains(seq2, 8)); |
246 |
1 |
sg2.deleteSequence(seq2, false); |
247 |
1 |
assertFalse(sg2.contains(seq2)); |
248 |
|
} |
249 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (53) |
Complexity: 1 |
Complexity Density: 0.02 |
1PASS
|
|
250 |
1 |
@Test(groups = { "Functional" })... |
251 |
|
public void testCopyConstructor() |
252 |
|
{ |
253 |
1 |
SequenceI seq = new Sequence("seq", "ABC"); |
254 |
1 |
SequenceGroup sg = new SequenceGroup(); |
255 |
1 |
sg.addSequence(seq, false); |
256 |
1 |
sg.setName("g1"); |
257 |
1 |
sg.setDescription("desc"); |
258 |
1 |
sg.setColourScheme(new PIDColourScheme()); |
259 |
1 |
Conservation cons = new Conservation("Cons", 2, |
260 |
|
Collections.<SequenceI> emptyList(), 3, 12); |
261 |
1 |
PA.setValue(cons, "consSequence", new Sequence("s", "abc")); |
262 |
1 |
sg.getGroupColourScheme().setConservation(cons); |
263 |
1 |
sg.getGroupColourScheme().setConsensus(new Profiles(0,null)); |
264 |
1 |
sg.setDisplayBoxes(false); |
265 |
1 |
sg.setDisplayText(false); |
266 |
1 |
sg.setColourText(true); |
267 |
1 |
sg.isDefined = true; |
268 |
1 |
sg.setShowNonconserved(true); |
269 |
1 |
sg.setOutlineColour(Color.red); |
270 |
1 |
sg.setIdColour(Color.blue); |
271 |
1 |
sg.thresholdTextColour = 1; |
272 |
1 |
sg.textColour = Color.orange; |
273 |
1 |
sg.textColour2 = Color.yellow; |
274 |
1 |
sg.setIgnoreGapsConsensus(false); |
275 |
1 |
sg.setshowSequenceLogo(true); |
276 |
1 |
sg.setNormaliseSequenceLogo(true); |
277 |
1 |
sg.setHidereps(true); |
278 |
1 |
sg.setHideCols(true); |
279 |
1 |
sg.setShowConsensusHistogram(true); |
280 |
1 |
sg.setContext(new SequenceGroup()); |
281 |
|
|
282 |
1 |
SequenceGroup sg2 = new SequenceGroup(sg); |
283 |
1 |
assertEquals(sg2.getName(), sg.getName()); |
284 |
1 |
assertEquals(sg2.getDescription(), sg.getDescription()); |
285 |
1 |
assertNotSame(sg2.getGroupColourScheme(), sg.getGroupColourScheme()); |
286 |
1 |
assertSame(sg2.getColourScheme(), sg.getColourScheme()); |
287 |
1 |
assertSame(PA.getValue(sg2.getGroupColourScheme(), "consensus"), |
288 |
|
PA.getValue(sg.getGroupColourScheme(), "consensus")); |
289 |
1 |
assertSame(PA.getValue(sg2.getGroupColourScheme(), "conservation"), |
290 |
|
PA.getValue(sg.getGroupColourScheme(), "conservation")); |
291 |
1 |
assertEquals(sg2.getDisplayBoxes(), sg.getDisplayBoxes()); |
292 |
1 |
assertEquals(sg2.getDisplayText(), sg.getDisplayText()); |
293 |
1 |
assertEquals(sg2.getColourText(), sg.getColourText()); |
294 |
1 |
assertEquals(sg2.getShowNonconserved(), sg.getShowNonconserved()); |
295 |
1 |
assertEquals(sg2.getOutlineColour(), sg.getOutlineColour()); |
296 |
1 |
assertEquals(sg2.getIdColour(), sg.getIdColour()); |
297 |
1 |
assertEquals(sg2.thresholdTextColour, sg.thresholdTextColour); |
298 |
1 |
assertEquals(sg2.textColour, sg.textColour); |
299 |
1 |
assertEquals(sg2.textColour2, sg.textColour2); |
300 |
1 |
assertEquals(sg2.getIgnoreGapsConsensus(), sg.getIgnoreGapsConsensus()); |
301 |
1 |
assertEquals(sg2.isShowSequenceLogo(), sg.isShowSequenceLogo()); |
302 |
1 |
assertEquals(sg2.isNormaliseSequenceLogo(), |
303 |
|
sg.isNormaliseSequenceLogo()); |
304 |
1 |
assertEquals(sg2.isHidereps(), sg.isHidereps()); |
305 |
1 |
assertEquals(sg2.isHideCols(), sg.isHideCols()); |
306 |
1 |
assertEquals(sg2.isShowConsensusHistogram(), |
307 |
|
sg.isShowConsensusHistogram()); |
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
1 |
assertNotSame(sg2.getSequences(), sg.getSequences()); |
313 |
1 |
assertEquals(sg2.getSequences(), sg.getSequences()); |
314 |
|
|
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
|
319 |
1 |
assertFalse(sg2.isDefined()); |
320 |
|
|
321 |
|
|
322 |
|
|
323 |
|
|
324 |
1 |
assertNull(sg2.getContext()); |
325 |
|
} |
326 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
327 |
1 |
@Test(groups = { "Functional" })... |
328 |
|
public void testConstructor_list() |
329 |
|
{ |
330 |
1 |
SequenceI s1 = new Sequence("abcde", "fg"); |
331 |
1 |
SequenceI s2 = new Sequence("foo", "bar"); |
332 |
1 |
List<SequenceI> seqs = new ArrayList<SequenceI>(); |
333 |
1 |
seqs.add(s1); |
334 |
1 |
seqs.add(s2); |
335 |
1 |
SequenceGroup sg = new SequenceGroup(seqs); |
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
1 |
List<SequenceI> sgList = sg.getSequences(); |
341 |
1 |
assertNotSame(sgList, seqs); |
342 |
1 |
assertEquals(sgList, seqs); |
343 |
|
|
344 |
|
|
345 |
|
|
346 |
|
|
347 |
1 |
sg.addSequence(new Sequence("bar", "foo"), false); |
348 |
1 |
assertEquals(sgList.size(), 3); |
349 |
1 |
assertEquals(seqs.size(), 2); |
350 |
|
|
351 |
|
|
352 |
|
|
353 |
|
|
354 |
1 |
seqs.remove(s1); |
355 |
1 |
assertEquals(sgList.size(), 3); |
356 |
1 |
assertEquals(seqs.size(), 1); |
357 |
|
} |
358 |
|
} |