X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=test%2Fjalview%2Fdatamodel%2Ffeatures%2FFeatureMatcherTest.java;h=f403a578681908d9c4eb0ce23451ce469c6a64eb;hb=d87b55e45cc1e6a5b7df3865ded1b87a0e3dc7ff;hp=4bd34cbf0997d570893074d786b6885f2f333fd0;hpb=7810a4a86cf5c344971dc1c834ac2227192badc2;p=jalview.git diff --git a/test/jalview/datamodel/features/FeatureMatcherTest.java b/test/jalview/datamodel/features/FeatureMatcherTest.java index 4bd34cb..f403a57 100644 --- a/test/jalview/datamodel/features/FeatureMatcherTest.java +++ b/test/jalview/datamodel/features/FeatureMatcherTest.java @@ -6,14 +6,17 @@ import static org.testng.Assert.assertNull; import static org.testng.Assert.assertSame; import static org.testng.Assert.assertTrue; -import jalview.datamodel.SequenceFeature; -import jalview.util.MessageManager; -import jalview.util.matcher.Condition; - import java.util.Locale; import org.testng.annotations.Test; +import jalview.datamodel.SequenceFeature; +import jalview.util.MessageManager; +import jalview.util.matcher.Condition; +import jalview.util.matcher.Matcher; +import jalview.util.matcher.MatcherI; +import junit.extensions.PA; + public class FeatureMatcherTest { @Test(groups = "Functional") @@ -222,7 +225,7 @@ public class FeatureMatcherTest FeatureMatcherI fm = FeatureMatcher.byAttribute(Condition.GE, "-2f", "AF"); assertEquals(fm.getMatcher().getCondition(), Condition.GE); - assertEquals(fm.getMatcher().getFloatValue(), -2F); + assertEquals(PA.getValue(fm.getMatcher(), "floatValue"), -2F); assertEquals(fm.getMatcher().getPattern(), "-2.0"); } @@ -233,71 +236,88 @@ public class FeatureMatcherTest assertFalse(fm.isByLabel()); assertFalse(fm.isByScore()); assertEquals(fm.getAttribute(), new String[] { "AF" }); - assertSame(Condition.LT, fm.getMatcher().getCondition()); - assertEquals(fm.getMatcher().getFloatValue(), 1.2f); - assertEquals(fm.getMatcher().getPattern(), "1.2"); + MatcherI matcher = fm.getMatcher(); + assertSame(Condition.LT, matcher.getCondition()); + assertEquals(PA.getValue(matcher, "floatValue"), 1.2f); + assertSame(PA.getValue(matcher, "patternType"), + Matcher.PatternType.Float); + assertEquals(matcher.getPattern(), "1.2"); // quotes are optional, condition is not case sensitive fm = FeatureMatcher.fromString("AF lt '1.2'"); + matcher = fm.getMatcher(); assertFalse(fm.isByLabel()); assertFalse(fm.isByScore()); assertEquals(fm.getAttribute(), new String[] { "AF" }); - assertSame(Condition.LT, fm.getMatcher().getCondition()); - assertEquals(fm.getMatcher().getFloatValue(), 1.2f); - assertEquals(fm.getMatcher().getPattern(), "1.2"); + assertSame(Condition.LT, matcher.getCondition()); + assertEquals(PA.getValue(matcher, "floatValue"), 1.2F); + assertEquals(matcher.getPattern(), "1.2"); fm = FeatureMatcher.fromString("'AF' Present"); + matcher = fm.getMatcher(); assertFalse(fm.isByLabel()); assertFalse(fm.isByScore()); assertEquals(fm.getAttribute(), new String[] { "AF" }); - assertSame(Condition.Present, fm.getMatcher().getCondition()); + assertSame(Condition.Present, matcher.getCondition()); + assertSame(PA.getValue(matcher, "patternType"), + Matcher.PatternType.String); fm = FeatureMatcher.fromString("CSQ:Consequence contains damaging"); + matcher = fm.getMatcher(); assertFalse(fm.isByLabel()); assertFalse(fm.isByScore()); assertEquals(fm.getAttribute(), new String[] { "CSQ", "Consequence" }); - assertSame(Condition.Contains, fm.getMatcher().getCondition()); - assertEquals(fm.getMatcher().getPattern(), "damaging"); + assertSame(Condition.Contains, matcher.getCondition()); + assertEquals(matcher.getPattern(), "damaging"); // keyword Label is not case sensitive fm = FeatureMatcher.fromString("LABEL Matches 'foobar'"); + matcher = fm.getMatcher(); assertTrue(fm.isByLabel()); assertFalse(fm.isByScore()); assertNull(fm.getAttribute()); - assertSame(Condition.Matches, fm.getMatcher().getCondition()); - assertEquals(fm.getMatcher().getPattern(), "foobar"); + assertSame(Condition.Matches, matcher.getCondition()); + assertEquals(matcher.getPattern(), "foobar"); fm = FeatureMatcher.fromString("'Label' matches 'foo bar'"); + matcher = fm.getMatcher(); assertTrue(fm.isByLabel()); assertFalse(fm.isByScore()); assertNull(fm.getAttribute()); - assertSame(Condition.Matches, fm.getMatcher().getCondition()); - assertEquals(fm.getMatcher().getPattern(), "foo bar"); + assertSame(Condition.Matches, matcher.getCondition()); + assertEquals(matcher.getPattern(), "foo bar"); // quotes optional on pattern fm = FeatureMatcher.fromString("'Label' matches foo bar"); + matcher = fm.getMatcher(); assertTrue(fm.isByLabel()); assertFalse(fm.isByScore()); assertNull(fm.getAttribute()); - assertSame(Condition.Matches, fm.getMatcher().getCondition()); - assertEquals(fm.getMatcher().getPattern(), "foo bar"); + assertSame(Condition.Matches, matcher.getCondition()); + assertEquals(matcher.getPattern(), "foo bar"); - fm = FeatureMatcher.fromString("Score GE 12.2"); + // integer condition + fm = FeatureMatcher.fromString("Score GE 12"); + matcher = fm.getMatcher(); assertFalse(fm.isByLabel()); assertTrue(fm.isByScore()); assertNull(fm.getAttribute()); - assertSame(Condition.GE, fm.getMatcher().getCondition()); - assertEquals(fm.getMatcher().getPattern(), "12.2"); - assertEquals(fm.getMatcher().getFloatValue(), 12.2f); + assertSame(Condition.GE, matcher.getCondition()); + assertEquals(matcher.getPattern(), "12"); + assertEquals(PA.getValue(matcher, "floatValue"), 0f); + assertEquals(PA.getValue(matcher, "longValue"), 12L); + assertSame(PA.getValue(matcher, "patternType"), + Matcher.PatternType.Integer); // keyword Score is not case sensitive fm = FeatureMatcher.fromString("'SCORE' ge '12.2'"); + matcher = fm.getMatcher(); assertFalse(fm.isByLabel()); assertTrue(fm.isByScore()); assertNull(fm.getAttribute()); - assertSame(Condition.GE, fm.getMatcher().getCondition()); - assertEquals(fm.getMatcher().getPattern(), "12.2"); - assertEquals(fm.getMatcher().getFloatValue(), 12.2f); + assertSame(Condition.GE, matcher.getCondition()); + assertEquals(matcher.getPattern(), "12.2"); + assertEquals(PA.getValue(matcher, "floatValue"), 12.2F); // invalid numeric pattern assertNull(FeatureMatcher.fromString("Score eq twelve"));