JAL-1270 unit test for SequenceIdMatcher.SeqIdName
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 11 Mar 2016 12:14:34 +0000 (12:14 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 11 Mar 2016 12:14:34 +0000 (12:14 +0000)
src/jalview/analysis/SequenceIdMatcher.java
test/jalview/analysis/SequenceIdMatcherTest.java [new file with mode: 0644]

index 454bc09..8351686 100755 (executable)
@@ -272,7 +272,7 @@ public class SequenceIdMatcher
     return r;
   }
 
-  private class SeqIdName
+  class SeqIdName
   {
     String id;
 
diff --git a/test/jalview/analysis/SequenceIdMatcherTest.java b/test/jalview/analysis/SequenceIdMatcherTest.java
new file mode 100644 (file)
index 0000000..eb0fc47
--- /dev/null
@@ -0,0 +1,78 @@
+package jalview.analysis;
+
+import static org.testng.AssertJUnit.assertFalse;
+import static org.testng.AssertJUnit.assertTrue;
+
+import jalview.analysis.SequenceIdMatcher.SeqIdName;
+import jalview.datamodel.SequenceI;
+
+import org.testng.annotations.Test;
+
+public class SequenceIdMatcherTest
+{
+
+  /**
+   * Test the method that checks for one sequence id starting with the other,
+   * followed by an 'allowed' separator character
+   */
+  @Test(groups = "Functional")
+  public void test_seqIdNameEquals()
+  {
+    SequenceIdMatcher sequenceIdMatcher = new SequenceIdMatcher(
+            new SequenceI[] {});
+
+    /*
+     * target name = matcher name + word separator...
+     */
+    SeqIdName testee = sequenceIdMatcher.new SeqIdName("A12345");
+    assertTrue(testee.equals("A12345"));
+    assertTrue(testee.equals("A12345~"));
+    assertTrue(testee.equals("A12345."));
+    assertTrue(testee.equals("A12345 "));
+    assertTrue(testee.equals("A12345|"));
+    assertTrue(testee.equals("A12345#"));
+    assertTrue(testee.equals("A12345\\"));
+    assertTrue(testee.equals("A12345/"));
+    assertTrue(testee.equals("A12345<"));
+    assertTrue(testee.equals("A12345>"));
+    assertTrue(testee.equals("A12345!"));
+    assertTrue(testee.equals("A12345\""));
+    assertTrue(testee.equals("A12345" + String.valueOf((char) 0x00A4)));
+    assertTrue(testee.equals("A12345$a"));
+    assertTrue(testee.equals("A12345%b"));
+    assertTrue(testee.equals("A12345^cd"));
+    assertTrue(testee.equals("A12345*efg"));
+    assertTrue(testee.equals("A12345)^&!"));
+    assertTrue(testee.equals("A12345}01&*"));
+    assertTrue(testee.equals("A12345[A23456"));
+    assertTrue(testee.equals("A12345@|Uniprot"));
+    assertTrue(testee.equals("A12345'whatever you want here"));
+    assertTrue(testee.equals("A12345,"));
+    assertTrue(testee.equals("A12345?"));
+    assertTrue(testee.equals("A12345_"));
+
+    /*
+     * matcher name = target name + word separator...
+     */
+    testee = sequenceIdMatcher.new SeqIdName("A12345#");
+    assertTrue(testee.equals("A12345"));
+
+    /*
+     * miscellaneous failing cases
+     */
+    testee = sequenceIdMatcher.new SeqIdName("A12345");
+    assertFalse(testee.equals((Object) null));
+    assertFalse(testee.equals(""));
+    assertFalse(testee.equals("a12345"));
+    assertFalse(testee.equals("A12346|A12345"));
+
+    testee = sequenceIdMatcher.new SeqIdName("A12345?B23456");
+    assertFalse(testee.equals("B23456"));
+    assertFalse(testee.equals("A12345|"));
+    assertFalse(testee.equals("A12345?"));
+
+    testee = sequenceIdMatcher.new SeqIdName("A12345<");
+    assertFalse(testee.equals("A12345?"));
+    assertTrue(testee.equals("A12345<")); // bug? inconsistent
+  }
+}