JAL-753_JAL-1427 basic test cases for SequenceIdMatcher
authorJim Procter <jprocter@issues.jalview.org>
Thu, 12 Nov 2015 13:15:04 +0000 (13:15 +0000)
committerJim Procter <jprocter@issues.jalview.org>
Thu, 12 Nov 2015 13:15:12 +0000 (13:15 +0000)
test/jalview/analysis/SequenceIdMatcherTest.java [new file with mode: 0644]

diff --git a/test/jalview/analysis/SequenceIdMatcherTest.java b/test/jalview/analysis/SequenceIdMatcherTest.java
new file mode 100644 (file)
index 0000000..be2497a
--- /dev/null
@@ -0,0 +1,86 @@
+package jalview.analysis;
+
+import jalview.datamodel.Sequence;
+import jalview.datamodel.SequenceI;
+
+import java.util.Arrays;
+
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+public class SequenceIdMatcherTest
+{
+  private static SequenceI[] someseqs = {
+      new Sequence("A|ComplexId", "dummy"),
+      new Sequence("A|ComplexId|confused", "dummy"),
+      new Sequence("A|ComplexId|bits_of", "dummy"),
+      new Sequence("ComplexId", "dummy"),
+      new Sequence("A|ComplexIdNot", "dummy"),
+      new Sequence("A ComplexId Id", "dummy"),
+      new Sequence("complexid", "dummy") };
+
+  private static SequenceIdMatcher getMatcher()
+  {
+    return new SequenceIdMatcher(Arrays.asList(someseqs));
+  }
+
+  @Test(groups = { "Functional" })
+  public void findSelfAndOthers()
+  {
+    for (SequenceI sq : SequenceIdMatcherTest.someseqs)
+    {
+      SequenceI[] idmatches = getMatcher().findAllIdMatches(sq.getName());
+      Assert.assertTrue(
+              idmatches.length >= 1,
+              "Couldn't recover at least one sequence for string '"
+                      + sq.getName() + "'");
+      SequenceI[] seqmatches = getMatcher().findIdMatch(
+              new SequenceI[] { sq });
+      Assert.assertTrue(seqmatches.length >= 1,
+              "Couldn't recover at least one sequence for sequence object called '"
+                      + sq.getName() + "'");
+      Assert.assertTrue(seqmatches.length == idmatches.length,
+              "Different matches found for '" + sq.getName() + "'");
+      for (SequenceI sid : idmatches)
+      {
+        boolean found = false;
+        for (SequenceI sobj : seqmatches)
+        {
+          if (sid == sobj)
+          {
+            found = true;
+          }
+        }
+        Assert.assertTrue(
+                found,
+                "Different sequences recovered for Id "
+                        + "and SequenceI (Couldn't find match for '"
+                        + sid.getName() + "')");
+
+      }
+    }
+  }
+
+  @Test(groups = { "Functional" })
+  public void testExactMatch()
+  {
+    SequenceI[] matches = getMatcher().findAllIdMatches("A|ComplexId");
+    Assert.assertTrue(matches.length == 1,
+            "Exact match failed for 'A|ComplexId'");
+    matches = getMatcher().findAllIdMatches("A|ComplexId|confused");
+    Assert.assertTrue(matches.length == 1,
+            "Exact match failed for 'A|ComplexId|confused'");
+    matches = getMatcher().findAllIdMatches("A|ComplexId|bits_of");
+    Assert.assertTrue(matches.length == 1,
+            "Exact match failed for 'A|ComplexId|bits_of'");
+    matches = getMatcher().findAllIdMatches("A ComplexId Id");
+    Assert.assertTrue(matches.length == 1,
+            "Exact match failed for 'A Complex Id'");
+
+  }
+
+  public void testContainedMatch()
+  {
+
+  }
+}