1 | package de.ugoe.cs.autoquest.usageprofiles;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.Collection;
|
---|
5 | import java.util.HashSet;
|
---|
6 | import java.util.List;
|
---|
7 |
|
---|
8 | import junitx.framework.ListAssert;
|
---|
9 |
|
---|
10 | import org.junit.*;
|
---|
11 |
|
---|
12 | import de.ugoe.cs.autoquest.usageprofiles.Trie;
|
---|
13 | import de.ugoe.cs.autoquest.usageprofiles.TrieNode;
|
---|
14 | import de.ugoe.cs.autoquest.usageprofiles.Trie.Edge;
|
---|
15 | import de.ugoe.cs.autoquest.usageprofiles.Trie.TrieVertex;
|
---|
16 | import static org.junit.Assert.*;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * The class <code>TrieTest</code> contains tests for the class
|
---|
20 | * <code>{@link Trie}</code>.
|
---|
21 | *
|
---|
22 | * @author Steffen Herbold
|
---|
23 | * @version 1.0
|
---|
24 | */
|
---|
25 | public class TrieTest {
|
---|
26 |
|
---|
27 | List<String> sequence;
|
---|
28 | Collection<String> symbols;
|
---|
29 |
|
---|
30 | private static void assertCollectionContent(Collection<?> c1,
|
---|
31 | Collection<?> c2) {
|
---|
32 | assertEquals(c1.size(), c2.size());
|
---|
33 | for (Object obj : c1) {
|
---|
34 | assertTrue(c2.contains(obj));
|
---|
35 | }
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Test
|
---|
39 | public void testTrie_1() throws Exception {
|
---|
40 |
|
---|
41 | Trie<String> result = new Trie<String>();
|
---|
42 |
|
---|
43 | assertNotNull(result);
|
---|
44 | assertEquals(0, result.getNumLeafs());
|
---|
45 | assertEquals(0, result.getNumSymbols());
|
---|
46 | assertEquals(0, result.getNumLeafAncestors());
|
---|
47 | assertTrue(result.getKnownSymbols().isEmpty());
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Test
|
---|
51 | public void testTrie_2() throws Exception {
|
---|
52 | Trie<String> trie1 = new Trie<String>();
|
---|
53 | trie1.train(sequence, 3);
|
---|
54 |
|
---|
55 | Trie<String> result = new Trie<String>(trie1);
|
---|
56 |
|
---|
57 | assertEquals(trie1, result);
|
---|
58 | assertNotSame(trie1, result);
|
---|
59 | }
|
---|
60 |
|
---|
61 | @Test(expected = java.lang.IllegalArgumentException.class)
|
---|
62 | public void testTrie_3() throws Exception {
|
---|
63 | new Trie<String>(null);
|
---|
64 | }
|
---|
65 |
|
---|
66 | @Test
|
---|
67 | public void testAdd_1() throws Exception {
|
---|
68 | Trie<String> fixture = new Trie<String>();
|
---|
69 | List<String> seq = new ArrayList<String>();
|
---|
70 | seq.add("a");
|
---|
71 | seq.add("b");
|
---|
72 |
|
---|
73 | fixture.add(seq);
|
---|
74 |
|
---|
75 | assertEquals(1, fixture.getChild("a").getCount());
|
---|
76 | assertEquals(1, fixture.getChild("a").getChild("b").getCount());
|
---|
77 | assertNull(fixture.getChild("b"));
|
---|
78 | }
|
---|
79 |
|
---|
80 | @Test
|
---|
81 | public void testAdd_2() throws Exception {
|
---|
82 | Trie<String> fixture = new Trie<String>();
|
---|
83 |
|
---|
84 | fixture.add(new ArrayList<String>());
|
---|
85 |
|
---|
86 | assertEquals(0, fixture.getNumSymbols());
|
---|
87 | }
|
---|
88 |
|
---|
89 | @Test
|
---|
90 | public void testAdd_3() throws Exception {
|
---|
91 | Trie<String> fixture = new Trie<String>();
|
---|
92 |
|
---|
93 | fixture.add(null);
|
---|
94 |
|
---|
95 | assertEquals(0, fixture.getNumSymbols());
|
---|
96 | }
|
---|
97 |
|
---|
98 | @Test
|
---|
99 | public void testFind_1() throws Exception {
|
---|
100 | Trie<String> fixture = new Trie<String>();
|
---|
101 | fixture.train(sequence, 3);
|
---|
102 | List<String> findSequence = new ArrayList<String>();
|
---|
103 | findSequence.add("a");
|
---|
104 | findSequence.add("b");
|
---|
105 | findSequence.add("r");
|
---|
106 | TrieNode<String> expected = fixture.getChild("a").getChild("b")
|
---|
107 | .getChild("r");
|
---|
108 |
|
---|
109 | TrieNode<String> result = fixture.find(findSequence);
|
---|
110 |
|
---|
111 | assertEquals(expected, result);
|
---|
112 | }
|
---|
113 |
|
---|
114 | @Test
|
---|
115 | public void testFind_2() throws Exception {
|
---|
116 | Trie<String> fixture = new Trie<String>();
|
---|
117 | fixture.train(sequence, 3);
|
---|
118 | List<String> findSequence = new ArrayList<String>();
|
---|
119 | findSequence.add("c");
|
---|
120 | findSequence.add("a");
|
---|
121 | TrieNode<String> expected = fixture.getChild("c").getChild("a");
|
---|
122 |
|
---|
123 | TrieNode<String> result = fixture.find(findSequence);
|
---|
124 |
|
---|
125 | assertEquals(expected, result);
|
---|
126 | }
|
---|
127 |
|
---|
128 | @Test
|
---|
129 | public void testFind_3() throws Exception {
|
---|
130 | Trie<String> fixture = new Trie<String>();
|
---|
131 | fixture.train(sequence, 3);
|
---|
132 | List<String> findSequence = new ArrayList<String>();
|
---|
133 |
|
---|
134 | TrieNode<String> result = fixture.find(findSequence);
|
---|
135 |
|
---|
136 | assertTrue(result.isRoot());
|
---|
137 | }
|
---|
138 |
|
---|
139 | @Test
|
---|
140 | public void testFind_4() throws Exception {
|
---|
141 | Trie<String> fixture = new Trie<String>();
|
---|
142 | fixture.train(sequence, 3);
|
---|
143 |
|
---|
144 | TrieNode<String> result = fixture.find(null);
|
---|
145 |
|
---|
146 | assertTrue(result.isRoot());
|
---|
147 | }
|
---|
148 |
|
---|
149 | @Test
|
---|
150 | public void testGetChildCreate_1() throws Exception {
|
---|
151 | Trie<String> fixture = new Trie<String>();
|
---|
152 | String symbol = "a";
|
---|
153 |
|
---|
154 | TrieNode<String> result = fixture.getChildCreate(symbol);
|
---|
155 |
|
---|
156 | assertEquals(symbol, result.getSymbol());
|
---|
157 | assertEquals(0, result.getCount());
|
---|
158 | assertTrue(result.isLeaf());
|
---|
159 | }
|
---|
160 |
|
---|
161 | @Test(expected = java.lang.IllegalArgumentException.class)
|
---|
162 | public void testGetChildCreate_2() throws Exception {
|
---|
163 | Trie<String> fixture = new Trie<String>();
|
---|
164 | fixture.getChildCreate(null);
|
---|
165 | }
|
---|
166 |
|
---|
167 | @Test
|
---|
168 | public void testGetContextSuffix_1() throws Exception {
|
---|
169 | Trie<String> fixture = new Trie<String>();
|
---|
170 | fixture.train(sequence, 3);
|
---|
171 | List<String> context = new ArrayList<String>();
|
---|
172 | context.add("a");
|
---|
173 | context.add("a");
|
---|
174 | context.add("b");
|
---|
175 | List<String> expected = new ArrayList<String>();
|
---|
176 | expected.add("a");
|
---|
177 | expected.add("b");
|
---|
178 |
|
---|
179 | List<String> result = fixture.getContextSuffix(context);
|
---|
180 |
|
---|
181 | ListAssert.assertEquals(expected, result);
|
---|
182 | }
|
---|
183 |
|
---|
184 | @Test
|
---|
185 | public void testGetContextSuffix_2() throws Exception {
|
---|
186 | Trie<String> fixture = new Trie<String>();
|
---|
187 | fixture.train(sequence, 3);
|
---|
188 | List<String> context = new ArrayList<String>();
|
---|
189 | context.add("a");
|
---|
190 | context.add("a");
|
---|
191 | context.add("b");
|
---|
192 | context.add("r");
|
---|
193 | List<String> expected = new ArrayList<String>();
|
---|
194 | expected.add("b");
|
---|
195 | expected.add("r");
|
---|
196 |
|
---|
197 | List<String> result = fixture.getContextSuffix(context);
|
---|
198 |
|
---|
199 | ListAssert.assertEquals(expected, result);
|
---|
200 | }
|
---|
201 |
|
---|
202 | @Test
|
---|
203 | public void testGetContextSuffix_3() throws Exception {
|
---|
204 | Trie<String> fixture = new Trie<String>();
|
---|
205 | fixture.train(sequence, 3);
|
---|
206 | List<String> context = new ArrayList<String>();
|
---|
207 | context.add("a");
|
---|
208 | context.add("a");
|
---|
209 | context.add("b");
|
---|
210 | context.add("x");
|
---|
211 | List<String> expected = new ArrayList<String>();
|
---|
212 |
|
---|
213 | List<String> result = fixture.getContextSuffix(context);
|
---|
214 |
|
---|
215 | ListAssert.assertEquals(expected, result);
|
---|
216 | }
|
---|
217 |
|
---|
218 | @Test
|
---|
219 | public void testGetContextSuffix_4() throws Exception {
|
---|
220 | Trie<String> fixture = new Trie<String>();
|
---|
221 |
|
---|
222 | List<String> result = fixture.getContextSuffix(null);
|
---|
223 |
|
---|
224 | // add additional test code here
|
---|
225 | assertNotNull(result);
|
---|
226 | assertEquals(0, result.size());
|
---|
227 | }
|
---|
228 |
|
---|
229 | @Test
|
---|
230 | public void testGetContextSuffix_5() throws Exception {
|
---|
231 | Trie<String> fixture = new Trie<String>();
|
---|
232 | fixture.train(sequence, 3);
|
---|
233 | List<String> context = new ArrayList<String>();
|
---|
234 | context.add("a");
|
---|
235 | context.add("a");
|
---|
236 | context.add("b");
|
---|
237 | List<String> expected = new ArrayList<String>();
|
---|
238 | expected.add("a");
|
---|
239 | expected.add("b");
|
---|
240 |
|
---|
241 | List<String> result = fixture.getContextSuffix(context);
|
---|
242 |
|
---|
243 | ListAssert.assertEquals(expected, result);
|
---|
244 | }
|
---|
245 |
|
---|
246 | @Test
|
---|
247 | public void testGetCount_1() throws Exception {
|
---|
248 | Trie<String> fixture = new Trie<String>();
|
---|
249 | fixture.train(sequence, 3);
|
---|
250 | List<String> subSequence = new ArrayList<String>();
|
---|
251 | subSequence.add("a");
|
---|
252 |
|
---|
253 | int result = fixture.getCount(subSequence);
|
---|
254 |
|
---|
255 | assertEquals(5, result);
|
---|
256 | }
|
---|
257 |
|
---|
258 | @Test
|
---|
259 | public void testGetCount_2() throws Exception {
|
---|
260 | Trie<String> fixture = new Trie<String>();
|
---|
261 | fixture.train(sequence, 3);
|
---|
262 | List<String> subSequence = new ArrayList<String>();
|
---|
263 | subSequence.add("a");
|
---|
264 | subSequence.add("b");
|
---|
265 |
|
---|
266 | int result = fixture.getCount(subSequence);
|
---|
267 |
|
---|
268 | assertEquals(2, result);
|
---|
269 | }
|
---|
270 |
|
---|
271 | @Test
|
---|
272 | public void testGetCount_3() throws Exception {
|
---|
273 | Trie<String> fixture = new Trie<String>();
|
---|
274 | fixture.train(sequence, 3);
|
---|
275 | List<String> subSequence = new ArrayList<String>();
|
---|
276 | subSequence.add("x");
|
---|
277 |
|
---|
278 | int result = fixture.getCount(subSequence);
|
---|
279 |
|
---|
280 | assertEquals(0, result);
|
---|
281 | }
|
---|
282 |
|
---|
283 | @Test
|
---|
284 | public void testGetCount_4() throws Exception {
|
---|
285 | Trie<String> fixture = new Trie<String>();
|
---|
286 | fixture.train(sequence, 3);
|
---|
287 | List<String> subSequence = new ArrayList<String>();
|
---|
288 |
|
---|
289 | int result = fixture.getCount(subSequence, "a");
|
---|
290 |
|
---|
291 | assertEquals(5, result);
|
---|
292 | }
|
---|
293 |
|
---|
294 | @Test
|
---|
295 | public void testGetCount_5() throws Exception {
|
---|
296 | Trie<String> fixture = new Trie<String>();
|
---|
297 | fixture.train(sequence, 3);
|
---|
298 | List<String> subSequence = new ArrayList<String>();
|
---|
299 | subSequence.add("a");
|
---|
300 | subSequence.add("b");
|
---|
301 |
|
---|
302 | int result = fixture.getCount(subSequence, "r");
|
---|
303 |
|
---|
304 | assertEquals(2, result);
|
---|
305 | }
|
---|
306 |
|
---|
307 | @Test
|
---|
308 | public void testGetCount_6() throws Exception {
|
---|
309 | Trie<String> fixture = new Trie<String>();
|
---|
310 | fixture.train(sequence, 3);
|
---|
311 | List<String> subSequence = new ArrayList<String>();
|
---|
312 |
|
---|
313 | int result = fixture.getCount(subSequence, "x");
|
---|
314 |
|
---|
315 | assertEquals(0, result);
|
---|
316 | }
|
---|
317 |
|
---|
318 | @Test
|
---|
319 | public void testGetFollowingSymbols_1() throws Exception {
|
---|
320 | Trie<String> fixture = new Trie<String>();
|
---|
321 | fixture.train(sequence, 3);
|
---|
322 | List<String> subSequence = new ArrayList<String>();
|
---|
323 | subSequence.add("a");
|
---|
324 | Collection<String> expected = new ArrayList<String>();
|
---|
325 | expected.add("b");
|
---|
326 | expected.add("c");
|
---|
327 | expected.add("d");
|
---|
328 |
|
---|
329 | Collection<String> result = fixture.getFollowingSymbols(subSequence);
|
---|
330 |
|
---|
331 | assertCollectionContent(expected, result);
|
---|
332 | }
|
---|
333 |
|
---|
334 | @Test
|
---|
335 | public void testGetFollowingSymbols_2() throws Exception {
|
---|
336 | Trie<String> fixture = new Trie<String>();
|
---|
337 | fixture.train(sequence, 3);
|
---|
338 | List<String> subSequence = new ArrayList<String>();
|
---|
339 | subSequence.add("a");
|
---|
340 | subSequence.add("b");
|
---|
341 | subSequence.add("r");
|
---|
342 |
|
---|
343 | Collection<String> result = fixture.getFollowingSymbols(subSequence);
|
---|
344 |
|
---|
345 | assertEquals(0, result.size());
|
---|
346 | }
|
---|
347 |
|
---|
348 | @Test
|
---|
349 | public void testGetFollowingSymbols_3() throws Exception {
|
---|
350 | Trie<String> fixture = new Trie<String>();
|
---|
351 | fixture.train(sequence, 3);
|
---|
352 | List<String> subSequence = new ArrayList<String>();
|
---|
353 | subSequence.add("x");
|
---|
354 |
|
---|
355 | Collection<String> result = fixture.getFollowingSymbols(subSequence);
|
---|
356 |
|
---|
357 | assertEquals(0, result.size());
|
---|
358 | }
|
---|
359 |
|
---|
360 | @Test
|
---|
361 | public void testGetNumLeafAncestors_1() throws Exception {
|
---|
362 | Trie<String> fixture = new Trie<String>();
|
---|
363 | fixture.train(sequence, 3);
|
---|
364 |
|
---|
365 | int result = fixture.getNumLeafAncestors();
|
---|
366 |
|
---|
367 | assertEquals(7, result);
|
---|
368 | }
|
---|
369 |
|
---|
370 | @Test
|
---|
371 | public void testGetNumLeafs_1() throws Exception {
|
---|
372 | Trie<String> fixture = new Trie<String>();
|
---|
373 | fixture.train(sequence, 3);
|
---|
374 |
|
---|
375 | int result = fixture.getNumLeafs();
|
---|
376 |
|
---|
377 | assertEquals(7, result);
|
---|
378 | }
|
---|
379 |
|
---|
380 | @Test
|
---|
381 | public void testGetNumSymbols_1() throws Exception {
|
---|
382 | Trie<String> fixture = new Trie<String>();
|
---|
383 | fixture.train(sequence, 3);
|
---|
384 |
|
---|
385 | int result = fixture.getNumSymbols();
|
---|
386 |
|
---|
387 | assertEquals(5, result);
|
---|
388 | }
|
---|
389 |
|
---|
390 | @Test
|
---|
391 | public void testTrain_1() throws Exception {
|
---|
392 | Trie<String> fixture = new Trie<String>();
|
---|
393 | int maxOrder = 3;
|
---|
394 |
|
---|
395 | fixture.train(sequence, maxOrder);
|
---|
396 |
|
---|
397 | // check if symbols are correct
|
---|
398 | assertCollectionContent(symbols, fixture.getKnownSymbols());
|
---|
399 |
|
---|
400 | // check if counters are correct and only the correct nodes exist
|
---|
401 | TrieNode<String> root = fixture.find(new ArrayList<String>());
|
---|
402 | TrieNode<String> root_a = root.getChild("a");
|
---|
403 | TrieNode<String> root_a_a = root_a.getChild("a");
|
---|
404 | TrieNode<String> root_a_b = root_a.getChild("b");
|
---|
405 | TrieNode<String> root_a_b_a = root_a_b.getChild("a");
|
---|
406 | TrieNode<String> root_a_b_b = root_a_b.getChild("b");
|
---|
407 | TrieNode<String> root_a_b_c = root_a_b.getChild("c");
|
---|
408 | TrieNode<String> root_a_b_d = root_a_b.getChild("d");
|
---|
409 | TrieNode<String> root_a_b_r = root_a_b.getChild("r");
|
---|
410 | TrieNode<String> root_a_c = root_a.getChild("c");
|
---|
411 | TrieNode<String> root_a_c_a = root_a_c.getChild("a");
|
---|
412 | TrieNode<String> root_a_c_b = root_a_c.getChild("b");
|
---|
413 | TrieNode<String> root_a_c_c = root_a_c.getChild("c");
|
---|
414 | TrieNode<String> root_a_c_d = root_a_c.getChild("d");
|
---|
415 | TrieNode<String> root_a_c_r = root_a_c.getChild("r");
|
---|
416 | TrieNode<String> root_a_d = root_a.getChild("d");
|
---|
417 | TrieNode<String> root_a_d_a = root_a_d.getChild("a");
|
---|
418 | TrieNode<String> root_a_d_b = root_a_d.getChild("b");
|
---|
419 | TrieNode<String> root_a_d_c = root_a_d.getChild("c");
|
---|
420 | TrieNode<String> root_a_d_d = root_a_d.getChild("d");
|
---|
421 | TrieNode<String> root_a_d_r = root_a_d.getChild("r");
|
---|
422 | TrieNode<String> root_a_r = root_a.getChild("r");
|
---|
423 | TrieNode<String> root_b = root.getChild("b");
|
---|
424 | TrieNode<String> root_b_a = root_b.getChild("a");
|
---|
425 | TrieNode<String> root_b_b = root_b.getChild("b");
|
---|
426 | TrieNode<String> root_b_c = root_b.getChild("c");
|
---|
427 | TrieNode<String> root_b_d = root_b.getChild("d");
|
---|
428 | TrieNode<String> root_b_r = root_b.getChild("r");
|
---|
429 | TrieNode<String> root_b_r_a = root_b_r.getChild("a");
|
---|
430 | TrieNode<String> root_b_r_b = root_b_r.getChild("b");
|
---|
431 | TrieNode<String> root_b_r_c = root_b_r.getChild("c");
|
---|
432 | TrieNode<String> root_b_r_d = root_b_r.getChild("d");
|
---|
433 | TrieNode<String> root_b_r_r = root_b_r.getChild("r");
|
---|
434 | TrieNode<String> root_c = root.getChild("c");
|
---|
435 | TrieNode<String> root_c_a = root_c.getChild("a");
|
---|
436 | TrieNode<String> root_c_a_a = root_c_a.getChild("a");
|
---|
437 | TrieNode<String> root_c_a_b = root_c_a.getChild("b");
|
---|
438 | TrieNode<String> root_c_a_c = root_c_a.getChild("c");
|
---|
439 | TrieNode<String> root_c_a_d = root_c_a.getChild("d");
|
---|
440 | TrieNode<String> root_c_a_r = root_c_a.getChild("r");
|
---|
441 | TrieNode<String> root_c_b = root_c.getChild("b");
|
---|
442 | TrieNode<String> root_c_c = root_c.getChild("c");
|
---|
443 | TrieNode<String> root_c_d = root_c.getChild("d");
|
---|
444 | TrieNode<String> root_c_r = root_c.getChild("r");
|
---|
445 | TrieNode<String> root_d = root.getChild("d");
|
---|
446 | TrieNode<String> root_d_a = root_d.getChild("a");
|
---|
447 | TrieNode<String> root_d_a_a = root_d_a.getChild("a");
|
---|
448 | TrieNode<String> root_d_a_b = root_d_a.getChild("b");
|
---|
449 | TrieNode<String> root_d_a_c = root_d_a.getChild("c");
|
---|
450 | TrieNode<String> root_d_a_d = root_d_a.getChild("d");
|
---|
451 | TrieNode<String> root_d_a_r = root_d_a.getChild("r");
|
---|
452 | TrieNode<String> root_d_b = root_d.getChild("b");
|
---|
453 | TrieNode<String> root_d_c = root_d.getChild("c");
|
---|
454 | TrieNode<String> root_d_d = root_d.getChild("d");
|
---|
455 | TrieNode<String> root_d_r = root_d.getChild("r");
|
---|
456 | TrieNode<String> root_r = root.getChild("r");
|
---|
457 | TrieNode<String> root_r_a = root_r.getChild("a");
|
---|
458 | TrieNode<String> root_r_a_a = root_r_a.getChild("a");
|
---|
459 | TrieNode<String> root_r_a_b = root_r_a.getChild("b");
|
---|
460 | TrieNode<String> root_r_a_c = root_r_a.getChild("c");
|
---|
461 | TrieNode<String> root_r_a_d = root_r_a.getChild("d");
|
---|
462 | TrieNode<String> root_r_a_r = root_r_a.getChild("r");
|
---|
463 | TrieNode<String> root_r_b = root_r.getChild("b");
|
---|
464 | TrieNode<String> root_r_c = root_r.getChild("c");
|
---|
465 | TrieNode<String> root_r_d = root_r.getChild("d");
|
---|
466 | TrieNode<String> root_r_r = root_r.getChild("r");
|
---|
467 |
|
---|
468 | assertEquals(5, root_a.getCount());
|
---|
469 | assertNull(root_a_a);
|
---|
470 | assertEquals(2, root_a_b.getCount());
|
---|
471 | assertNull(root_a_b_a);
|
---|
472 | assertNull(root_a_b_b);
|
---|
473 | assertNull(root_a_b_c);
|
---|
474 | assertNull(root_a_b_d);
|
---|
475 | assertEquals(2, root_a_b_r.getCount());
|
---|
476 | assertEquals(1, root_a_c.getCount());
|
---|
477 | assertEquals(1, root_a_c_a.getCount());
|
---|
478 | assertNull(root_a_c_b);
|
---|
479 | assertNull(root_a_c_c);
|
---|
480 | assertNull(root_a_c_d);
|
---|
481 | assertNull(root_a_c_r);
|
---|
482 | assertEquals(1, root_a_d.getCount());
|
---|
483 | assertEquals(1, root_a_d_a.getCount());
|
---|
484 | assertNull(root_a_d_b);
|
---|
485 | assertNull(root_a_d_c);
|
---|
486 | assertNull(root_a_d_d);
|
---|
487 | assertNull(root_a_d_r);
|
---|
488 | assertNull(root_a_r);
|
---|
489 |
|
---|
490 | assertEquals(2, root_b.getCount());
|
---|
491 | assertNull(root_b_a);
|
---|
492 | assertNull(root_b_b);
|
---|
493 | assertNull(root_b_c);
|
---|
494 | assertNull(root_b_d);
|
---|
495 | assertEquals(2, root_b_r.getCount());
|
---|
496 | assertEquals(2, root_b_r_a.getCount());
|
---|
497 | assertNull(root_b_r_b);
|
---|
498 | assertNull(root_b_r_c);
|
---|
499 | assertNull(root_b_r_d);
|
---|
500 | assertNull(root_b_r_r);
|
---|
501 |
|
---|
502 | assertEquals(1, root_c.getCount());
|
---|
503 | assertEquals(1, root_c_a.getCount());
|
---|
504 | assertNull(root_c_a_a);
|
---|
505 | assertNull(root_c_a_b);
|
---|
506 | assertNull(root_c_a_c);
|
---|
507 | assertEquals(1, root_c_a_d.getCount());
|
---|
508 | assertNull(root_c_a_r);
|
---|
509 | assertNull(root_c_b);
|
---|
510 | assertNull(root_c_c);
|
---|
511 | assertNull(root_c_d);
|
---|
512 | assertNull(root_c_r);
|
---|
513 |
|
---|
514 | assertEquals(1, root_d.getCount());
|
---|
515 | assertEquals(1, root_d_a.getCount());
|
---|
516 | assertNull(root_d_a_a);
|
---|
517 | assertEquals(1, root_d_a_b.getCount());
|
---|
518 | assertNull(root_d_a_c);
|
---|
519 | assertNull(root_d_a_d);
|
---|
520 | assertNull(root_d_a_r);
|
---|
521 | assertNull(root_d_b);
|
---|
522 | assertNull(root_d_c);
|
---|
523 | assertNull(root_d_d);
|
---|
524 | assertNull(root_d_r);
|
---|
525 |
|
---|
526 | assertEquals(2, root_r.getCount());
|
---|
527 | assertEquals(2, root_r_a.getCount());
|
---|
528 | assertNull(root_r_a_a);
|
---|
529 | assertNull(root_r_a_b);
|
---|
530 | assertEquals(1, root_r_a_c.getCount());
|
---|
531 | assertNull(root_r_a_d);
|
---|
532 | assertNull(root_r_a_r);
|
---|
533 | assertNull(root_r_b);
|
---|
534 | assertNull(root_r_c);
|
---|
535 | assertNull(root_r_d);
|
---|
536 | assertNull(root_r_r);
|
---|
537 |
|
---|
538 | // check if leafs are really leafs
|
---|
539 | assertTrue(root_a_b_r.isLeaf());
|
---|
540 | assertTrue(root_a_c_a.isLeaf());
|
---|
541 | assertTrue(root_a_d_a.isLeaf());
|
---|
542 | assertTrue(root_b_r_a.isLeaf());
|
---|
543 | assertTrue(root_c_a_d.isLeaf());
|
---|
544 | assertTrue(root_d_a_b.isLeaf());
|
---|
545 | assertTrue(root_r_a_c.isLeaf());
|
---|
546 | }
|
---|
547 |
|
---|
548 | @Test
|
---|
549 | public void testTrain_2() throws Exception {
|
---|
550 | Trie<String> fixture = new Trie<String>();
|
---|
551 | int maxOrder = 0;
|
---|
552 |
|
---|
553 | fixture.train(sequence, maxOrder);
|
---|
554 |
|
---|
555 | assertTrue(fixture.getKnownSymbols().isEmpty());
|
---|
556 | }
|
---|
557 |
|
---|
558 | @Test
|
---|
559 | public void testTrain_3() throws Exception {
|
---|
560 | Trie<Object> fixture = new Trie<Object>();
|
---|
561 | List<Object> sequence = new ArrayList<Object>();
|
---|
562 | int maxOrder = 1;
|
---|
563 |
|
---|
564 | fixture.train(sequence, maxOrder);
|
---|
565 |
|
---|
566 | assertTrue(fixture.getKnownSymbols().isEmpty());
|
---|
567 | }
|
---|
568 |
|
---|
569 | @Test
|
---|
570 | public void testTrain_4() throws Exception {
|
---|
571 | Trie<String> fixture = new Trie<String>();
|
---|
572 | List<String> sequence = new ArrayList<String>();
|
---|
573 | sequence.add("a");
|
---|
574 | sequence.add("b");
|
---|
575 | int maxOrder = 3;
|
---|
576 |
|
---|
577 | fixture.train(sequence, maxOrder);
|
---|
578 |
|
---|
579 | assertCollectionContent(sequence, fixture.getKnownSymbols());
|
---|
580 | TrieNode<String> root = fixture.find(new ArrayList<String>());
|
---|
581 | TrieNode<String> root_a = root.getChild("a");
|
---|
582 | TrieNode<String> root_a_a = root_a.getChild("a");
|
---|
583 | TrieNode<String> root_a_b = root_a.getChild("b");
|
---|
584 | TrieNode<String> root_b = root.getChild("b");
|
---|
585 | TrieNode<String> root_b_a = root_b.getChild("a");
|
---|
586 | TrieNode<String> root_b_b = root_b.getChild("b");
|
---|
587 |
|
---|
588 | assertEquals(1, root_a.getCount());
|
---|
589 | assertNull(root_a_a);
|
---|
590 | assertEquals(1, root_a_b.getCount());
|
---|
591 | assertEquals(1, root_b.getCount());
|
---|
592 | assertNull(root_b_a);
|
---|
593 | assertNull(root_b_b);
|
---|
594 |
|
---|
595 | assertTrue(root_a_b.isLeaf());
|
---|
596 | assertTrue(root_b.isLeaf());
|
---|
597 | }
|
---|
598 |
|
---|
599 | @Test
|
---|
600 | public void testEdgeEdge_1() throws Exception {
|
---|
601 | Edge result = new Edge();
|
---|
602 |
|
---|
603 | assertNotNull(result);
|
---|
604 | }
|
---|
605 |
|
---|
606 | @Test
|
---|
607 | public void testTrieVertexTrieVertex_1() throws Exception {
|
---|
608 | String id = "idString";
|
---|
609 |
|
---|
610 | TrieVertex result = new TrieVertex(id);
|
---|
611 |
|
---|
612 | assertNotNull(result);
|
---|
613 | }
|
---|
614 |
|
---|
615 | @Test
|
---|
616 | public void testTrieVertexToString_1() throws Exception {
|
---|
617 | String id = "idString";
|
---|
618 | TrieVertex fixture = new TrieVertex(id);
|
---|
619 |
|
---|
620 | String result = fixture.toString();
|
---|
621 |
|
---|
622 | assertEquals(id, result);
|
---|
623 | }
|
---|
624 |
|
---|
625 | @Test
|
---|
626 | public void testEquals_1() throws Exception {
|
---|
627 | Trie<String> trieOther = new Trie<String>();
|
---|
628 | Trie<String> fixture = new Trie<String>();
|
---|
629 |
|
---|
630 | boolean result = fixture.equals(trieOther);
|
---|
631 |
|
---|
632 | assertEquals(true, result);
|
---|
633 | }
|
---|
634 |
|
---|
635 | @Test
|
---|
636 | public void testEquals_2() throws Exception {
|
---|
637 | Trie<String> trieOther = new Trie<String>();
|
---|
638 | trieOther.train(sequence, 2);
|
---|
639 | Trie<String> fixture = new Trie<String>();
|
---|
640 | fixture.train(sequence, 2);
|
---|
641 |
|
---|
642 | boolean result = fixture.equals(trieOther);
|
---|
643 |
|
---|
644 | assertEquals(true, result);
|
---|
645 | }
|
---|
646 |
|
---|
647 | @Test
|
---|
648 | public void testEquals_3() throws Exception {
|
---|
649 | Trie<String> trieOther = new Trie<String>();
|
---|
650 | trieOther.train(sequence, 2);
|
---|
651 | Trie<String> fixture = new Trie<String>();
|
---|
652 | fixture.train(sequence, 3);
|
---|
653 |
|
---|
654 | boolean result = fixture.equals(trieOther);
|
---|
655 |
|
---|
656 | assertEquals(false, result);
|
---|
657 | }
|
---|
658 |
|
---|
659 | @Test
|
---|
660 | public void testEquals_4() throws Exception {
|
---|
661 | Trie<String> trieOther = new Trie<String>();
|
---|
662 | Trie<String> fixture = new Trie<String>();
|
---|
663 | fixture.train(sequence, 2);
|
---|
664 |
|
---|
665 | boolean result = fixture.equals(trieOther);
|
---|
666 |
|
---|
667 | assertEquals(false, result);
|
---|
668 | }
|
---|
669 |
|
---|
670 | @Test
|
---|
671 | public void testEquals_5() throws Exception {
|
---|
672 | Trie<String> trieOther = new Trie<String>();
|
---|
673 | trieOther.train(sequence, 2);
|
---|
674 | Trie<String> fixture = new Trie<String>();
|
---|
675 |
|
---|
676 | boolean result = fixture.equals(trieOther);
|
---|
677 |
|
---|
678 | assertEquals(false, result);
|
---|
679 | }
|
---|
680 |
|
---|
681 | @Test
|
---|
682 | public void testEquals_6() throws Exception {
|
---|
683 | Trie<String> fixture = new Trie<String>();
|
---|
684 | fixture.train(sequence, 2);
|
---|
685 |
|
---|
686 | boolean result = fixture.equals(fixture);
|
---|
687 |
|
---|
688 | assertEquals(true, result);
|
---|
689 | }
|
---|
690 |
|
---|
691 | @Test
|
---|
692 | public void testEquals_7() throws Exception {
|
---|
693 | Trie<String> fixture = new Trie<String>();
|
---|
694 | fixture.train(sequence, 2);
|
---|
695 |
|
---|
696 | boolean result = fixture.equals(null);
|
---|
697 |
|
---|
698 | assertEquals(false, result);
|
---|
699 | }
|
---|
700 |
|
---|
701 | @Before
|
---|
702 | public void setUp() throws Exception {
|
---|
703 | sequence = new ArrayList<String>();
|
---|
704 | sequence.add("a");
|
---|
705 | sequence.add("b");
|
---|
706 | sequence.add("r");
|
---|
707 | sequence.add("a");
|
---|
708 | sequence.add("c");
|
---|
709 | sequence.add("a");
|
---|
710 | sequence.add("d");
|
---|
711 | sequence.add("a");
|
---|
712 | sequence.add("b");
|
---|
713 | sequence.add("r");
|
---|
714 | sequence.add("a");
|
---|
715 |
|
---|
716 | symbols = new HashSet<String>();
|
---|
717 | symbols.add("a");
|
---|
718 | symbols.add("b");
|
---|
719 | symbols.add("c");
|
---|
720 | symbols.add("d");
|
---|
721 | symbols.add("r");
|
---|
722 | }
|
---|
723 |
|
---|
724 | public static void main(String[] args) {
|
---|
725 | new org.junit.runner.JUnitCore().run(TrieTest.class);
|
---|
726 | }
|
---|
727 | } |
---|