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