JAL-1628 new method to get a list of insertions in a SequenceI
[jalview.git] / test / jalview / datamodel / SequenceTest.java
index d9101cf..40476a0 100644 (file)
@@ -12,7 +12,7 @@ import org.junit.Test;
 
 public class SequenceTest
 {
-  Sequence seq;
+  SequenceI seq;
 
   @Before
   public void setUp()
@@ -20,6 +20,21 @@ public class SequenceTest
     seq = new Sequence("FER1", "AKPNGVL");
   }
   @Test
+  public void testInsertGapsAndGapmaps()
+  {
+    SequenceI aseq = seq.deriveSequence();
+    aseq.insertCharAt(2, 3, '-');
+    aseq.insertCharAt(6, 3, '-');
+    assertEquals("Gap insertions not correct", "AK---P---NGVL",
+            aseq.getSequenceAsString());
+    List<int[]> gapInt = aseq.getInsertions();
+    assertEquals("Gap interval 1 start wrong", 2, gapInt.get(0)[0]);
+    assertEquals("Gap interval 1 end wrong", 4, gapInt.get(0)[1]);
+    assertEquals("Gap interval 2 start wrong", 6, gapInt.get(1)[0]);
+    assertEquals("Gap interval 2 end wrong", 8, gapInt.get(1)[1]);
+  }
+
+  @Test
   public void testGetAnnotation()
   {
     // initial state returns null not an empty array
@@ -88,12 +103,13 @@ public class SequenceTest
 
   /**
    * Tests for addAlignmentAnnotation. Note this method has the side-effect of
-   * setting the sequenceRef on the annotation.
+   * setting the sequenceRef on the annotation. Adding the same annotation twice
+   * should be ignored.
    */
   @Test
   public void testAddAlignmentAnnotation()
   {
-    assertNull(seq.annotation);
+    assertNull(seq.getAnnotation());
     final AlignmentAnnotation annotation = new AlignmentAnnotation("a",
             "b", 2d);
     assertNull(annotation.sequenceRef);
@@ -102,5 +118,21 @@ public class SequenceTest
     AlignmentAnnotation[] anns = seq.getAnnotation();
     assertEquals(1, anns.length);
     assertSame(annotation, anns[0]);
+
+    // re-adding does nothing
+    seq.addAlignmentAnnotation(annotation);
+    anns = seq.getAnnotation();
+    assertEquals(1, anns.length);
+    assertSame(annotation, anns[0]);
+
+    // an identical but different annotation can be added
+    final AlignmentAnnotation annotation2 = new AlignmentAnnotation("a",
+            "b", 2d);
+    seq.addAlignmentAnnotation(annotation2);
+    anns = seq.getAnnotation();
+    assertEquals(2, anns.length);
+    assertSame(annotation, anns[0]);
+    assertSame(annotation2, anns[1]);
+
   }
 }