1 package jalview.util.matcher;
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertFalse;
5 import static org.testng.Assert.assertTrue;
7 import java.util.function.Function;
9 import org.testng.annotations.Test;
11 public class KeyedMatcherTest
14 public void testMatches()
17 * a numeric matcher - MatcherTest covers more conditions
19 MatcherI m1 = new Matcher(Condition.GE, -2f);
20 KeyedMatcherI km = new KeyedMatcher("AF", m1);
21 assertTrue(km.matches(key -> "-2"));
22 assertTrue(km.matches(key -> "-1"));
23 assertFalse(km.matches(key -> "-3"));
24 assertFalse(km.matches(key -> ""));
25 assertFalse(km.matches(key -> "junk"));
26 assertFalse(km.matches(key -> null));
29 * a string pattern matcher
31 MatcherI m2 = new Matcher(Condition.Contains, "Cat");
32 km = new KeyedMatcher("AF", m2);
33 assertTrue(km.matches(key -> "AF".equals(key) ? "raining cats and dogs"
40 // condition1: AF value contains "dog" (matches)
41 KeyedMatcherI km1 = new KeyedMatcher("AF", new Matcher(
42 Condition.Contains, "dog"));
44 Function<String, String> vp = key -> "AF".equals(key) ? "raining cats and dogs"
46 assertTrue(km1.matches(vp));
48 // condition 2: CSQ value does not contain "how" (does not match)
49 KeyedMatcherI km2 = km1.and("CSQ", new Matcher(Condition.NotContains,
51 assertFalse(km2.matches(vp));
55 public void testToString()
57 KeyedMatcherI km = new KeyedMatcher("AF",
58 new Matcher(Condition.LT, 1.2f));
59 assertEquals(km.toString(), "AF LT 1.2");
62 * add an AND condition
64 km = km.and("CLIN_SIG", new Matcher(Condition.NotContains, "path"));
65 assertEquals(km.toString(), "CLIN_SIG NotContains PATH AND (AF LT 1.2)");
70 km = km.or("CSQ", new Matcher(Condition.Contains, "benign"));
71 assertEquals(km.toString(),
72 "CSQ Contains BENIGN OR (CLIN_SIG NotContains PATH AND (AF LT 1.2))");
78 // condition1: AF value contains "dog" (matches)
79 KeyedMatcherI km1 = new KeyedMatcher("AF", new Matcher(
80 Condition.Contains, "dog"));
82 Function<String, String> vp = key -> "AF".equals(key) ? "raining cats and dogs"
84 assertTrue(km1.matches(vp));
86 // condition 2: CSQ value does not contain "how" (does not match)
87 // the OR combination still passes
88 KeyedMatcherI km2 = km1.or("CSQ", new Matcher(Condition.NotContains,
90 assertTrue(km2.matches(vp));