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.assertNotEquals; |
6 |
|
import static org.testng.Assert.assertTrue; |
7 |
|
import static org.testng.Assert.fail; |
8 |
|
|
9 |
|
import java.util.Locale; |
10 |
|
|
11 |
|
import org.testng.annotations.Test; |
12 |
|
|
13 |
|
import junit.extensions.PA; |
14 |
|
|
|
|
| 98.5% |
Uncovered Elements: 2 (137) |
Complexity: 11 |
Complexity Density: 0.09 |
|
15 |
|
public class MatcherTest |
16 |
|
{ |
|
|
| 91.3% |
Uncovered Elements: 2 (23) |
Complexity: 3 |
Complexity Density: 0.13 |
1PASS
|
|
17 |
1 |
@Test(groups = "Functional")... |
18 |
|
public void testConstructor() |
19 |
|
{ |
20 |
1 |
MatcherI m = new Matcher(Condition.Contains, "foo"); |
21 |
1 |
assertEquals(m.getCondition(), Condition.Contains); |
22 |
1 |
assertEquals(m.getPattern(), "foo"); |
23 |
1 |
assertEquals(PA.getValue(m, "uppercasePattern"), "FOO"); |
24 |
1 |
assertEquals(m.getFloatValue(), 0f); |
25 |
|
|
26 |
1 |
m = new Matcher(Condition.GT, -2.1f); |
27 |
1 |
assertEquals(m.getCondition(), Condition.GT); |
28 |
1 |
assertEquals(m.getPattern(), "-2.1"); |
29 |
1 |
assertEquals(m.getFloatValue(), -2.1f); |
30 |
|
|
31 |
1 |
m = new Matcher(Condition.NotContains, "-1.2f"); |
32 |
1 |
assertEquals(m.getCondition(), Condition.NotContains); |
33 |
1 |
assertEquals(m.getPattern(), "-1.2f"); |
34 |
1 |
assertEquals(m.getFloatValue(), 0f); |
35 |
|
|
36 |
1 |
m = new Matcher(Condition.GE, "-1.2f"); |
37 |
1 |
assertEquals(m.getCondition(), Condition.GE); |
38 |
1 |
assertEquals(m.getPattern(), "-1.2"); |
39 |
1 |
assertEquals(m.getFloatValue(), -1.2f); |
40 |
|
|
41 |
1 |
try |
42 |
|
{ |
43 |
1 |
new Matcher(null, 0f); |
44 |
0 |
fail("Expected exception"); |
45 |
|
} catch (NullPointerException e) |
46 |
|
{ |
47 |
|
|
48 |
|
} |
49 |
|
|
50 |
1 |
try |
51 |
|
{ |
52 |
1 |
new Matcher(Condition.LT, "123,456"); |
53 |
0 |
fail("Expected exception"); |
54 |
|
} catch (NumberFormatException e) |
55 |
|
{ |
56 |
|
|
57 |
|
} |
58 |
|
} |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 1 |
Complexity Density: 0.04 |
1PASS
|
|
63 |
1 |
@Test(groups = "Functional")... |
64 |
|
public void testMatches_float() |
65 |
|
{ |
66 |
|
|
67 |
|
|
68 |
|
|
69 |
1 |
MatcherI m = new Matcher(Condition.EQ, 2f); |
70 |
1 |
assertTrue(m.matches("2")); |
71 |
1 |
assertTrue(m.matches("2.0")); |
72 |
1 |
assertFalse(m.matches("2.01")); |
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
1 |
m = new Matcher(Condition.NE, 2f); |
78 |
1 |
assertFalse(m.matches("2")); |
79 |
1 |
assertFalse(m.matches("2.0")); |
80 |
1 |
assertTrue(m.matches("2.01")); |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
1 |
m = new Matcher(Condition.GE, 2f); |
86 |
1 |
assertTrue(m.matches("2")); |
87 |
1 |
assertTrue(m.matches("2.1")); |
88 |
1 |
assertFalse(m.matches("1.9")); |
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
1 |
m = new Matcher(Condition.GT, 2f); |
94 |
1 |
assertFalse(m.matches("2")); |
95 |
1 |
assertTrue(m.matches("2.1")); |
96 |
1 |
assertFalse(m.matches("1.9")); |
97 |
|
|
98 |
|
|
99 |
|
|
100 |
|
|
101 |
1 |
m = new Matcher(Condition.LE, 2f); |
102 |
1 |
assertTrue(m.matches("2")); |
103 |
1 |
assertFalse(m.matches("2.1")); |
104 |
1 |
assertTrue(m.matches("1.9")); |
105 |
|
|
106 |
|
|
107 |
|
|
108 |
|
|
109 |
1 |
m = new Matcher(Condition.LT, 2f); |
110 |
1 |
assertFalse(m.matches("2")); |
111 |
1 |
assertFalse(m.matches("2.1")); |
112 |
1 |
assertTrue(m.matches("1.9")); |
113 |
|
} |
114 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
1PASS
|
|
115 |
1 |
@Test(groups = "Functional")... |
116 |
|
public void testMatches_floatNullOrInvalid() |
117 |
|
{ |
118 |
1 |
for (Condition cond : Condition.values()) |
119 |
|
{ |
120 |
12 |
if (cond.isNumeric()) |
121 |
|
{ |
122 |
6 |
MatcherI m = new Matcher(cond, 2f); |
123 |
6 |
assertFalse(m.matches(null)); |
124 |
6 |
assertFalse(m.matches("")); |
125 |
6 |
assertFalse(m.matches("two")); |
126 |
|
} |
127 |
|
} |
128 |
|
} |
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (33) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
133 |
1 |
@Test(groups = "Functional")... |
134 |
|
public void testMatches_pattern() |
135 |
|
{ |
136 |
|
|
137 |
|
|
138 |
|
|
139 |
1 |
MatcherI m = new Matcher(Condition.Contains, "benign"); |
140 |
1 |
assertTrue(m.matches("benign")); |
141 |
1 |
assertTrue(m.matches("MOSTLY BENIGN OBSERVED")); |
142 |
1 |
assertFalse(m.matches("pathogenic")); |
143 |
1 |
assertFalse(m.matches(null)); |
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
1 |
m = new Matcher(Condition.NotContains, "benign"); |
149 |
1 |
assertFalse(m.matches("benign")); |
150 |
1 |
assertFalse(m.matches("MOSTLY BENIGN OBSERVED")); |
151 |
1 |
assertTrue(m.matches("pathogenic")); |
152 |
1 |
assertTrue(m.matches(null)); |
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
1 |
m = new Matcher(Condition.Matches, "benign"); |
158 |
1 |
assertTrue(m.matches("benign")); |
159 |
1 |
assertTrue(m.matches(" Benign ")); |
160 |
1 |
assertFalse(m.matches("MOSTLY BENIGN")); |
161 |
1 |
assertFalse(m.matches("pathogenic")); |
162 |
1 |
assertFalse(m.matches(null)); |
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
1 |
m = new Matcher(Condition.NotMatches, "benign"); |
168 |
1 |
assertFalse(m.matches("benign")); |
169 |
1 |
assertFalse(m.matches(" Benign ")); |
170 |
1 |
assertTrue(m.matches("MOSTLY BENIGN")); |
171 |
1 |
assertTrue(m.matches("pathogenic")); |
172 |
1 |
assertTrue(m.matches(null)); |
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
1 |
m = new Matcher(Condition.Present, null); |
178 |
1 |
assertTrue(m.matches("benign")); |
179 |
1 |
assertTrue(m.matches("")); |
180 |
1 |
assertFalse(m.matches(null)); |
181 |
|
|
182 |
|
|
183 |
|
|
184 |
|
|
185 |
1 |
m = new Matcher(Condition.NotPresent, null); |
186 |
1 |
assertFalse(m.matches("benign")); |
187 |
1 |
assertFalse(m.matches("")); |
188 |
1 |
assertTrue(m.matches(null)); |
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
|
193 |
1 |
Matcher m1 = new Matcher(Condition.Contains, "32"); |
194 |
1 |
assertFalse(m1.matches(-203f)); |
195 |
1 |
assertTrue(m1.matches(-4321.0f)); |
196 |
|
} |
197 |
|
|
198 |
|
|
199 |
|
|
200 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
201 |
1 |
@Test(groups = "Functional")... |
202 |
|
public void testMatches_floatWithStringCondition() |
203 |
|
{ |
204 |
1 |
MatcherI m = new Matcher(Condition.Contains, 1.2e-6f); |
205 |
1 |
assertTrue(m.matches("1.2e-6")); |
206 |
|
|
207 |
1 |
m = new Matcher(Condition.Contains, 0.0000001f); |
208 |
1 |
assertTrue(m.matches("1.0e-7")); |
209 |
1 |
assertTrue(m.matches("1.0E-7")); |
210 |
1 |
assertFalse(m.matches("0.0000001f")); |
211 |
|
} |
212 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
213 |
1 |
@Test(groups = "Functional")... |
214 |
|
public void testToString() |
215 |
|
{ |
216 |
1 |
Locale.setDefault(Locale.ENGLISH); |
217 |
|
|
218 |
1 |
MatcherI m = new Matcher(Condition.LT, 1.2e-6f); |
219 |
1 |
assertEquals(m.toString(), "< 1.2E-6"); |
220 |
|
|
221 |
1 |
m = new Matcher(Condition.NotMatches, "ABC"); |
222 |
1 |
assertEquals(m.toString(), "Does not match 'ABC'"); |
223 |
|
|
224 |
1 |
m = new Matcher(Condition.Contains, -1.2f); |
225 |
1 |
assertEquals(m.toString(), "Contains '-1.2'"); |
226 |
|
} |
227 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
228 |
1 |
@Test(groups = "Functional")... |
229 |
|
public void testEquals() |
230 |
|
{ |
231 |
|
|
232 |
|
|
233 |
|
|
234 |
1 |
MatcherI m = new Matcher(Condition.NotMatches, "ABC"); |
235 |
1 |
assertFalse(m.equals(null)); |
236 |
1 |
assertFalse(m.equals("foo")); |
237 |
1 |
assertTrue(m.equals(m)); |
238 |
1 |
assertTrue(m.equals(new Matcher(Condition.NotMatches, "ABC"))); |
239 |
|
|
240 |
1 |
assertTrue(m.equals(new Matcher(Condition.NotMatches, "abc"))); |
241 |
1 |
assertFalse(m.equals(new Matcher(Condition.Matches, "ABC"))); |
242 |
1 |
assertFalse(m.equals(new Matcher(Condition.NotMatches, "def"))); |
243 |
|
|
244 |
|
|
245 |
|
|
246 |
|
|
247 |
1 |
m = new Matcher(Condition.LT, -1f); |
248 |
1 |
assertFalse(m.equals(null)); |
249 |
1 |
assertFalse(m.equals("foo")); |
250 |
1 |
assertTrue(m.equals(m)); |
251 |
1 |
assertTrue(m.equals(new Matcher(Condition.LT, -1f))); |
252 |
1 |
assertTrue(m.equals(new Matcher(Condition.LT, "-1f"))); |
253 |
1 |
assertTrue(m.equals(new Matcher(Condition.LT, "-1.00f"))); |
254 |
1 |
assertFalse(m.equals(new Matcher(Condition.LE, -1f))); |
255 |
1 |
assertFalse(m.equals(new Matcher(Condition.GE, -1f))); |
256 |
1 |
assertFalse(m.equals(new Matcher(Condition.NE, -1f))); |
257 |
1 |
assertFalse(m.equals(new Matcher(Condition.LT, 1f))); |
258 |
1 |
assertFalse(m.equals(new Matcher(Condition.LT, -1.1f))); |
259 |
|
} |
260 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
261 |
1 |
@Test(groups = "Functional")... |
262 |
|
public void testHashCode() |
263 |
|
{ |
264 |
1 |
MatcherI m1 = new Matcher(Condition.NotMatches, "ABC"); |
265 |
1 |
MatcherI m2 = new Matcher(Condition.NotMatches, "ABC"); |
266 |
1 |
MatcherI m3 = new Matcher(Condition.NotMatches, "AB"); |
267 |
1 |
MatcherI m4 = new Matcher(Condition.Matches, "ABC"); |
268 |
1 |
assertEquals(m1.hashCode(), m2.hashCode()); |
269 |
1 |
assertNotEquals(m1.hashCode(), m3.hashCode()); |
270 |
1 |
assertNotEquals(m1.hashCode(), m4.hashCode()); |
271 |
1 |
assertNotEquals(m3.hashCode(), m4.hashCode()); |
272 |
|
} |
273 |
|
} |