X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Futil%2Fmatcher%2FKeyedMatcherTest.java;h=164b8eb2d7e8fda663e9cc6c8f409b06ed0dcf53;hb=9bcdd1d38988de350482acfd1a21628f73cdbd6d;hp=ccf2ba25949ebcc4612944ea0483623f9ad3a00e;hpb=67dbd0072044a077ac43079ea12c8c4803636ee1;p=jalview.git diff --git a/test/jalview/util/matcher/KeyedMatcherTest.java b/test/jalview/util/matcher/KeyedMatcherTest.java index ccf2ba2..164b8eb 100644 --- a/test/jalview/util/matcher/KeyedMatcherTest.java +++ b/test/jalview/util/matcher/KeyedMatcherTest.java @@ -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,34 @@ 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() - { - // condition1: AF value contains "dog" (matches) - KeyedMatcherI km1 = new KeyedMatcher("AF", new Matcher( - Condition.Contains, "dog")); - - Function 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)); - } - - @Test public void testToString() { - KeyedMatcherI km = new KeyedMatcher("AF", - new Matcher(Condition.LT, 1.2f)); - assertEquals(km.toString(), "AF LT 1.2"); - /* - * add an AND condition + * toString uses the i18n translation of the enum conditions */ - km = km.and("CLIN_SIG", new Matcher(Condition.NotContains, "path")); - assertEquals(km.toString(), "CLIN_SIG NotContains PATH AND (AF LT 1.2)"); + KeyedMatcherI km = new KeyedMatcher("AF", Condition.LT, 1.2f); + assertEquals(km.toString(), "AF < 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))"); + @Test + public void testGetKey() + { + 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 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"); } }