From 1e4805c16393771cbe0de65ab801134e5d3a0029 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Thu, 2 Nov 2017 14:36:04 +0000 Subject: [PATCH] JAL-2808 toString modified, tests corrected --- src/jalview/util/matcher/KeyedMatcher.java | 2 +- src/jalview/util/matcher/KeyedMatcherSet.java | 6 +++ src/jalview/util/matcher/KeyedMatcherSetI.java | 7 +++ src/jalview/util/matcher/Matcher.java | 2 +- test/jalview/util/matcher/ConditionTest.java | 16 +++---- test/jalview/util/matcher/KeyedMatcherSetTest.java | 49 +++++++++++--------- test/jalview/util/matcher/KeyedMatcherTest.java | 5 +- 7 files changed, 55 insertions(+), 32 deletions(-) diff --git a/src/jalview/util/matcher/KeyedMatcher.java b/src/jalview/util/matcher/KeyedMatcher.java index 474dc31..5e42e1c 100644 --- a/src/jalview/util/matcher/KeyedMatcher.java +++ b/src/jalview/util/matcher/KeyedMatcher.java @@ -78,7 +78,7 @@ public class KeyedMatcher implements KeyedMatcherI public String toString() { StringBuilder sb = new StringBuilder(); - sb.append(key).append(" ").append(matcher.getCondition().name()) + sb.append(key).append(" ").append(matcher.getCondition().toString()) .append(" ").append(matcher.getPattern()); return sb.toString(); diff --git a/src/jalview/util/matcher/KeyedMatcherSet.java b/src/jalview/util/matcher/KeyedMatcherSet.java index 3c21d50..adc04ba 100644 --- a/src/jalview/util/matcher/KeyedMatcherSet.java +++ b/src/jalview/util/matcher/KeyedMatcherSet.java @@ -113,4 +113,10 @@ public class KeyedMatcherSet implements KeyedMatcherSetI return sb.toString(); } + @Override + public boolean isEmpty() + { + return matchConditions == null || matchConditions.isEmpty(); + } + } diff --git a/src/jalview/util/matcher/KeyedMatcherSetI.java b/src/jalview/util/matcher/KeyedMatcherSetI.java index 09532a4..7cbebab 100644 --- a/src/jalview/util/matcher/KeyedMatcherSetI.java +++ b/src/jalview/util/matcher/KeyedMatcherSetI.java @@ -55,4 +55,11 @@ public interface KeyedMatcherSetI * @return */ Iterator getMatchers(); + + /** + * Answers true if this object contains no conditions + * + * @return + */ + boolean isEmpty(); } diff --git a/src/jalview/util/matcher/Matcher.java b/src/jalview/util/matcher/Matcher.java index 638933d..d8c9361 100644 --- a/src/jalview/util/matcher/Matcher.java +++ b/src/jalview/util/matcher/Matcher.java @@ -40,7 +40,7 @@ public class Matcher implements MatcherI * if a numerical condition is specified with a non-numeric * comparision value * @throws NullPointerException - * if a null comparison string is specified + * if a null condition or comparison string is specified */ public Matcher(Condition cond, String compareTo) { diff --git a/test/jalview/util/matcher/ConditionTest.java b/test/jalview/util/matcher/ConditionTest.java index 11a0630..270aa2a 100644 --- a/test/jalview/util/matcher/ConditionTest.java +++ b/test/jalview/util/matcher/ConditionTest.java @@ -16,16 +16,16 @@ public class ConditionTest assertEquals(Condition.NotContains.toString(), "Does not contain"); assertEquals(Condition.Matches.toString(), "Matches"); assertEquals(Condition.NotMatches.toString(), "Does not match"); - assertEquals(Condition.LT.toString(), "Is less than"); - assertEquals(Condition.LE.toString(), "Is less than or equal to"); - assertEquals(Condition.GT.toString(), "Is greater than"); - assertEquals(Condition.GE.toString(), "Is greater than or equal to"); - assertEquals(Condition.EQ.toString(), "Is equal to"); - assertEquals(Condition.NE.toString(), "Is not equal to"); + assertEquals(Condition.LT.toString(), "<"); + assertEquals(Condition.LE.toString(), "<="); + assertEquals(Condition.GT.toString(), ">"); + assertEquals(Condition.GE.toString(), ">="); + assertEquals(Condition.EQ.toString(), "="); + assertEquals(Condition.NE.toString(), "not ="); /* - * repeat call to get coverage of cached value + * repeat call to get coverage of value caching */ - assertEquals(Condition.NE.toString(), "Is not equal to"); + assertEquals(Condition.NE.toString(), "not ="); } } diff --git a/test/jalview/util/matcher/KeyedMatcherSetTest.java b/test/jalview/util/matcher/KeyedMatcherSetTest.java index 76ae8a5..0d2767d 100644 --- a/test/jalview/util/matcher/KeyedMatcherSetTest.java +++ b/test/jalview/util/matcher/KeyedMatcherSetTest.java @@ -17,18 +17,23 @@ public class KeyedMatcherSetTest * a numeric matcher - MatcherTest covers more conditions */ KeyedMatcherI km = new KeyedMatcher("AF", Condition.GE, -2F); - assertTrue(km.matches(key -> "-2")); - assertTrue(km.matches(key -> "-1")); - assertFalse(km.matches(key -> "-3")); - assertFalse(km.matches(key -> "")); - assertFalse(km.matches(key -> "junk")); - assertFalse(km.matches(key -> null)); + KeyedMatcherSetI kms = new KeyedMatcherSet(); + kms.and(km); + assertTrue(kms.matches(key -> "-2")); + assertTrue(kms.matches(key -> "-1")); + assertFalse(kms.matches(key -> "-3")); + assertFalse(kms.matches(key -> "")); + assertFalse(kms.matches(key -> "junk")); + assertFalse(kms.matches(key -> null)); /* * a string pattern matcher */ km = new KeyedMatcher("AF", Condition.Contains, "Cat"); - assertTrue(km.matches(key -> "AF".equals(key) ? "raining cats and dogs" + kms = new KeyedMatcherSet(); + kms.and(km); + assertTrue(kms + .matches(key -> "AF".equals(key) ? "raining cats and dogs" : "showers")); } @@ -58,10 +63,10 @@ public class KeyedMatcherSetTest public void testToString() { KeyedMatcherI km1 = new KeyedMatcher("AF", Condition.LT, 1.2f); - assertEquals(km1.toString(), "AF LT 1.2"); + assertEquals(km1.toString(), "AF < 1.2"); KeyedMatcher km2 = new KeyedMatcher("CLIN_SIG", Condition.NotContains, "path"); - assertEquals(km2.toString(), "CLIN_SIG NotContains PATH"); + assertEquals(km2.toString(), "CLIN_SIG Does not contain PATH"); /* * AND them @@ -69,10 +74,10 @@ public class KeyedMatcherSetTest KeyedMatcherSetI kms = new KeyedMatcherSet(); assertEquals(kms.toString(), ""); kms.and(km1); - assertEquals(kms.toString(), "(AF LT 1.2)"); + assertEquals(kms.toString(), "(AF < 1.2)"); kms.and(km2); assertEquals(kms.toString(), - "(AF LT 1.2) AND (CLIN_SIG NotContains PATH)"); + "(AF < 1.2) AND (CLIN_SIG Does not contain PATH)"); /* * OR them @@ -80,18 +85,10 @@ public class KeyedMatcherSetTest kms = new KeyedMatcherSet(); assertEquals(kms.toString(), ""); kms.or(km1); - assertEquals(kms.toString(), "(AF LT 1.2)"); + assertEquals(kms.toString(), "(AF < 1.2)"); kms.or(km2); assertEquals(kms.toString(), - "(AF LT 1.2) OR (CLIN_SIG NotContains PATH)"); - } - - /** - * @return - */ - protected KeyedMatcher km3() - { - return new KeyedMatcher("CSQ", Condition.Contains, "benign"); + "(AF < 1.2) OR (CLIN_SIG Does not contain PATH)"); } @Test @@ -114,4 +111,14 @@ public class KeyedMatcherSetTest kms.or(km1); assertTrue(kms.matches(vp)); } + + @Test + public void testIsEmpty() + { + KeyedMatcherI km = new KeyedMatcher("AF", Condition.GE, -2F); + KeyedMatcherSetI kms = new KeyedMatcherSet(); + assertTrue(kms.isEmpty()); + kms.and(km); + assertFalse(kms.isEmpty()); + } } diff --git a/test/jalview/util/matcher/KeyedMatcherTest.java b/test/jalview/util/matcher/KeyedMatcherTest.java index ebc09c1..164b8eb 100644 --- a/test/jalview/util/matcher/KeyedMatcherTest.java +++ b/test/jalview/util/matcher/KeyedMatcherTest.java @@ -33,8 +33,11 @@ public class KeyedMatcherTest @Test public void testToString() { + /* + * toString uses the i18n translation of the enum conditions + */ KeyedMatcherI km = new KeyedMatcher("AF", Condition.LT, 1.2f); - assertEquals(km.toString(), "AF LT 1.2"); + assertEquals(km.toString(), "AF < 1.2"); } @Test -- 1.7.10.2