JAL-2808 revised util.matcher package, 2 filter conditions per feature
[jalview.git] / test / jalview / util / matcher / KeyedMatcherTest.java
index ccf2ba2..ebc09c1 100644 (file)
@@ -4,8 +4,6 @@ import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertTrue;
 
-import java.util.function.Function;
-
 import org.testng.annotations.Test;
 
 public class KeyedMatcherTest
@@ -16,8 +14,7 @@ public class KeyedMatcherTest
     /*
      * a numeric matcher - MatcherTest covers more conditions
      */
-    MatcherI m1 = new Matcher(Condition.GE, -2f);
-    KeyedMatcherI km = new KeyedMatcher("AF", m1);
+    KeyedMatcherI km = new KeyedMatcher("AF", Condition.GE, -2F);
     assertTrue(km.matches(key -> "-2"));
     assertTrue(km.matches(key -> "-1"));
     assertFalse(km.matches(key -> "-3"));
@@ -28,65 +25,31 @@ public class KeyedMatcherTest
     /*
      * a string pattern matcher
      */
-    MatcherI m2 = new Matcher(Condition.Contains, "Cat");
-    km = new KeyedMatcher("AF", m2);
+    km = new KeyedMatcher("AF", Condition.Contains, "Cat");
     assertTrue(km.matches(key -> "AF".equals(key) ? "raining cats and dogs"
             : "showers"));
   }
 
   @Test
-  public void testAnd()
+  public void testToString()
   {
-    // condition1: AF value contains "dog" (matches)
-    KeyedMatcherI km1 = new KeyedMatcher("AF", new Matcher(
-            Condition.Contains, "dog"));
-
-    Function<String, String> vp = key -> "AF".equals(key) ? "raining cats and dogs"
-            : "showers";
-    assertTrue(km1.matches(vp));
-
-    // condition 2: CSQ value does not contain "how" (does not match)
-    KeyedMatcherI km2 = km1.and("CSQ", new Matcher(Condition.NotContains,
-            "how"));
-    assertFalse(km2.matches(vp));
+    KeyedMatcherI km = new KeyedMatcher("AF", Condition.LT, 1.2f);
+    assertEquals(km.toString(), "AF LT 1.2");
   }
 
   @Test
-  public void testToString()
+  public void testGetKey()
   {
-    KeyedMatcherI km = new KeyedMatcher("AF",
-            new Matcher(Condition.LT, 1.2f));
-    assertEquals(km.toString(), "AF LT 1.2");
-
-    /*
-     * add an AND condition
-     */
-    km = km.and("CLIN_SIG", new Matcher(Condition.NotContains, "path"));
-    assertEquals(km.toString(), "CLIN_SIG NotContains PATH AND (AF LT 1.2)");
-
-    /*
-     * add an OR condition
-     */
-    km = km.or("CSQ", new Matcher(Condition.Contains, "benign"));
-    assertEquals(km.toString(),
-            "CSQ Contains BENIGN OR (CLIN_SIG NotContains PATH AND (AF LT 1.2))");
+    KeyedMatcherI km = new KeyedMatcher("AF", Condition.GE, -2F);
+    assertEquals(km.getKey(), "AF");
   }
 
   @Test
-  public void testOr()
+  public void testGetMatcher()
   {
-    // condition1: AF value contains "dog" (matches)
-    KeyedMatcherI km1 = new KeyedMatcher("AF", new Matcher(
-            Condition.Contains, "dog"));
-  
-    Function<String, String> vp = key -> "AF".equals(key) ? "raining cats and dogs"
-            : "showers";
-    assertTrue(km1.matches(vp));
-  
-    // condition 2: CSQ value does not contain "how" (does not match)
-    // the OR combination still passes
-    KeyedMatcherI km2 = km1.or("CSQ", new Matcher(Condition.NotContains,
-            "how"));
-    assertTrue(km2.matches(vp));
+    KeyedMatcherI km = new KeyedMatcher("AF", Condition.GE, -2F);
+    assertEquals(km.getMatcher().getCondition(), Condition.GE);
+    assertEquals(km.getMatcher().getFloatValue(), -2F);
+    assertEquals(km.getMatcher().getPattern(), "-2.0");
   }
 }