JAL-2808 update spike to latest (filter range, Present option)
[jalview.git] / test / jalview / util / matcher / KeyedMatcherTest.java
1 package jalview.util.matcher;
2
3 import static org.testng.Assert.assertEquals;
4 import static org.testng.Assert.assertFalse;
5 import static org.testng.Assert.assertTrue;
6
7 import org.testng.annotations.Test;
8
9 public class KeyedMatcherTest
10 {
11   @Test
12   public void testMatches()
13   {
14     /*
15      * a numeric matcher - MatcherTest covers more conditions
16      */
17     KeyedMatcherI km = new KeyedMatcher(Condition.GE, -2F, "AF");
18     assertTrue(km.matches(key -> "-2"));
19     assertTrue(km.matches(key -> "-1"));
20     assertFalse(km.matches(key -> "-3"));
21     assertFalse(km.matches(key -> ""));
22     assertFalse(km.matches(key -> "junk"));
23     assertFalse(km.matches(key -> null));
24
25     /*
26      * a string pattern matcher
27      */
28     km = new KeyedMatcher(Condition.Contains, "Cat", "AF");
29     assertTrue(
30             km.matches(key -> "AF".equals(key[0]) ? "raining cats and dogs"
31                     : "showers"));
32   }
33
34   @Test
35   public void testToString()
36   {
37     /*
38      * toString uses the i18n translation of the enum conditions
39      */
40     KeyedMatcherI km = new KeyedMatcher(Condition.LT, 1.2f, "AF");
41     assertEquals(km.toString(), "AF < 1.2");
42
43     /*
44      * Present / NotPresent omit the value pattern
45      */
46     km = new KeyedMatcher(Condition.Present, "", "AF");
47     assertEquals(km.toString(), "AF Is present");
48     km = new KeyedMatcher(Condition.NotPresent, "", "AF");
49     assertEquals(km.toString(), "AF Is not present");
50   }
51
52   @Test
53   public void testGetKey()
54   {
55     KeyedMatcherI km = new KeyedMatcher(Condition.GE, -2F, "AF");
56     assertEquals(km.getKey(), new String[] { "AF" });
57
58     /*
59      * compound key (attribute / subattribute)
60      */
61     km = new KeyedMatcher(Condition.GE, -2F, "CSQ", "Consequence");
62     assertEquals(km.getKey(), new String[] { "CSQ", "Consequence" });
63   }
64
65   @Test
66   public void testGetMatcher()
67   {
68     KeyedMatcherI km = new KeyedMatcher(Condition.GE, -2F, "AF");
69     assertEquals(km.getMatcher().getCondition(), Condition.GE);
70     assertEquals(km.getMatcher().getFloatValue(), -2F);
71     assertEquals(km.getMatcher().getPattern(), "-2.0");
72   }
73 }