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