1 package jalview.datamodel;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNull;
5 import static org.junit.Assert.assertSame;
6 import static org.junit.Assert.assertTrue;
10 import org.junit.Before;
11 import org.junit.Test;
13 public class SequenceTest
20 seq = new Sequence("FER1", "AKPNGVL");
23 public void testInsertGapsAndGapmaps()
25 SequenceI aseq = seq.deriveSequence();
26 aseq.insertCharAt(2, 3, '-');
27 aseq.insertCharAt(6, 3, '-');
28 assertEquals("Gap insertions not correct", "AK---P---NGVL",
29 aseq.getSequenceAsString());
30 List<int[]> gapInt = aseq.getInsertions();
31 assertEquals("Gap interval 1 start wrong", 2, gapInt.get(0)[0]);
32 assertEquals("Gap interval 1 end wrong", 4, gapInt.get(0)[1]);
33 assertEquals("Gap interval 2 start wrong", 6, gapInt.get(1)[0]);
34 assertEquals("Gap interval 2 end wrong", 8, gapInt.get(1)[1]);
38 public void testGetAnnotation()
40 // initial state returns null not an empty array
41 assertNull(seq.getAnnotation());
42 AlignmentAnnotation ann = addAnnotation("label1", "desc1", "calcId1",
44 AlignmentAnnotation[] anns = seq.getAnnotation();
45 assertEquals(1, anns.length);
46 assertSame(ann, anns[0]);
48 // removing all annotations reverts array to null
49 seq.removeAlignmentAnnotation(ann);
50 assertNull(seq.getAnnotation());
54 public void testGetAnnotation_forLabel()
56 AlignmentAnnotation ann1 = addAnnotation("label1", "desc1", "calcId1", 1f);
57 AlignmentAnnotation ann2 = addAnnotation("label2", "desc2", "calcId2", 1f);
58 AlignmentAnnotation ann3 = addAnnotation("label1", "desc3", "calcId3", 1f);
59 AlignmentAnnotation[] anns = seq.getAnnotation("label1");
60 assertEquals(2, anns.length);
61 assertSame(ann1, anns[0]);
62 assertSame(ann3, anns[1]);
65 private AlignmentAnnotation addAnnotation(String label,
66 String description, String calcId,
69 final AlignmentAnnotation annotation = new AlignmentAnnotation(label, description,
71 annotation.setCalcId(calcId);
72 seq.addAlignmentAnnotation(annotation);
77 public void testGetAlignmentAnnotations_forCalcIdAndLabel()
79 AlignmentAnnotation ann1 = addAnnotation("label1", "desc1", "calcId1",
81 AlignmentAnnotation ann2 = addAnnotation("label2", "desc2", "calcId2",
83 AlignmentAnnotation ann3 = addAnnotation("label2", "desc3", "calcId3",
85 AlignmentAnnotation ann4 = addAnnotation("label2", "desc3", "calcId2",
87 AlignmentAnnotation ann5 = addAnnotation("label5", "desc3", null,
89 AlignmentAnnotation ann6 = addAnnotation(null, "desc3", "calcId3",
91 List<AlignmentAnnotation> anns = seq.getAlignmentAnnotations("calcId2",
93 assertEquals(2, anns.size());
94 assertSame(ann2, anns.get(0));
95 assertSame(ann4, anns.get(1));
97 assertTrue(seq.getAlignmentAnnotations("calcId2", "label3").isEmpty());
98 assertTrue(seq.getAlignmentAnnotations("calcId3", "label5").isEmpty());
99 assertTrue(seq.getAlignmentAnnotations("calcId2", null).isEmpty());
100 assertTrue(seq.getAlignmentAnnotations(null, "label3").isEmpty());
101 assertTrue(seq.getAlignmentAnnotations(null, null).isEmpty());
105 * Tests for addAlignmentAnnotation. Note this method has the side-effect of
106 * setting the sequenceRef on the annotation. Adding the same annotation twice
110 public void testAddAlignmentAnnotation()
112 assertNull(seq.getAnnotation());
113 final AlignmentAnnotation annotation = new AlignmentAnnotation("a",
115 assertNull(annotation.sequenceRef);
116 seq.addAlignmentAnnotation(annotation);
117 assertSame(seq, annotation.sequenceRef);
118 AlignmentAnnotation[] anns = seq.getAnnotation();
119 assertEquals(1, anns.length);
120 assertSame(annotation, anns[0]);
122 // re-adding does nothing
123 seq.addAlignmentAnnotation(annotation);
124 anns = seq.getAnnotation();
125 assertEquals(1, anns.length);
126 assertSame(annotation, anns[0]);
128 // an identical but different annotation can be added
129 final AlignmentAnnotation annotation2 = new AlignmentAnnotation("a",
131 seq.addAlignmentAnnotation(annotation2);
132 anns = seq.getAnnotation();
133 assertEquals(2, anns.length);
134 assertSame(annotation, anns[0]);
135 assertSame(annotation2, anns[1]);