1 package jalview.datamodel.features;
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertFalse;
5 import static org.testng.Assert.assertTrue;
7 import jalview.datamodel.SequenceFeature;
8 import jalview.util.matcher.Condition;
10 import org.testng.annotations.Test;
12 public class FeatureMatcherTest
15 public void testMatches_byLabel()
17 SequenceFeature sf = new SequenceFeature("Cath", "this is my label", 11,
21 * contains - not case sensitive
24 FeatureMatcher.byLabel(Condition.Contains, "IS").matches(sf));
25 assertTrue(FeatureMatcher.byLabel(Condition.Contains, "").matches(sf));
27 FeatureMatcher.byLabel(Condition.Contains, "ISNT").matches(sf));
32 assertTrue(FeatureMatcher.byLabel(Condition.NotContains, "isnt")
34 assertFalse(FeatureMatcher.byLabel(Condition.NotContains, "is")
40 assertTrue(FeatureMatcher.byLabel(Condition.Matches, "THIS is MY label")
42 assertFalse(FeatureMatcher.byLabel(Condition.Matches, "THIS is MY")
48 assertFalse(FeatureMatcher
49 .byLabel(Condition.NotMatches, "THIS is MY label").matches(sf));
50 assertTrue(FeatureMatcher.byLabel(Condition.NotMatches, "THIS is MY")
54 * is present / not present
56 assertTrue(FeatureMatcher.byLabel(Condition.Present, "").matches(sf));
58 FeatureMatcher.byLabel(Condition.NotPresent, "").matches(sf));
62 public void testMatches_byScore()
64 SequenceFeature sf = new SequenceFeature("Cath", "this is my label", 11,
67 assertTrue(FeatureMatcher.byScore(Condition.LT, "3.3").matches(sf));
68 assertFalse(FeatureMatcher.byScore(Condition.LT, "3.2").matches(sf));
69 assertFalse(FeatureMatcher.byScore(Condition.LT, "2.2").matches(sf));
71 assertTrue(FeatureMatcher.byScore(Condition.LE, "3.3").matches(sf));
72 assertTrue(FeatureMatcher.byScore(Condition.LE, "3.2").matches(sf));
73 assertFalse(FeatureMatcher.byScore(Condition.LE, "2.2").matches(sf));
75 assertFalse(FeatureMatcher.byScore(Condition.EQ, "3.3").matches(sf));
76 assertTrue(FeatureMatcher.byScore(Condition.EQ, "3.2").matches(sf));
78 assertFalse(FeatureMatcher.byScore(Condition.GE, "3.3").matches(sf));
79 assertTrue(FeatureMatcher.byScore(Condition.GE, "3.2").matches(sf));
80 assertTrue(FeatureMatcher.byScore(Condition.GE, "2.2").matches(sf));
82 assertFalse(FeatureMatcher.byScore(Condition.GT, "3.3").matches(sf));
83 assertFalse(FeatureMatcher.byScore(Condition.GT, "3.2").matches(sf));
84 assertTrue(FeatureMatcher.byScore(Condition.GT, "2.2").matches(sf));
87 public void testMatches_byAttribute()
90 * a numeric matcher - MatcherTest covers more conditions
92 FeatureMatcherI fm = FeatureMatcher
93 .byAttribute(Condition.GE, "-2", "AF");
94 SequenceFeature sf = new SequenceFeature("Cath", "desc", 11, 12, "grp");
95 assertFalse(fm.matches(sf));
96 sf.setValue("AF", "foobar");
97 assertFalse(fm.matches(sf));
98 sf.setValue("AF", "-2");
99 assertTrue(fm.matches(sf));
100 sf.setValue("AF", "-1");
101 assertTrue(fm.matches(sf));
102 sf.setValue("AF", "-3");
103 assertFalse(fm.matches(sf));
104 sf.setValue("AF", "");
105 assertFalse(fm.matches(sf));
108 * a string pattern matcher
110 fm = FeatureMatcher.byAttribute(Condition.Contains, "Cat", "AF");
111 assertFalse(fm.matches(sf));
112 sf.setValue("AF", "raining cats and dogs");
113 assertTrue(fm.matches(sf));
115 fm = FeatureMatcher.byAttribute(Condition.Present, "", "AC");
116 assertFalse(fm.matches(sf));
117 sf.setValue("AC", "21");
118 assertTrue(fm.matches(sf));
120 fm = FeatureMatcher.byAttribute(Condition.NotPresent, "", "AC_Females");
121 assertTrue(fm.matches(sf));
122 sf.setValue("AC_Females", "21");
123 assertFalse(fm.matches(sf));
127 public void testToString()
130 * toString uses the i18n translation of the enum conditions
132 FeatureMatcherI fm = FeatureMatcher.byAttribute(Condition.LT, "1.2",
134 assertEquals(fm.toString(), "AF < 1.2");
137 * Present / NotPresent omit the value pattern
139 fm = FeatureMatcher.byAttribute(Condition.Present, "", "AF");
140 assertEquals(fm.toString(), "AF Is present");
141 fm = FeatureMatcher.byAttribute(Condition.NotPresent, "", "AF");
142 assertEquals(fm.toString(), "AF Is not present");
146 public void testGetKey()
148 FeatureMatcherI fm = FeatureMatcher.byAttribute(Condition.GE, "-2",
150 assertEquals(fm.getKey(), new String[] { "AF" });
153 * compound key (attribute / subattribute)
155 fm = FeatureMatcher.byAttribute(Condition.GE, "-2F", "CSQ",
157 assertEquals(fm.getKey(), new String[] { "CSQ", "Consequence" });
161 public void testGetMatcher()
163 FeatureMatcherI fm = FeatureMatcher.byAttribute(Condition.GE, "-2f",
165 assertEquals(fm.getMatcher().getCondition(), Condition.GE);
166 assertEquals(fm.getMatcher().getFloatValue(), -2F);
167 assertEquals(fm.getMatcher().getPattern(), "-2.0");