JAL-2996 JAL-3053 ~ | : [] {} () treated as gap characters.
[jalview.git] / test / jalview / util / ComparisonTest.java
index ec1779b..bd3b52e 100644 (file)
@@ -28,6 +28,7 @@ import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceI;
 import jalview.gui.JvOptionPane;
 
+import org.testng.Assert;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
@@ -51,6 +52,23 @@ public class ComparisonTest
     assertFalse(Comparison.isGap('x'));
     assertFalse(Comparison.isGap('*'));
     assertFalse(Comparison.isGap('G'));
+
+    // consistency - test Comparison.isGap covers all gapChars
+    StringBuilder missing = new StringBuilder();
+    for (int i = 0, iSize = Comparison.GapChars.length(); i < iSize; i++)
+    {
+      char gc = Comparison.GapChars.charAt(i);
+      if (!Comparison.isGap(gc))
+      {
+        missing.append(gc);
+      }
+    }
+    if (missing.length() > 0)
+    {
+      Assert.fail(
+              "Comparison.GapChars contains symbols not covered by Comparison.isGap: '"
+              + missing.toString() + "'");
+    }
   }
 
   /**
@@ -115,7 +133,7 @@ public class ComparisonTest
   @Test(groups = { "Functional" })
   public void testPID_includingGaps()
   {
-    String seq1 = "ABCDEF";
+    String seq1 = "ABCDEFG"; // extra length here is ignored
     String seq2 = "abcdef";
     assertEquals("identical", 100f, Comparison.PID(seq1, seq2), 0.001f);
 
@@ -165,7 +183,8 @@ public class ComparisonTest
   public void testPID_ungappedOnly()
   {
     // 5 identical, 2 gap-gap, 2 gap-residue, 1 mismatch
-    String seq1 = "a--b-cdefh";
+    // the extra length of seq1 is ignored
+    String seq1 = "a--b-cdefhr";
     String seq2 = "a---bcdefg";
     int length = seq1.length();