1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.io.gff; |
22 |
|
|
23 |
|
import static org.testng.Assert.assertEquals; |
24 |
|
import static org.testng.Assert.assertFalse; |
25 |
|
import static org.testng.Assert.assertTrue; |
26 |
|
import static org.testng.Assert.fail; |
27 |
|
|
28 |
|
import jalview.gui.JvOptionPane; |
29 |
|
|
30 |
|
import java.util.Arrays; |
31 |
|
import java.util.List; |
32 |
|
import java.util.Map; |
33 |
|
|
34 |
|
import org.testng.annotations.BeforeClass; |
35 |
|
import org.testng.annotations.Test; |
36 |
|
|
|
|
| 99.3% |
Uncovered Elements: 1 (138) |
Complexity: 5 |
Complexity Density: 0.04 |
|
37 |
|
public class GffHelperBaseTest |
38 |
|
{ |
39 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
40 |
1 |
@BeforeClass(alwaysRun = true)... |
41 |
|
public void setUpJvOptionPane() |
42 |
|
{ |
43 |
1 |
JvOptionPane.setInteractiveMode(false); |
44 |
1 |
JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION); |
45 |
|
} |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 1 |
Complexity Density: 0.05 |
1PASS
|
|
51 |
1 |
@Test(groups = { "Functional" })... |
52 |
|
public void testParseNameValuePairs() |
53 |
|
{ |
54 |
1 |
assertTrue(GffHelperBase.parseNameValuePairs(null, ";", ' ', ",") |
55 |
|
.isEmpty()); |
56 |
1 |
assertTrue(GffHelperBase.parseNameValuePairs("", ";", ' ', ",") |
57 |
|
.isEmpty()); |
58 |
1 |
assertTrue(GffHelperBase.parseNameValuePairs("hello=world", ";", ' ', |
59 |
|
",").isEmpty()); |
60 |
|
|
61 |
1 |
Map<String, List<String>> map = GffHelperBase.parseNameValuePairs( |
62 |
|
"hello world", ";", ' ', ", "); |
63 |
1 |
assertEquals(map.size(), 1); |
64 |
1 |
assertEquals(map.get("hello").size(), 1); |
65 |
1 |
assertEquals(map.get("hello").get(0), "world"); |
66 |
|
|
67 |
1 |
map = GffHelperBase |
68 |
|
.parseNameValuePairs( |
69 |
|
"Method= manual curation ;nothing; Notes=F2 S ; Notes=Metal,Shiny%2Csmooth; Type=", |
70 |
|
";", '=', ","); |
71 |
|
|
72 |
|
|
73 |
1 |
assertEquals(map.size(), 2); |
74 |
|
|
75 |
1 |
assertEquals(map.get("Method").size(), 1); |
76 |
1 |
assertEquals(map.get("Method").get(0), "manual curation"); |
77 |
|
|
78 |
1 |
assertEquals(map.get("Notes").size(), 3); |
79 |
1 |
assertEquals(map.get("Notes").get(0), "F2 S"); |
80 |
1 |
assertEquals(map.get("Notes").get(1), "Metal"); |
81 |
1 |
assertEquals(map.get("Notes").get(2), "Shiny%2Csmooth"); |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
1 |
String csqValue = "POLYPHEN=possibly_damaging,probably_damaging,SIFT=tolerated%2Cdeleterious"; |
87 |
1 |
map = GffHelperBase.parseNameValuePairs("hello=world;CSQ=" + csqValue, |
88 |
|
";", '=', ","); |
89 |
1 |
assertEquals(map.size(), 2); |
90 |
1 |
assertEquals(map.get("hello").size(), 1); |
91 |
1 |
assertEquals(map.get("hello").get(0), "world"); |
92 |
|
|
93 |
1 |
assertEquals(map.get("CSQ").size(), 1); |
94 |
1 |
assertEquals(map.get("CSQ").get(0), csqValue); |
95 |
|
} |
96 |
|
|
97 |
|
|
98 |
|
|
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (75) |
Complexity: 1 |
Complexity Density: 0.01 |
1PASS
|
|
100 |
1 |
@Test(groups = "Functional")... |
101 |
|
public void testTrimMapping() |
102 |
|
{ |
103 |
1 |
int[] from = { 1, 12 }; |
104 |
1 |
int[] to = { 20, 31 }; |
105 |
1 |
assertTrue(GffHelperBase.trimMapping(from, to, 1, 1)); |
106 |
1 |
assertEquals(Arrays.toString(from), "[1, 12]"); |
107 |
1 |
assertEquals(Arrays.toString(to), "[20, 31]"); |
108 |
|
|
109 |
|
|
110 |
1 |
from = new int[] { 1, 13 }; |
111 |
1 |
assertTrue(GffHelperBase.trimMapping(from, to, 1, 1)); |
112 |
1 |
assertEquals(Arrays.toString(from), "[1, 12]"); |
113 |
1 |
assertEquals(Arrays.toString(to), "[20, 31]"); |
114 |
|
|
115 |
|
|
116 |
1 |
to = new int[] { 20, 33 }; |
117 |
1 |
assertTrue(GffHelperBase.trimMapping(from, to, 1, 1)); |
118 |
1 |
assertEquals(Arrays.toString(from), "[1, 12]"); |
119 |
1 |
assertEquals(Arrays.toString(to), "[20, 31]"); |
120 |
|
|
121 |
|
|
122 |
1 |
from = new int[] { 12, 1 }; |
123 |
1 |
assertTrue(GffHelperBase.trimMapping(from, to, 1, 1)); |
124 |
1 |
assertEquals(Arrays.toString(from), "[12, 1]"); |
125 |
1 |
assertEquals(Arrays.toString(to), "[20, 31]"); |
126 |
|
|
127 |
|
|
128 |
1 |
to = new int[] { 31, 20 }; |
129 |
1 |
assertTrue(GffHelperBase.trimMapping(from, to, 1, 1)); |
130 |
1 |
assertEquals(Arrays.toString(from), "[12, 1]"); |
131 |
1 |
assertEquals(Arrays.toString(to), "[31, 20]"); |
132 |
|
|
133 |
|
|
134 |
1 |
from = new int[] { 14, 1 }; |
135 |
1 |
assertTrue(GffHelperBase.trimMapping(from, to, 1, 1)); |
136 |
1 |
assertEquals(Arrays.toString(from), "[14, 3]"); |
137 |
1 |
assertEquals(Arrays.toString(to), "[31, 20]"); |
138 |
|
|
139 |
|
|
140 |
1 |
to = new int[] { 31, 10 }; |
141 |
1 |
assertTrue(GffHelperBase.trimMapping(from, to, 1, 1)); |
142 |
1 |
assertEquals(Arrays.toString(from), "[14, 3]"); |
143 |
1 |
assertEquals(Arrays.toString(to), "[31, 20]"); |
144 |
|
|
145 |
|
|
146 |
1 |
from = new int[] { 1, 18 }; |
147 |
1 |
to = new int[] { 4, 9 }; |
148 |
1 |
assertTrue(GffHelperBase.trimMapping(from, to, 3, 1)); |
149 |
1 |
assertEquals(Arrays.toString(from), "[1, 18]"); |
150 |
1 |
assertEquals(Arrays.toString(to), "[4, 9]"); |
151 |
|
|
152 |
|
|
153 |
1 |
from = new int[] { 1, 20 }; |
154 |
1 |
assertTrue(GffHelperBase.trimMapping(from, to, 3, 1)); |
155 |
1 |
assertEquals(Arrays.toString(from), "[1, 18]"); |
156 |
1 |
assertEquals(Arrays.toString(to), "[4, 9]"); |
157 |
|
|
158 |
|
|
159 |
1 |
from = new int[] { 20, 1 }; |
160 |
1 |
assertTrue(GffHelperBase.trimMapping(from, to, 3, 1)); |
161 |
1 |
assertEquals(Arrays.toString(from), "[20, 3]"); |
162 |
1 |
assertEquals(Arrays.toString(to), "[4, 9]"); |
163 |
|
|
164 |
|
|
165 |
1 |
from = new int[] { 20, 1 }; |
166 |
1 |
to = new int[] { 9, 4 }; |
167 |
1 |
assertTrue(GffHelperBase.trimMapping(from, to, 3, 1)); |
168 |
1 |
assertEquals(Arrays.toString(from), "[20, 3]"); |
169 |
1 |
assertEquals(Arrays.toString(to), "[9, 4]"); |
170 |
|
|
171 |
|
|
172 |
1 |
from = new int[] { 4, 9 }; |
173 |
1 |
to = new int[] { 1, 18 }; |
174 |
1 |
assertTrue(GffHelperBase.trimMapping(from, to, 1, 3)); |
175 |
1 |
assertEquals(Arrays.toString(from), "[4, 9]"); |
176 |
1 |
assertEquals(Arrays.toString(to), "[1, 18]"); |
177 |
|
|
178 |
|
|
179 |
1 |
to = new int[] { 1, 20 }; |
180 |
1 |
assertTrue(GffHelperBase.trimMapping(from, to, 1, 3)); |
181 |
1 |
assertEquals(Arrays.toString(from), "[4, 9]"); |
182 |
1 |
assertEquals(Arrays.toString(to), "[1, 18]"); |
183 |
|
|
184 |
|
|
185 |
1 |
to = new int[] { 20, 1 }; |
186 |
1 |
assertTrue(GffHelperBase.trimMapping(from, to, 1, 3)); |
187 |
1 |
assertEquals(Arrays.toString(from), "[4, 9]"); |
188 |
1 |
assertEquals(Arrays.toString(to), "[20, 3]"); |
189 |
|
|
190 |
|
|
191 |
1 |
from = new int[] { 9, 4 }; |
192 |
1 |
to = new int[] { 20, 1 }; |
193 |
1 |
assertTrue(GffHelperBase.trimMapping(from, to, 1, 3)); |
194 |
1 |
assertEquals(Arrays.toString(from), "[9, 4]"); |
195 |
1 |
assertEquals(Arrays.toString(to), "[20, 3]"); |
196 |
|
|
197 |
|
|
198 |
1 |
from = new int[] { 4, 10 }; |
199 |
1 |
to = new int[] { 1, 18 }; |
200 |
1 |
assertTrue(GffHelperBase.trimMapping(from, to, 1, 3)); |
201 |
1 |
assertEquals(Arrays.toString(from), "[4, 9]"); |
202 |
1 |
assertEquals(Arrays.toString(to), "[1, 18]"); |
203 |
|
|
204 |
|
|
205 |
1 |
from = new int[] { 4, 10 }; |
206 |
1 |
to = new int[] { 1, 19 }; |
207 |
1 |
assertFalse(GffHelperBase.trimMapping(from, to, 1, 3)); |
208 |
1 |
assertEquals(Arrays.toString(from), "[4, 10]"); |
209 |
1 |
assertEquals(Arrays.toString(to), "[1, 19]"); |
210 |
|
} |
211 |
|
|
|
|
| 97.1% |
Uncovered Elements: 1 (35) |
Complexity: 2 |
Complexity Density: 0.06 |
1PASS
|
|
212 |
1 |
@Test(groups = { "Functional" })... |
213 |
|
public void testParseAttributeMap() |
214 |
|
{ |
215 |
1 |
Map<String, String> map = GffHelperBase |
216 |
|
.parseAttributeMap("A=B,C%2C%3D%3B%09%25D,X=Y"); |
217 |
1 |
assertEquals(map.size(), 2); |
218 |
|
|
219 |
1 |
assertEquals(map.get("A"), "B,C,=;\t%D"); |
220 |
1 |
assertEquals(map.get("X"), "Y"); |
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
1 |
map = GffHelperBase.parseAttributeMap("=B=Y"); |
226 |
1 |
assertTrue(map.isEmpty()); |
227 |
|
|
228 |
1 |
map = GffHelperBase.parseAttributeMap("A,B=C"); |
229 |
1 |
assertTrue(map.isEmpty()); |
230 |
|
|
231 |
1 |
map = GffHelperBase.parseAttributeMap("A=B=C"); |
232 |
1 |
assertTrue(map.isEmpty()); |
233 |
|
|
234 |
1 |
map = GffHelperBase.parseAttributeMap("A=B"); |
235 |
1 |
assertEquals(map.get("A"), "B"); |
236 |
1 |
map = GffHelperBase.parseAttributeMap("A=B,C"); |
237 |
1 |
assertEquals(map.get("A"), "B,C"); |
238 |
1 |
map = GffHelperBase.parseAttributeMap("A"); |
239 |
1 |
assertTrue(map.isEmpty()); |
240 |
1 |
map = GffHelperBase.parseAttributeMap("A="); |
241 |
1 |
assertTrue(map.isEmpty()); |
242 |
1 |
map = GffHelperBase.parseAttributeMap("A==C"); |
243 |
1 |
assertTrue(map.isEmpty()); |
244 |
1 |
map = GffHelperBase.parseAttributeMap("=A"); |
245 |
1 |
assertTrue(map.isEmpty()); |
246 |
1 |
map = GffHelperBase.parseAttributeMap("="); |
247 |
1 |
assertTrue(map.isEmpty()); |
248 |
1 |
map = GffHelperBase.parseAttributeMap(","); |
249 |
1 |
assertTrue(map.isEmpty()); |
250 |
1 |
map = GffHelperBase.parseAttributeMap(" "); |
251 |
1 |
assertTrue(map.isEmpty()); |
252 |
1 |
map = GffHelperBase.parseAttributeMap(""); |
253 |
1 |
assertTrue(map.isEmpty()); |
254 |
1 |
map = GffHelperBase.parseAttributeMap("A=B, =C"); |
255 |
1 |
assertTrue(map.isEmpty()); |
256 |
|
|
257 |
1 |
try |
258 |
|
{ |
259 |
1 |
GffHelperBase.parseAttributeMap(null); |
260 |
0 |
fail("expected exception"); |
261 |
|
} catch (NullPointerException e) |
262 |
|
{ |
263 |
|
|
264 |
|
} |
265 |
|
} |
266 |
|
} |