Merge branch 'features/JAL-2393customMatrices' into develop
[jalview.git] / test / jalview / analysis / AlignSeqTest.java
index 4cb5329..837e970 100644 (file)
  */
 package jalview.analysis;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+import static org.testng.internal.junit.ArrayAsserts.assertArrayEquals;
 
+import jalview.datamodel.Sequence;
 import jalview.gui.JvOptionPane;
 
 import org.testng.annotations.BeforeClass;
@@ -45,10 +47,32 @@ public class AlignSeqTest
     assertNull(AlignSeq.extractGaps(null, "ACG"));
     assertNull(AlignSeq.extractGaps("-. ", null));
 
-    assertEquals(" AC-G.T", AlignSeq.extractGaps("", " AC-G.T"));
-    assertEquals("AC-G.T", AlignSeq.extractGaps(" ", " AC-G.T"));
-    assertEquals("ACG.T", AlignSeq.extractGaps(" -", " AC-G.T"));
-    assertEquals("ACGT", AlignSeq.extractGaps(" -.", " AC-G.T ."));
-    assertEquals(" ACG.T", AlignSeq.extractGaps("-", " AC-G.T"));
+    assertEquals(AlignSeq.extractGaps("", " AC-G.T"), " AC-G.T");
+    assertEquals(AlignSeq.extractGaps(" ", " AC-G.T"), "AC-G.T");
+    assertEquals(AlignSeq.extractGaps(" -", " AC-G.T"), "ACG.T");
+    assertEquals(AlignSeq.extractGaps(" -.", " AC-G.T ."), "ACGT");
+    assertEquals(AlignSeq.extractGaps("-", " AC-G.T"), " ACG.T");
+  }
+
+  @Test(groups = { "Functional" })
+  public void testIndexEncode_nucleotide()
+  {
+    AlignSeq as = new AlignSeq(new Sequence("s1", "TTAG"), new Sequence(
+            "s2", "ACGT"), AlignSeq.DNA);
+    int[] expected = new int[] { 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6,
+        7, 7, 8, 8, 9, 9, -1, -1, 10, -1 };
+    String s = "aAcCgGtTuUiIxXrRyYnN .-?";
+    assertArrayEquals(expected, as.indexEncode(s));
+  }
+
+  @Test(groups = { "Functional" })
+  public void testIndexEncode_peptide()
+  {
+    AlignSeq as = new AlignSeq(new Sequence("s1", "PFY"), new Sequence(
+            "s2", "RQW"), AlignSeq.PEP);
+    int[] expected = new int[] { 0, 0, 1, 1, 2, 2, 21, 21, 22, 22, -1, 23,
+        -1, -1, -1 };
+    String s = "aArRnNzZxX *.-?";
+    assertArrayEquals(expected, as.indexEncode(s));
   }
 }