1 |
|
package jalview.datamodel.features; |
2 |
|
|
3 |
|
import static org.testng.Assert.assertEquals; |
4 |
|
import static org.testng.Assert.assertFalse; |
5 |
|
import static org.testng.Assert.assertNull; |
6 |
|
import static org.testng.Assert.assertSame; |
7 |
|
import static org.testng.Assert.assertTrue; |
8 |
|
|
9 |
|
import jalview.datamodel.SequenceFeature; |
10 |
|
import jalview.util.MessageManager; |
11 |
|
import jalview.util.matcher.Condition; |
12 |
|
|
13 |
|
import java.util.Locale; |
14 |
|
|
15 |
|
import org.testng.annotations.Test; |
16 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (168) |
Complexity: 11 |
Complexity Density: 0.07 |
|
17 |
|
public class FeatureMatcherTest |
18 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
19 |
1 |
@Test(groups = "Functional")... |
20 |
|
public void testMatches_byLabel() |
21 |
|
{ |
22 |
1 |
SequenceFeature sf = new SequenceFeature("Cath", "this is my label", 11, |
23 |
|
12, "grp"); |
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
1 |
assertTrue( |
29 |
|
FeatureMatcher.byLabel(Condition.Contains, "IS").matches(sf)); |
30 |
1 |
assertTrue(FeatureMatcher.byLabel(Condition.Contains, "").matches(sf)); |
31 |
1 |
assertFalse( |
32 |
|
FeatureMatcher.byLabel(Condition.Contains, "ISNT").matches(sf)); |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
1 |
assertTrue(FeatureMatcher.byLabel(Condition.NotContains, "isnt") |
38 |
|
.matches(sf)); |
39 |
1 |
assertFalse(FeatureMatcher.byLabel(Condition.NotContains, "is") |
40 |
|
.matches(sf)); |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
1 |
assertTrue(FeatureMatcher.byLabel(Condition.Matches, "THIS is MY label") |
46 |
|
.matches(sf)); |
47 |
1 |
assertFalse(FeatureMatcher.byLabel(Condition.Matches, "THIS is MY") |
48 |
|
.matches(sf)); |
49 |
|
|
50 |
|
|
51 |
|
|
52 |
|
|
53 |
1 |
assertFalse(FeatureMatcher |
54 |
|
.byLabel(Condition.NotMatches, "THIS is MY label").matches(sf)); |
55 |
1 |
assertTrue(FeatureMatcher.byLabel(Condition.NotMatches, "THIS is MY") |
56 |
|
.matches(sf)); |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
1 |
assertTrue(FeatureMatcher.byLabel(Condition.Present, "").matches(sf)); |
62 |
1 |
assertFalse( |
63 |
|
FeatureMatcher.byLabel(Condition.NotPresent, "").matches(sf)); |
64 |
|
} |
65 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
66 |
1 |
@Test(groups = "Functional")... |
67 |
|
public void testMatches_byScore() |
68 |
|
{ |
69 |
1 |
SequenceFeature sf = new SequenceFeature("Cath", "this is my label", 11, |
70 |
|
12, 3.2f, "grp"); |
71 |
|
|
72 |
1 |
assertTrue(FeatureMatcher.byScore(Condition.LT, "3.3").matches(sf)); |
73 |
1 |
assertFalse(FeatureMatcher.byScore(Condition.LT, "3.2").matches(sf)); |
74 |
1 |
assertFalse(FeatureMatcher.byScore(Condition.LT, "2.2").matches(sf)); |
75 |
|
|
76 |
1 |
assertTrue(FeatureMatcher.byScore(Condition.LE, "3.3").matches(sf)); |
77 |
1 |
assertTrue(FeatureMatcher.byScore(Condition.LE, "3.2").matches(sf)); |
78 |
1 |
assertFalse(FeatureMatcher.byScore(Condition.LE, "2.2").matches(sf)); |
79 |
|
|
80 |
1 |
assertFalse(FeatureMatcher.byScore(Condition.EQ, "3.3").matches(sf)); |
81 |
1 |
assertTrue(FeatureMatcher.byScore(Condition.EQ, "3.2").matches(sf)); |
82 |
|
|
83 |
1 |
assertFalse(FeatureMatcher.byScore(Condition.GE, "3.3").matches(sf)); |
84 |
1 |
assertTrue(FeatureMatcher.byScore(Condition.GE, "3.2").matches(sf)); |
85 |
1 |
assertTrue(FeatureMatcher.byScore(Condition.GE, "2.2").matches(sf)); |
86 |
|
|
87 |
1 |
assertFalse(FeatureMatcher.byScore(Condition.GT, "3.3").matches(sf)); |
88 |
1 |
assertFalse(FeatureMatcher.byScore(Condition.GT, "3.2").matches(sf)); |
89 |
1 |
assertTrue(FeatureMatcher.byScore(Condition.GT, "2.2").matches(sf)); |
90 |
|
} |
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
92 |
1 |
@Test(groups = "Functional")... |
93 |
|
public void testMatches_byAttribute() |
94 |
|
{ |
95 |
|
|
96 |
|
|
97 |
|
|
98 |
1 |
FeatureMatcherI fm = FeatureMatcher |
99 |
|
.byAttribute(Condition.GE, "-2", "AF"); |
100 |
1 |
SequenceFeature sf = new SequenceFeature("Cath", "desc", 11, 12, "grp"); |
101 |
1 |
assertFalse(fm.matches(sf)); |
102 |
1 |
sf.setValue("AF", "foobar"); |
103 |
1 |
assertFalse(fm.matches(sf)); |
104 |
1 |
sf.setValue("AF", "-2"); |
105 |
1 |
assertTrue(fm.matches(sf)); |
106 |
1 |
sf.setValue("AF", "-1"); |
107 |
1 |
assertTrue(fm.matches(sf)); |
108 |
1 |
sf.setValue("AF", "-3"); |
109 |
1 |
assertFalse(fm.matches(sf)); |
110 |
1 |
sf.setValue("AF", ""); |
111 |
1 |
assertFalse(fm.matches(sf)); |
112 |
|
|
113 |
|
|
114 |
|
|
115 |
|
|
116 |
1 |
fm = FeatureMatcher.byAttribute(Condition.Contains, "Cat", "AF"); |
117 |
1 |
assertFalse(fm.matches(sf)); |
118 |
1 |
sf.setValue("AF", "raining cats and dogs"); |
119 |
1 |
assertTrue(fm.matches(sf)); |
120 |
|
|
121 |
1 |
fm = FeatureMatcher.byAttribute(Condition.Present, "", "AC"); |
122 |
1 |
assertFalse(fm.matches(sf)); |
123 |
1 |
sf.setValue("AC", "21"); |
124 |
1 |
assertTrue(fm.matches(sf)); |
125 |
|
|
126 |
1 |
fm = FeatureMatcher.byAttribute(Condition.NotPresent, "", "AC_Females"); |
127 |
1 |
assertTrue(fm.matches(sf)); |
128 |
1 |
sf.setValue("AC_Females", "21"); |
129 |
1 |
assertFalse(fm.matches(sf)); |
130 |
|
} |
131 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
132 |
1 |
@Test(groups = "Functional")... |
133 |
|
public void testToString() |
134 |
|
{ |
135 |
1 |
Locale.setDefault(Locale.ENGLISH); |
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
1 |
FeatureMatcherI fm = FeatureMatcher.byAttribute(Condition.LT, "1.2", |
141 |
|
"AF"); |
142 |
1 |
assertEquals(fm.toString(), "AF < 1.2"); |
143 |
|
|
144 |
|
|
145 |
|
|
146 |
|
|
147 |
1 |
fm = FeatureMatcher.byAttribute(Condition.Present, "", "AF"); |
148 |
1 |
assertEquals(fm.toString(), "AF is present"); |
149 |
1 |
fm = FeatureMatcher.byAttribute(Condition.NotPresent, "", "AF"); |
150 |
1 |
assertEquals(fm.toString(), "AF is not present"); |
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
1 |
fm = FeatureMatcher.byLabel(Condition.Matches, "foobar"); |
156 |
1 |
assertEquals(fm.toString(), |
157 |
|
MessageManager.getString("label.label") + " matches 'foobar'"); |
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
1 |
fm = FeatureMatcher.byScore(Condition.GE, "12.2"); |
163 |
1 |
assertEquals(fm.toString(), |
164 |
|
MessageManager.getString("label.score") + " >= 12.2"); |
165 |
|
} |
166 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
167 |
1 |
@Test(groups = "Functional")... |
168 |
|
public void testGetAttribute() |
169 |
|
{ |
170 |
1 |
FeatureMatcherI fm = FeatureMatcher.byAttribute(Condition.GE, "-2", |
171 |
|
"AF"); |
172 |
1 |
assertEquals(fm.getAttribute(), new String[] { "AF" }); |
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
1 |
fm = FeatureMatcher.byAttribute(Condition.GE, "-2F", "CSQ", |
178 |
|
"Consequence"); |
179 |
1 |
assertEquals(fm.getAttribute(), new String[] { "CSQ", "Consequence" }); |
180 |
|
|
181 |
|
|
182 |
|
|
183 |
|
|
184 |
1 |
assertNull(FeatureMatcher.byLabel(Condition.NotContains, "foo") |
185 |
|
.getAttribute()); |
186 |
1 |
assertNull(FeatureMatcher.byScore(Condition.LE, "-1").getAttribute()); |
187 |
|
} |
188 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
189 |
1 |
@Test(groups = "Functional")... |
190 |
|
public void testIsByAttribute() |
191 |
|
{ |
192 |
1 |
assertFalse(FeatureMatcher.byLabel(Condition.NotContains, "foo") |
193 |
|
.isByAttribute()); |
194 |
1 |
assertFalse(FeatureMatcher.byScore(Condition.LE, "-1").isByAttribute()); |
195 |
1 |
assertTrue(FeatureMatcher.byAttribute(Condition.LE, "-1", "AC") |
196 |
|
.isByAttribute()); |
197 |
|
} |
198 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
199 |
1 |
@Test(groups = "Functional")... |
200 |
|
public void testIsByLabel() |
201 |
|
{ |
202 |
1 |
assertTrue(FeatureMatcher.byLabel(Condition.NotContains, "foo") |
203 |
|
.isByLabel()); |
204 |
1 |
assertFalse(FeatureMatcher.byScore(Condition.LE, "-1").isByLabel()); |
205 |
1 |
assertFalse(FeatureMatcher.byAttribute(Condition.LE, "-1", "AC") |
206 |
|
.isByLabel()); |
207 |
|
} |
208 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
209 |
1 |
@Test(groups = "Functional")... |
210 |
|
public void testIsByScore() |
211 |
|
{ |
212 |
1 |
assertFalse(FeatureMatcher.byLabel(Condition.NotContains, "foo") |
213 |
|
.isByScore()); |
214 |
1 |
assertTrue(FeatureMatcher.byScore(Condition.LE, "-1").isByScore()); |
215 |
1 |
assertFalse(FeatureMatcher.byAttribute(Condition.LE, "-1", "AC") |
216 |
|
.isByScore()); |
217 |
|
} |
218 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
219 |
1 |
@Test(groups = "Functional")... |
220 |
|
public void testGetMatcher() |
221 |
|
{ |
222 |
1 |
FeatureMatcherI fm = FeatureMatcher.byAttribute(Condition.GE, "-2f", |
223 |
|
"AF"); |
224 |
1 |
assertEquals(fm.getMatcher().getCondition(), Condition.GE); |
225 |
1 |
assertEquals(fm.getMatcher().getFloatValue(), -2F); |
226 |
1 |
assertEquals(fm.getMatcher().getPattern(), "-2.0"); |
227 |
|
} |
228 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (63) |
Complexity: 1 |
Complexity Density: 0.02 |
1PASS
|
|
229 |
1 |
@Test(groups = "Functional")... |
230 |
|
public void testFromString() |
231 |
|
{ |
232 |
1 |
FeatureMatcherI fm = FeatureMatcher.fromString("'AF' LT 1.2"); |
233 |
1 |
assertFalse(fm.isByLabel()); |
234 |
1 |
assertFalse(fm.isByScore()); |
235 |
1 |
assertEquals(fm.getAttribute(), new String[] { "AF" }); |
236 |
1 |
assertSame(Condition.LT, fm.getMatcher().getCondition()); |
237 |
1 |
assertEquals(fm.getMatcher().getFloatValue(), 1.2f); |
238 |
1 |
assertEquals(fm.getMatcher().getPattern(), "1.2"); |
239 |
|
|
240 |
|
|
241 |
1 |
fm = FeatureMatcher.fromString("AF lt '1.2'"); |
242 |
1 |
assertFalse(fm.isByLabel()); |
243 |
1 |
assertFalse(fm.isByScore()); |
244 |
1 |
assertEquals(fm.getAttribute(), new String[] { "AF" }); |
245 |
1 |
assertSame(Condition.LT, fm.getMatcher().getCondition()); |
246 |
1 |
assertEquals(fm.getMatcher().getFloatValue(), 1.2f); |
247 |
1 |
assertEquals(fm.getMatcher().getPattern(), "1.2"); |
248 |
|
|
249 |
1 |
fm = FeatureMatcher.fromString("'AF' Present"); |
250 |
1 |
assertFalse(fm.isByLabel()); |
251 |
1 |
assertFalse(fm.isByScore()); |
252 |
1 |
assertEquals(fm.getAttribute(), new String[] { "AF" }); |
253 |
1 |
assertSame(Condition.Present, fm.getMatcher().getCondition()); |
254 |
|
|
255 |
1 |
fm = FeatureMatcher.fromString("CSQ:Consequence contains damaging"); |
256 |
1 |
assertFalse(fm.isByLabel()); |
257 |
1 |
assertFalse(fm.isByScore()); |
258 |
1 |
assertEquals(fm.getAttribute(), new String[] { "CSQ", "Consequence" }); |
259 |
1 |
assertSame(Condition.Contains, fm.getMatcher().getCondition()); |
260 |
1 |
assertEquals(fm.getMatcher().getPattern(), "damaging"); |
261 |
|
|
262 |
|
|
263 |
1 |
fm = FeatureMatcher.fromString("LABEL Matches 'foobar'"); |
264 |
1 |
assertTrue(fm.isByLabel()); |
265 |
1 |
assertFalse(fm.isByScore()); |
266 |
1 |
assertNull(fm.getAttribute()); |
267 |
1 |
assertSame(Condition.Matches, fm.getMatcher().getCondition()); |
268 |
1 |
assertEquals(fm.getMatcher().getPattern(), "foobar"); |
269 |
|
|
270 |
1 |
fm = FeatureMatcher.fromString("'Label' matches 'foo bar'"); |
271 |
1 |
assertTrue(fm.isByLabel()); |
272 |
1 |
assertFalse(fm.isByScore()); |
273 |
1 |
assertNull(fm.getAttribute()); |
274 |
1 |
assertSame(Condition.Matches, fm.getMatcher().getCondition()); |
275 |
1 |
assertEquals(fm.getMatcher().getPattern(), "foo bar"); |
276 |
|
|
277 |
|
|
278 |
1 |
fm = FeatureMatcher.fromString("'Label' matches foo bar"); |
279 |
1 |
assertTrue(fm.isByLabel()); |
280 |
1 |
assertFalse(fm.isByScore()); |
281 |
1 |
assertNull(fm.getAttribute()); |
282 |
1 |
assertSame(Condition.Matches, fm.getMatcher().getCondition()); |
283 |
1 |
assertEquals(fm.getMatcher().getPattern(), "foo bar"); |
284 |
|
|
285 |
1 |
fm = FeatureMatcher.fromString("Score GE 12.2"); |
286 |
1 |
assertFalse(fm.isByLabel()); |
287 |
1 |
assertTrue(fm.isByScore()); |
288 |
1 |
assertNull(fm.getAttribute()); |
289 |
1 |
assertSame(Condition.GE, fm.getMatcher().getCondition()); |
290 |
1 |
assertEquals(fm.getMatcher().getPattern(), "12.2"); |
291 |
1 |
assertEquals(fm.getMatcher().getFloatValue(), 12.2f); |
292 |
|
|
293 |
|
|
294 |
1 |
fm = FeatureMatcher.fromString("'SCORE' ge '12.2'"); |
295 |
1 |
assertFalse(fm.isByLabel()); |
296 |
1 |
assertTrue(fm.isByScore()); |
297 |
1 |
assertNull(fm.getAttribute()); |
298 |
1 |
assertSame(Condition.GE, fm.getMatcher().getCondition()); |
299 |
1 |
assertEquals(fm.getMatcher().getPattern(), "12.2"); |
300 |
1 |
assertEquals(fm.getMatcher().getFloatValue(), 12.2f); |
301 |
|
|
302 |
|
|
303 |
1 |
assertNull(FeatureMatcher.fromString("Score eq twelve")); |
304 |
|
|
305 |
1 |
assertNull(FeatureMatcher.fromString("'Score ge 12.2")); |
306 |
|
|
307 |
1 |
assertNull(FeatureMatcher.fromString("'Score' ge '12.2")); |
308 |
|
|
309 |
1 |
assertNull(FeatureMatcher.fromString("Score ge")); |
310 |
|
|
311 |
1 |
assertNull(FeatureMatcher.fromString("Score")); |
312 |
|
|
313 |
1 |
assertNull(FeatureMatcher.fromString("")); |
314 |
|
} |
315 |
|
|
316 |
|
|
317 |
|
|
318 |
|
|
319 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
320 |
1 |
@Test(groups = "Functional")... |
321 |
|
public void testToStableString() |
322 |
|
{ |
323 |
|
|
324 |
1 |
FeatureMatcherI fm = FeatureMatcher.byAttribute(Condition.LT, "1.2", |
325 |
|
"AF"); |
326 |
1 |
assertEquals(fm.toStableString(), "AF LT 1.2"); |
327 |
|
|
328 |
|
|
329 |
|
|
330 |
|
|
331 |
1 |
fm = FeatureMatcher.byAttribute(Condition.Present, "", "AF"); |
332 |
1 |
assertEquals(fm.toStableString(), "AF Present"); |
333 |
1 |
fm = FeatureMatcher.byAttribute(Condition.NotPresent, "", "AF"); |
334 |
1 |
assertEquals(fm.toStableString(), "AF NotPresent"); |
335 |
|
|
336 |
|
|
337 |
|
|
338 |
|
|
339 |
|
|
340 |
1 |
fm = FeatureMatcher.byLabel(Condition.Matches, "foobar"); |
341 |
1 |
assertEquals(fm.toStableString(), "Label Matches foobar"); |
342 |
|
|
343 |
1 |
fm = FeatureMatcher.byLabel(Condition.Matches, "foo bar"); |
344 |
1 |
assertEquals(fm.toStableString(), "Label Matches 'foo bar'"); |
345 |
|
|
346 |
|
|
347 |
|
|
348 |
|
|
349 |
1 |
fm = FeatureMatcher.byScore(Condition.GE, "12.2"); |
350 |
1 |
assertEquals(fm.toStableString(), "Score GE 12.2"); |
351 |
|
} |
352 |
|
} |