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