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