JAL-1946 additional unit test cases for PID calculation
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 28 Oct 2015 10:40:00 +0000 (10:40 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 28 Oct 2015 10:40:00 +0000 (10:40 +0000)
test/jalview/util/ComparisonTest.java

index 6618789..67c81ad 100644 (file)
@@ -101,10 +101,10 @@ public class ComparisonTest
   }
 
   /**
-   * Test percentage identity calculation for two sequences.
+   * Test the percentage identity calculation for two sequences
    */
   @Test(groups = { "Functional" })
-  public void testPID_matchGaps()
+  public void testPID()
   {
     String seq1 = "ABCDEF";
     String seq2 = "abcdef";
@@ -114,6 +114,30 @@ public class ComparisonTest
     seq2 = "abcdefghijklmnopqrstuvwxyz";
     assertEquals("identical", 100f, Comparison.PID(seq1, seq2), 0.001f);
 
-    seq2 = "a---bcdef";
+    // 5 identical, 2 gap-gap, 2 gap-residue, 1 mismatch
+    seq1 = "a--b-cdefh";
+    seq2 = "a---bcdefg";
+    int length = seq1.length();
+
+    // match gap-residue, match gap-gap: 9/10 identical
+    assertEquals(90f, Comparison.PID(seq1, seq2, 0, length, true, false),
+            0.001f);
+    // overloaded version of the method signature above:
+    assertEquals(90f, Comparison.PID(seq1, seq2), 0.001f);
+
+    // don't match gap-residue, match gap-gap: 7/10 identical
+    assertEquals(70f,
+            Comparison.PID(seq1, seq2, 0, seq1.length(), false, false),
+            0.001f);
+
+    // match gap-residue, match gap-gap: 7/8 identical
+    assertEquals(87.5f,
+            Comparison.PID(seq1, seq2, 0, seq1.length(), true, true),
+            0.001f);
+
+    // don't match gap-residue with 'ungapped only' - same as above
+    assertEquals(87.5f,
+            Comparison.PID(seq1, seq2, 0, seq1.length(), false, true),
+            0.001f);
   }
 }