JAL-1965 word based matching and explicit coping with match collisions - tests are...
[jalview.git] / test / jalview / analysis / SequenceIdMatcherTest.java
index a71d105..2a07ad5 100644 (file)
@@ -24,6 +24,11 @@ public class SequenceIdMatcherTest
     return new SequenceIdMatcher(Arrays.asList(someseqs));
   }
 
+  private static SequenceIdMatcher getWordMatcher()
+  {
+    return new SequenceIdMatcher(true, Arrays.asList(someseqs));
+  }
+
   @Test(groups = { "Functional" })
   public void findSelfAndOthers()
   {
@@ -36,15 +41,19 @@ public class SequenceIdMatcherTest
                       + 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 '"
+      Assert.assertEquals(1, seqmatches.length,
+              "Expected to recover one sequence for sequence object called '"
                       + sq.getName() + "'");
-      Assert.assertTrue(seqmatches.length == idmatches.length,
-              "Different matches found for '" + sq.getName() + "'");
-      for (SequenceI sid : idmatches)
+      Assert.assertEquals(sq, seqmatches[0],
+              "Expected to recover the sequence queried with findIdMatch(SequenceI[])");
+      // TODO: complexid and ComplexId are identical with case-insensitive
+      // matching. This assert fails because of this.
+      // Assert.assertTrue(seqmatches.length == idmatches.length,
+      // "Different matches found for '" + sq.getName() + "'");
+      for (SequenceI sid : seqmatches)
       {
         boolean found = false;
-        for (SequenceI sobj : seqmatches)
+        for (SequenceI sobj : idmatches)
         {
           if (sid == sobj)
           {
@@ -90,8 +99,15 @@ public class SequenceIdMatcherTest
   public void testFlankingMatch()
   {
     SequenceI[] match = getMatcher().findAllIdMatches("complexId");
-    Assert.assertNotNull(match, "Flanking matches not found.");
-    Assert.assertEquals(match.length, 6,
+    // should find two matches - one case exact, the other case inexact.
+    Assert.assertNotNull(match, "Exact matches not found.");
+    Assert.assertEquals(match.length, 2,
+            "Expected two exact matches to be found.");
+    SequenceI[] fmatch = getWordMatcher()
+            .findAllIdMatches("complexId");
+    // should find 6 distinct sequences
+    Assert.assertNotNull(fmatch, "Flanking matches not found.");
+    Assert.assertEquals(fmatch.length, 6,
             "Couldn't find all entries with IDs containing 'complexId' word match");
 
   }