Merge branch 'releases/Release_2_10_Branch' into develop
[jalview.git] / test / jalview / datamodel / SequenceTest.java
index 17dfcdc..cfc4cbb 100644 (file)
@@ -65,6 +65,30 @@ public class SequenceTest
     assertEquals("Gap interval 2 end wrong", 8, gapInt.get(1)[1]);
   }
 
+  @Test(groups = ("Functional"))
+  public void testIsProtein()
+  {
+    // test Protein
+    assertTrue(new Sequence("prot","ASDFASDFASDF").isProtein());
+    // test DNA
+    assertFalse(new Sequence("prot","ACGTACGTACGT").isProtein());
+    // test RNA
+    SequenceI sq = new Sequence("prot","ACGUACGUACGU");
+    assertFalse(sq.isProtein());
+    // change sequence, should trigger an update of cached result
+    sq.setSequence("ASDFASDFADSF");
+    assertTrue(sq.isProtein());
+    /*
+     * in situ change of sequence doesn't change hashcode :-O
+     * (sequence should not expose internal implementation)
+     */
+    for (int i = 0; i < sq.getSequence().length; i++)
+    {
+      sq.getSequence()[i] = "acgtu".charAt(i % 5);
+    }
+    assertTrue(sq.isProtein()); // but it isn't
+  }
+
   @Test(groups = { "Functional" })
   public void testGetAnnotation()
   {
@@ -86,8 +110,7 @@ public class SequenceTest
   {
     AlignmentAnnotation ann1 = addAnnotation("label1", "desc1", "calcId1",
             1f);
-    AlignmentAnnotation ann2 = addAnnotation("label2", "desc2", "calcId2",
-            1f);
+    addAnnotation("label2", "desc2", "calcId2", 1f);
     AlignmentAnnotation ann3 = addAnnotation("label1", "desc3", "calcId3",
             1f);
     AlignmentAnnotation[] anns = seq.getAnnotation("label1");
@@ -109,16 +132,15 @@ public class SequenceTest
   @Test(groups = { "Functional" })
   public void testGetAlignmentAnnotations_forCalcIdAndLabel()
   {
-    AlignmentAnnotation ann1 = addAnnotation("label1", "desc1", "calcId1",
-            1f);
+    addAnnotation("label1", "desc1", "calcId1", 1f);
     AlignmentAnnotation ann2 = addAnnotation("label2", "desc2", "calcId2",
             1f);
-    AlignmentAnnotation ann3 = addAnnotation("label2", "desc3", "calcId3",
-            1f);
+    addAnnotation("label2", "desc3", "calcId3", 1f);
     AlignmentAnnotation ann4 = addAnnotation("label2", "desc3", "calcId2",
             1f);
-    AlignmentAnnotation ann5 = addAnnotation("label5", "desc3", null, 1f);
-    AlignmentAnnotation ann6 = addAnnotation(null, "desc3", "calcId3", 1f);
+    addAnnotation("label5", "desc3", null, 1f);
+    addAnnotation(null, "desc3", "calcId3", 1f);
+
     List<AlignmentAnnotation> anns = seq.getAlignmentAnnotations("calcId2",
             "label2");
     assertEquals(2, anns.size());
@@ -388,6 +410,20 @@ public class SequenceTest
   }
 
   /**
+   * test createDatasetSequence behaves to doc
+   */
+  @Test(groups = { "Functional" })
+  public void testCreateDatasetSequence()
+  {
+    SequenceI sq = new Sequence("my","ASDASD");
+    assertNull(sq.getDatasetSequence());
+    SequenceI rds = sq.createDatasetSequence();
+    assertNotNull(rds);
+    assertNull(rds.getDatasetSequence());
+    assertEquals(sq.getDatasetSequence(), rds);
+  }
+
+  /**
    * Test for deriveSequence applied to a sequence with a dataset
    */
   @Test(groups = { "Functional" })