From 7550d8c3a8b93d9d9f866e1d4714846e573e22e5 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Wed, 28 Oct 2015 10:40:00 +0000 Subject: [PATCH] JAL-1946 additional unit test cases for PID calculation --- test/jalview/util/ComparisonTest.java | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/test/jalview/util/ComparisonTest.java b/test/jalview/util/ComparisonTest.java index 6618789..67c81ad 100644 --- a/test/jalview/util/ComparisonTest.java +++ b/test/jalview/util/ComparisonTest.java @@ -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); } } -- 1.7.10.2