1 | package de.ugoe.cs.eventbench.models;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.Collection;
|
---|
5 | import java.util.HashSet;
|
---|
6 | import java.util.List;
|
---|
7 | import java.util.Random;
|
---|
8 | import de.ugoe.cs.eventbench.data.Event;
|
---|
9 | import org.junit.*;
|
---|
10 | import static org.junit.Assert.*;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * The class <code>TrieBasedModelTest</code> contains tests for the class
|
---|
14 | * <code>{@link TrieBasedModel}</code>.
|
---|
15 | *
|
---|
16 | * @author Steffen Herbold
|
---|
17 | * @version 1.0
|
---|
18 | */
|
---|
19 | public class TrieBasedModelTest {
|
---|
20 |
|
---|
21 | List<Event<?>> sequence;
|
---|
22 | Collection<Event<?>> symbols;
|
---|
23 |
|
---|
24 | private void assertTrieStructure(Trie<Event<?>> trie, int numSequences) {
|
---|
25 | TrieNode<Event<?>> root = trie.find(null);
|
---|
26 | TrieNode<Event<?>> root_a = root.getChild(new Event<String>("a"));
|
---|
27 | TrieNode<Event<?>> root_a_a = root_a.getChild(new Event<String>("a"));
|
---|
28 | TrieNode<Event<?>> root_a_b = root_a.getChild(new Event<String>("b"));
|
---|
29 | TrieNode<Event<?>> root_a_b_a = root_a_b
|
---|
30 | .getChild(new Event<String>("a"));
|
---|
31 | TrieNode<Event<?>> root_a_b_b = root_a_b
|
---|
32 | .getChild(new Event<String>("b"));
|
---|
33 | TrieNode<Event<?>> root_a_b_c = root_a_b
|
---|
34 | .getChild(new Event<String>("c"));
|
---|
35 | TrieNode<Event<?>> root_a_b_d = root_a_b
|
---|
36 | .getChild(new Event<String>("d"));
|
---|
37 | TrieNode<Event<?>> root_a_b_r = root_a_b
|
---|
38 | .getChild(new Event<String>("r"));
|
---|
39 | TrieNode<Event<?>> root_a_c = root_a.getChild(new Event<String>("c"));
|
---|
40 | TrieNode<Event<?>> root_a_c_a = root_a_c
|
---|
41 | .getChild(new Event<String>("a"));
|
---|
42 | TrieNode<Event<?>> root_a_c_b = root_a_c
|
---|
43 | .getChild(new Event<String>("b"));
|
---|
44 | TrieNode<Event<?>> root_a_c_c = root_a_c
|
---|
45 | .getChild(new Event<String>("c"));
|
---|
46 | TrieNode<Event<?>> root_a_c_d = root_a_c
|
---|
47 | .getChild(new Event<String>("d"));
|
---|
48 | TrieNode<Event<?>> root_a_c_r = root_a_c
|
---|
49 | .getChild(new Event<String>("r"));
|
---|
50 | TrieNode<Event<?>> root_a_d = root_a.getChild(new Event<String>("d"));
|
---|
51 | TrieNode<Event<?>> root_a_d_a = root_a_d
|
---|
52 | .getChild(new Event<String>("a"));
|
---|
53 | TrieNode<Event<?>> root_a_d_b = root_a_d
|
---|
54 | .getChild(new Event<String>("b"));
|
---|
55 | TrieNode<Event<?>> root_a_d_c = root_a_d
|
---|
56 | .getChild(new Event<String>("c"));
|
---|
57 | TrieNode<Event<?>> root_a_d_d = root_a_d
|
---|
58 | .getChild(new Event<String>("d"));
|
---|
59 | TrieNode<Event<?>> root_a_d_r = root_a_d
|
---|
60 | .getChild(new Event<String>("r"));
|
---|
61 | TrieNode<Event<?>> root_a_r = root_a.getChild(new Event<String>("r"));
|
---|
62 | TrieNode<Event<?>> root_b = root.getChild(new Event<String>("b"));
|
---|
63 | TrieNode<Event<?>> root_b_a = root_b.getChild(new Event<String>("a"));
|
---|
64 | TrieNode<Event<?>> root_b_b = root_b.getChild(new Event<String>("b"));
|
---|
65 | TrieNode<Event<?>> root_b_c = root_b.getChild(new Event<String>("c"));
|
---|
66 | TrieNode<Event<?>> root_b_d = root_b.getChild(new Event<String>("d"));
|
---|
67 | TrieNode<Event<?>> root_b_r = root_b.getChild(new Event<String>("r"));
|
---|
68 | TrieNode<Event<?>> root_b_r_a = root_b_r
|
---|
69 | .getChild(new Event<String>("a"));
|
---|
70 | TrieNode<Event<?>> root_b_r_b = root_b_r
|
---|
71 | .getChild(new Event<String>("b"));
|
---|
72 | TrieNode<Event<?>> root_b_r_c = root_b_r
|
---|
73 | .getChild(new Event<String>("c"));
|
---|
74 | TrieNode<Event<?>> root_b_r_d = root_b_r
|
---|
75 | .getChild(new Event<String>("d"));
|
---|
76 | TrieNode<Event<?>> root_b_r_r = root_b_r
|
---|
77 | .getChild(new Event<String>("r"));
|
---|
78 | TrieNode<Event<?>> root_c = root.getChild(new Event<String>("c"));
|
---|
79 | TrieNode<Event<?>> root_c_a = root_c.getChild(new Event<String>("a"));
|
---|
80 | TrieNode<Event<?>> root_c_a_a = root_c_a
|
---|
81 | .getChild(new Event<String>("a"));
|
---|
82 | TrieNode<Event<?>> root_c_a_b = root_c_a
|
---|
83 | .getChild(new Event<String>("b"));
|
---|
84 | TrieNode<Event<?>> root_c_a_c = root_c_a
|
---|
85 | .getChild(new Event<String>("c"));
|
---|
86 | TrieNode<Event<?>> root_c_a_d = root_c_a
|
---|
87 | .getChild(new Event<String>("d"));
|
---|
88 | TrieNode<Event<?>> root_c_a_r = root_c_a
|
---|
89 | .getChild(new Event<String>("r"));
|
---|
90 | TrieNode<Event<?>> root_c_b = root_c.getChild(new Event<String>("b"));
|
---|
91 | TrieNode<Event<?>> root_c_c = root_c.getChild(new Event<String>("c"));
|
---|
92 | TrieNode<Event<?>> root_c_d = root_c.getChild(new Event<String>("d"));
|
---|
93 | TrieNode<Event<?>> root_c_r = root_c.getChild(new Event<String>("r"));
|
---|
94 | TrieNode<Event<?>> root_d = root.getChild(new Event<String>("d"));
|
---|
95 | TrieNode<Event<?>> root_d_a = root_d.getChild(new Event<String>("a"));
|
---|
96 | TrieNode<Event<?>> root_d_a_a = root_d_a
|
---|
97 | .getChild(new Event<String>("a"));
|
---|
98 | TrieNode<Event<?>> root_d_a_b = root_d_a
|
---|
99 | .getChild(new Event<String>("b"));
|
---|
100 | TrieNode<Event<?>> root_d_a_c = root_d_a
|
---|
101 | .getChild(new Event<String>("c"));
|
---|
102 | TrieNode<Event<?>> root_d_a_d = root_d_a
|
---|
103 | .getChild(new Event<String>("d"));
|
---|
104 | TrieNode<Event<?>> root_d_a_r = root_d_a
|
---|
105 | .getChild(new Event<String>("r"));
|
---|
106 | TrieNode<Event<?>> root_d_b = root_d.getChild(new Event<String>("b"));
|
---|
107 | TrieNode<Event<?>> root_d_c = root_d.getChild(new Event<String>("c"));
|
---|
108 | TrieNode<Event<?>> root_d_d = root_d.getChild(new Event<String>("d"));
|
---|
109 | TrieNode<Event<?>> root_d_r = root_d.getChild(new Event<String>("r"));
|
---|
110 | TrieNode<Event<?>> root_r = root.getChild(new Event<String>("r"));
|
---|
111 | TrieNode<Event<?>> root_r_a = root_r.getChild(new Event<String>("a"));
|
---|
112 | TrieNode<Event<?>> root_r_a_a = root_r_a
|
---|
113 | .getChild(new Event<String>("a"));
|
---|
114 | TrieNode<Event<?>> root_r_a_b = root_r_a
|
---|
115 | .getChild(new Event<String>("b"));
|
---|
116 | TrieNode<Event<?>> root_r_a_c = root_r_a
|
---|
117 | .getChild(new Event<String>("c"));
|
---|
118 | TrieNode<Event<?>> root_r_a_d = root_r_a
|
---|
119 | .getChild(new Event<String>("d"));
|
---|
120 | TrieNode<Event<?>> root_r_a_r = root_r_a
|
---|
121 | .getChild(new Event<String>("r"));
|
---|
122 | TrieNode<Event<?>> root_r_a_end = root_r_a.getChild(Event.ENDEVENT);
|
---|
123 | TrieNode<Event<?>> root_r_b = root_r.getChild(new Event<String>("b"));
|
---|
124 | TrieNode<Event<?>> root_r_c = root_r.getChild(new Event<String>("c"));
|
---|
125 | TrieNode<Event<?>> root_r_d = root_r.getChild(new Event<String>("d"));
|
---|
126 | TrieNode<Event<?>> root_r_r = root_r.getChild(new Event<String>("r"));
|
---|
127 | TrieNode<Event<?>> root_start = root.getChild(Event.STARTEVENT);
|
---|
128 | TrieNode<Event<?>> root_start_a = root_start
|
---|
129 | .getChild(new Event<String>("a"));
|
---|
130 | TrieNode<Event<?>> root_start_a_a = root_start_a
|
---|
131 | .getChild(new Event<String>("a"));
|
---|
132 | TrieNode<Event<?>> root_start_a_b = root_start_a
|
---|
133 | .getChild(new Event<String>("b"));
|
---|
134 | TrieNode<Event<?>> root_start_a_c = root_start_a
|
---|
135 | .getChild(new Event<String>("c"));
|
---|
136 | TrieNode<Event<?>> root_start_a_d = root_start_a
|
---|
137 | .getChild(new Event<String>("d"));
|
---|
138 | TrieNode<Event<?>> root_start_a_r = root_start_a
|
---|
139 | .getChild(new Event<String>("r"));
|
---|
140 | TrieNode<Event<?>> root_start_b = root_start
|
---|
141 | .getChild(new Event<String>("b"));
|
---|
142 | TrieNode<Event<?>> root_start_c = root_start
|
---|
143 | .getChild(new Event<String>("c"));
|
---|
144 | TrieNode<Event<?>> root_start_d = root_start
|
---|
145 | .getChild(new Event<String>("d"));
|
---|
146 | TrieNode<Event<?>> root_start_r = root_start
|
---|
147 | .getChild(new Event<String>("r"));
|
---|
148 |
|
---|
149 | assertEquals(numSequences * 5, root_a.getCount());
|
---|
150 | assertNull(root_a_a);
|
---|
151 | assertEquals(numSequences * 2, root_a_b.getCount());
|
---|
152 | assertNull(root_a_b_a);
|
---|
153 | assertNull(root_a_b_b);
|
---|
154 | assertNull(root_a_b_c);
|
---|
155 | assertNull(root_a_b_d);
|
---|
156 | assertEquals(numSequences * 2, root_a_b_r.getCount());
|
---|
157 | assertEquals(numSequences * 1, root_a_c.getCount());
|
---|
158 | assertEquals(numSequences * 1, root_a_c_a.getCount());
|
---|
159 | assertNull(root_a_c_b);
|
---|
160 | assertNull(root_a_c_c);
|
---|
161 | assertNull(root_a_c_d);
|
---|
162 | assertNull(root_a_c_r);
|
---|
163 | assertEquals(numSequences * 1, root_a_d.getCount());
|
---|
164 | assertEquals(numSequences * 1, root_a_d_a.getCount());
|
---|
165 | assertNull(root_a_d_b);
|
---|
166 | assertNull(root_a_d_c);
|
---|
167 | assertNull(root_a_d_d);
|
---|
168 | assertNull(root_a_d_r);
|
---|
169 | assertNull(root_a_r);
|
---|
170 |
|
---|
171 | assertEquals(numSequences * 2, root_b.getCount());
|
---|
172 | assertNull(root_b_a);
|
---|
173 | assertNull(root_b_b);
|
---|
174 | assertNull(root_b_c);
|
---|
175 | assertNull(root_b_d);
|
---|
176 | assertEquals(numSequences * 2, root_b_r.getCount());
|
---|
177 | assertEquals(numSequences * 2, root_b_r_a.getCount());
|
---|
178 | assertNull(root_b_r_b);
|
---|
179 | assertNull(root_b_r_c);
|
---|
180 | assertNull(root_b_r_d);
|
---|
181 | assertNull(root_b_r_r);
|
---|
182 |
|
---|
183 | assertEquals(numSequences * 1, root_c.getCount());
|
---|
184 | assertEquals(numSequences * 1, root_c_a.getCount());
|
---|
185 | assertNull(root_c_a_a);
|
---|
186 | assertNull(root_c_a_b);
|
---|
187 | assertNull(root_c_a_c);
|
---|
188 | assertEquals(numSequences * 1, root_c_a_d.getCount());
|
---|
189 | assertNull(root_c_a_r);
|
---|
190 | assertNull(root_c_b);
|
---|
191 | assertNull(root_c_c);
|
---|
192 | assertNull(root_c_d);
|
---|
193 | assertNull(root_c_r);
|
---|
194 |
|
---|
195 | assertEquals(numSequences * 1, root_d.getCount());
|
---|
196 | assertEquals(numSequences * 1, root_d_a.getCount());
|
---|
197 | assertNull(root_d_a_a);
|
---|
198 | assertEquals(numSequences * 1, root_d_a_b.getCount());
|
---|
199 | assertNull(root_d_a_c);
|
---|
200 | assertNull(root_d_a_d);
|
---|
201 | assertNull(root_d_a_r);
|
---|
202 | assertNull(root_d_b);
|
---|
203 | assertNull(root_d_c);
|
---|
204 | assertNull(root_d_d);
|
---|
205 | assertNull(root_d_r);
|
---|
206 |
|
---|
207 | assertEquals(numSequences * 2, root_r.getCount());
|
---|
208 | assertEquals(numSequences * 2, root_r_a.getCount());
|
---|
209 | assertNull(root_r_a_a);
|
---|
210 | assertNull(root_r_a_b);
|
---|
211 | assertEquals(numSequences * 1, root_r_a_c.getCount());
|
---|
212 | assertNull(root_r_a_d);
|
---|
213 | assertNull(root_r_a_r);
|
---|
214 | assertEquals(numSequences * 1, root_r_a_end.getCount());
|
---|
215 | assertNull(root_r_b);
|
---|
216 | assertNull(root_r_c);
|
---|
217 | assertNull(root_r_d);
|
---|
218 | assertNull(root_r_r);
|
---|
219 |
|
---|
220 | assertEquals(numSequences * 1, root_start.getCount());
|
---|
221 | assertEquals(numSequences * 1, root_start_a.getCount());
|
---|
222 | assertNull(root_start_a_a);
|
---|
223 | assertEquals(numSequences * 1, root_start_a_b.getCount());
|
---|
224 | assertNull(root_start_a_c);
|
---|
225 | assertNull(root_start_a_d);
|
---|
226 | assertNull(root_start_a_r);
|
---|
227 | assertNull(root_start_b);
|
---|
228 | assertNull(root_start_c);
|
---|
229 | assertNull(root_start_d);
|
---|
230 | assertNull(root_start_r);
|
---|
231 |
|
---|
232 | // check if leafs are really leafs
|
---|
233 | assertTrue(root_a_b_r.isLeaf());
|
---|
234 | assertTrue(root_a_c_a.isLeaf());
|
---|
235 | assertTrue(root_a_d_a.isLeaf());
|
---|
236 | assertTrue(root_b_r_a.isLeaf());
|
---|
237 | assertTrue(root_c_a_d.isLeaf());
|
---|
238 | assertTrue(root_d_a_b.isLeaf());
|
---|
239 | assertTrue(root_r_a_c.isLeaf());
|
---|
240 | assertTrue(root_r_a_end.isLeaf());
|
---|
241 | }
|
---|
242 |
|
---|
243 | private static void assertCollectionContent(Collection<?> c1,
|
---|
244 | Collection<?> c2) {
|
---|
245 | assertEquals(c1.size(), c2.size());
|
---|
246 | for (Object obj : c1) {
|
---|
247 | assertTrue(c2.contains(obj));
|
---|
248 | }
|
---|
249 | }
|
---|
250 |
|
---|
251 | @Test
|
---|
252 | public void testTrieBasedModel_1() throws Exception {
|
---|
253 | int markovOrder = 2;
|
---|
254 | Random r = new Random();
|
---|
255 |
|
---|
256 | MockTrieBasedModel result = new MockTrieBasedModel(markovOrder, r);
|
---|
257 |
|
---|
258 | assertNotNull(result);
|
---|
259 | assertEquals(markovOrder + 1, result.trieOrder);
|
---|
260 | assertEquals(r, result.r);
|
---|
261 | }
|
---|
262 |
|
---|
263 | @Test(expected = java.security.InvalidParameterException.class)
|
---|
264 | public void testTrieBasedModel_2() throws Exception {
|
---|
265 | int markovOrder = -1;
|
---|
266 | Random r = new Random();
|
---|
267 |
|
---|
268 | new MockTrieBasedModel(markovOrder, r);
|
---|
269 | }
|
---|
270 |
|
---|
271 | @Test(expected = java.security.InvalidParameterException.class)
|
---|
272 | public void testTrieBasedModel_3() throws Exception {
|
---|
273 | int markovOrder = 2;
|
---|
274 | Random r = null;
|
---|
275 |
|
---|
276 | new MockTrieBasedModel(markovOrder, r);
|
---|
277 | }
|
---|
278 |
|
---|
279 | @Test
|
---|
280 | public void testGenerateSequences_1() throws Exception {
|
---|
281 | int markovOrder = 2;
|
---|
282 | MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder,
|
---|
283 | new Random());
|
---|
284 | Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>();
|
---|
285 | sequences.add(sequence);
|
---|
286 | fixture.train(sequences);
|
---|
287 | int length = 2;
|
---|
288 |
|
---|
289 | Collection<List<Event<?>>> expected = new HashSet<List<Event<?>>>();
|
---|
290 | ArrayList<Event<?>> list;
|
---|
291 | list = new ArrayList<Event<?>>();
|
---|
292 | list.add(new Event<String>("a"));
|
---|
293 | list.add(Event.ENDEVENT);
|
---|
294 | expected.add(list);
|
---|
295 | list = new ArrayList<Event<?>>();
|
---|
296 | list.add(new Event<String>("a"));
|
---|
297 | list.add(new Event<String>("b"));
|
---|
298 | expected.add(list);
|
---|
299 | list = new ArrayList<Event<?>>();
|
---|
300 | list.add(new Event<String>("a"));
|
---|
301 | list.add(new Event<String>("c"));
|
---|
302 | expected.add(list);
|
---|
303 | list = new ArrayList<Event<?>>();
|
---|
304 | list.add(new Event<String>("a"));
|
---|
305 | list.add(new Event<String>("d"));
|
---|
306 | expected.add(list);
|
---|
307 | list = new ArrayList<Event<?>>();
|
---|
308 | list.add(new Event<String>("b"));
|
---|
309 | list.add(new Event<String>("r"));
|
---|
310 | expected.add(list);
|
---|
311 | list = new ArrayList<Event<?>>();
|
---|
312 | list.add(new Event<String>("c"));
|
---|
313 | list.add(new Event<String>("a"));
|
---|
314 | expected.add(list);
|
---|
315 | list = new ArrayList<Event<?>>();
|
---|
316 | list.add(new Event<String>("d"));
|
---|
317 | list.add(new Event<String>("a"));
|
---|
318 | expected.add(list);
|
---|
319 | list = new ArrayList<Event<?>>();
|
---|
320 | list.add(new Event<String>("r"));
|
---|
321 | list.add(new Event<String>("a"));
|
---|
322 | expected.add(list);
|
---|
323 | list = new ArrayList<Event<?>>();
|
---|
324 | list.add(Event.STARTEVENT);
|
---|
325 | list.add(new Event<String>("a"));
|
---|
326 | expected.add(list);
|
---|
327 |
|
---|
328 | Collection<List<? extends Event<?>>> result = fixture
|
---|
329 | .generateSequences(length);
|
---|
330 |
|
---|
331 | assertCollectionContent(expected, result);
|
---|
332 | }
|
---|
333 |
|
---|
334 | @Test
|
---|
335 | public void testGenerateSequences_2() throws Exception {
|
---|
336 | int markovOrder = 2;
|
---|
337 | MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder,
|
---|
338 | new Random());
|
---|
339 | Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>();
|
---|
340 | sequences.add(sequence);
|
---|
341 | fixture.train(sequences);
|
---|
342 | int length = 3;
|
---|
343 |
|
---|
344 | Collection<List<Event<?>>> expected = new HashSet<List<Event<?>>>();
|
---|
345 | ArrayList<Event<?>> list;
|
---|
346 | list = new ArrayList<Event<?>>();
|
---|
347 | list.add(Event.STARTEVENT);
|
---|
348 | list.add(new Event<String>("a"));
|
---|
349 | list.add(Event.ENDEVENT);
|
---|
350 | expected.add(list);
|
---|
351 | list = new ArrayList<Event<?>>();
|
---|
352 | list.add(Event.STARTEVENT);
|
---|
353 | list.add(new Event<String>("a"));
|
---|
354 | list.add(new Event<String>("b"));
|
---|
355 | expected.add(list);
|
---|
356 | list = new ArrayList<Event<?>>();
|
---|
357 | list.add(Event.STARTEVENT);
|
---|
358 | list.add(new Event<String>("a"));
|
---|
359 | list.add(new Event<String>("c"));
|
---|
360 | expected.add(list);
|
---|
361 | list = new ArrayList<Event<?>>();
|
---|
362 | list.add(Event.STARTEVENT);
|
---|
363 | list.add(new Event<String>("a"));
|
---|
364 | list.add(new Event<String>("d"));
|
---|
365 | expected.add(list);
|
---|
366 |
|
---|
367 | Collection<List<? extends Event<?>>> result = fixture
|
---|
368 | .generateSequences(length, true);
|
---|
369 |
|
---|
370 | assertCollectionContent(expected, result);
|
---|
371 | }
|
---|
372 |
|
---|
373 | @Test(expected = java.security.InvalidParameterException.class)
|
---|
374 | public void testGenerateSequences_3() throws Exception {
|
---|
375 | int markovOrder = 2;
|
---|
376 | MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder,
|
---|
377 | new Random());
|
---|
378 | Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>();
|
---|
379 | sequences.add(sequence);
|
---|
380 | fixture.train(sequences);
|
---|
381 | int length = 0;
|
---|
382 |
|
---|
383 | fixture.generateSequences(length, false);
|
---|
384 | }
|
---|
385 |
|
---|
386 | @Test
|
---|
387 | public void testGenerateValidSequences_1() throws Exception {
|
---|
388 | int markovOrder = 2;
|
---|
389 | MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder,
|
---|
390 | new Random());
|
---|
391 | Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>();
|
---|
392 | sequences.add(sequence);
|
---|
393 | fixture.train(sequences);
|
---|
394 | int length = 5;
|
---|
395 |
|
---|
396 | Collection<List<Event<?>>> expected = new HashSet<List<Event<?>>>();
|
---|
397 | ArrayList<Event<?>> list;
|
---|
398 | list = new ArrayList<Event<?>>();
|
---|
399 | list.add(Event.STARTEVENT);
|
---|
400 | list.add(new Event<String>("a"));
|
---|
401 | list.add(new Event<String>("c"));
|
---|
402 | list.add(new Event<String>("a"));
|
---|
403 | list.add(Event.ENDEVENT);
|
---|
404 | expected.add(list);
|
---|
405 | list = new ArrayList<Event<?>>();
|
---|
406 | list.add(Event.STARTEVENT);
|
---|
407 | list.add(new Event<String>("a"));
|
---|
408 | list.add(new Event<String>("d"));
|
---|
409 | list.add(new Event<String>("a"));
|
---|
410 | list.add(Event.ENDEVENT);
|
---|
411 | expected.add(list);
|
---|
412 |
|
---|
413 | Collection<List<? extends Event<?>>> result = fixture
|
---|
414 | .generateValidSequences(length);
|
---|
415 |
|
---|
416 | assertCollectionContent(expected, result);
|
---|
417 | }
|
---|
418 |
|
---|
419 | @Test(expected = java.security.InvalidParameterException.class)
|
---|
420 | public void testGenerateValidSequences_2() throws Exception {
|
---|
421 | int markovOrder = 2;
|
---|
422 | MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder,
|
---|
423 | new Random());
|
---|
424 | Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>();
|
---|
425 | sequences.add(sequence);
|
---|
426 | fixture.train(sequences);
|
---|
427 | int length = 0;
|
---|
428 |
|
---|
429 | fixture.generateValidSequences(length);
|
---|
430 | }
|
---|
431 |
|
---|
432 | @Test
|
---|
433 | public void testGetEvents_1() throws Exception {
|
---|
434 | int markovOrder = 2;
|
---|
435 | MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder,
|
---|
436 | new Random());
|
---|
437 | Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>();
|
---|
438 | sequences.add(sequence);
|
---|
439 |
|
---|
440 | fixture.train(sequences);
|
---|
441 |
|
---|
442 | Collection<? extends Event<?>> result = fixture.getEvents();
|
---|
443 |
|
---|
444 | assertCollectionContent(symbols, result);
|
---|
445 | }
|
---|
446 |
|
---|
447 | @Test
|
---|
448 | public void testGetEvents_2() throws Exception {
|
---|
449 | int markovOrder = 2;
|
---|
450 | MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder,
|
---|
451 | new Random());
|
---|
452 |
|
---|
453 | Collection<? extends Event<?>> result = fixture.getEvents();
|
---|
454 |
|
---|
455 | assertCollectionContent(new HashSet<Event<?>>(), result);
|
---|
456 | }
|
---|
457 |
|
---|
458 | @Test
|
---|
459 | public void testGetNumFOMStates_1() throws Exception {
|
---|
460 | int markovOrder = 2;
|
---|
461 | MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder,
|
---|
462 | new Random());
|
---|
463 | Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>();
|
---|
464 | sequences.add(sequence);
|
---|
465 |
|
---|
466 | fixture.train(sequences);
|
---|
467 |
|
---|
468 | int result = fixture.getNumFOMStates();
|
---|
469 |
|
---|
470 | assertEquals(10, result);
|
---|
471 | }
|
---|
472 |
|
---|
473 | @Test
|
---|
474 | public void testGetNumFOMStates_2() throws Exception {
|
---|
475 | int markovOrder = 2;
|
---|
476 | MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder,
|
---|
477 | new Random());
|
---|
478 | ;
|
---|
479 |
|
---|
480 | int result = fixture.getNumFOMStates();
|
---|
481 |
|
---|
482 | assertEquals(0, result);
|
---|
483 | }
|
---|
484 |
|
---|
485 | @Test
|
---|
486 | public void testGetNumSymbols_1() throws Exception {
|
---|
487 | int markovOrder = 2;
|
---|
488 | MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder,
|
---|
489 | new Random());
|
---|
490 | Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>();
|
---|
491 | sequences.add(sequence);
|
---|
492 | fixture.train(sequences);
|
---|
493 |
|
---|
494 | int result = fixture.getNumSymbols();
|
---|
495 |
|
---|
496 | assertEquals(7, result);
|
---|
497 | }
|
---|
498 |
|
---|
499 | @Test
|
---|
500 | public void testGetNumSymbols_2() throws Exception {
|
---|
501 | int markovOrder = 2;
|
---|
502 | MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder,
|
---|
503 | new Random());
|
---|
504 |
|
---|
505 | int result = fixture.getNumSymbols();
|
---|
506 |
|
---|
507 | assertEquals(0, result);
|
---|
508 | }
|
---|
509 |
|
---|
510 | @Test
|
---|
511 | public void testGetNumTransitions_1() throws Exception {
|
---|
512 | int markovOrder = 2;
|
---|
513 | MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder,
|
---|
514 | new Random());
|
---|
515 | Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>();
|
---|
516 | sequences.add(sequence);
|
---|
517 | fixture.train(sequences);
|
---|
518 |
|
---|
519 | int result = fixture.getNumTransitions();
|
---|
520 |
|
---|
521 | assertEquals(11, result);
|
---|
522 | }
|
---|
523 |
|
---|
524 | @Test
|
---|
525 | public void testGetNumTransitions_2() throws Exception {
|
---|
526 | int markovOrder = 2;
|
---|
527 | MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder,
|
---|
528 | new Random());
|
---|
529 |
|
---|
530 | int result = fixture.getNumTransitions();
|
---|
531 |
|
---|
532 | assertEquals(0, result);
|
---|
533 | }
|
---|
534 |
|
---|
535 | @Test
|
---|
536 | public void testTrain_1() throws Exception {
|
---|
537 | int markovOrder = 2;
|
---|
538 | MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder,
|
---|
539 | new Random());
|
---|
540 | Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>();
|
---|
541 | sequences.add(sequence);
|
---|
542 |
|
---|
543 | fixture.train(sequences);
|
---|
544 |
|
---|
545 | assertCollectionContent(symbols, fixture.getEvents());
|
---|
546 |
|
---|
547 | assertTrieStructure(fixture.trie, 1);
|
---|
548 | }
|
---|
549 |
|
---|
550 | @Test
|
---|
551 | public void testTrain_2() throws Exception {
|
---|
552 | int markovOrder = 2;
|
---|
553 | MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder,
|
---|
554 | new Random());
|
---|
555 | Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>();
|
---|
556 | sequences.add(sequence);
|
---|
557 | sequences.add(sequence);
|
---|
558 |
|
---|
559 | fixture.train(sequences);
|
---|
560 |
|
---|
561 | assertCollectionContent(symbols, fixture.getEvents());
|
---|
562 |
|
---|
563 | assertTrieStructure(fixture.trie, 2);
|
---|
564 | }
|
---|
565 |
|
---|
566 | @Test(expected = java.security.InvalidParameterException.class)
|
---|
567 | public void testTrain_3() throws Exception {
|
---|
568 | int markovOrder = 2;
|
---|
569 | MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder,
|
---|
570 | new Random());
|
---|
571 | Collection<List<? extends Event<?>>> sequences = null;
|
---|
572 |
|
---|
573 | fixture.train(sequences);
|
---|
574 | }
|
---|
575 |
|
---|
576 | @Test
|
---|
577 | public void testUpdate_1() throws Exception {
|
---|
578 | int markovOrder = 2;
|
---|
579 | MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder,
|
---|
580 | new Random());
|
---|
581 | Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>();
|
---|
582 | sequences.add(sequence);
|
---|
583 | fixture.train(sequences);
|
---|
584 |
|
---|
585 | fixture.update(sequences);
|
---|
586 |
|
---|
587 | assertCollectionContent(symbols, fixture.getEvents());
|
---|
588 | assertTrieStructure(fixture.trie, 2);
|
---|
589 | }
|
---|
590 |
|
---|
591 | @Test(expected = java.security.InvalidParameterException.class)
|
---|
592 | public void testUpdate_2() throws Exception {
|
---|
593 | int markovOrder = 2;
|
---|
594 | MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder,
|
---|
595 | new Random());
|
---|
596 | Collection<List<? extends Event<?>>> sequences = null;
|
---|
597 | fixture.trie = null;
|
---|
598 |
|
---|
599 | fixture.update(sequences);
|
---|
600 | }
|
---|
601 |
|
---|
602 | @Before
|
---|
603 | public void setUp() throws Exception {
|
---|
604 | sequence = new ArrayList<Event<?>>();
|
---|
605 | sequence.add(new Event<String>("a"));
|
---|
606 | sequence.add(new Event<String>("b"));
|
---|
607 | sequence.add(new Event<String>("r"));
|
---|
608 | sequence.add(new Event<String>("a"));
|
---|
609 | sequence.add(new Event<String>("c"));
|
---|
610 | sequence.add(new Event<String>("a"));
|
---|
611 | sequence.add(new Event<String>("d"));
|
---|
612 | sequence.add(new Event<String>("a"));
|
---|
613 | sequence.add(new Event<String>("b"));
|
---|
614 | sequence.add(new Event<String>("r"));
|
---|
615 | sequence.add(new Event<String>("a"));
|
---|
616 |
|
---|
617 | symbols = new HashSet<Event<?>>();
|
---|
618 | symbols.add(new Event<String>("a"));
|
---|
619 | symbols.add(new Event<String>("b"));
|
---|
620 | symbols.add(new Event<String>("c"));
|
---|
621 | symbols.add(new Event<String>("d"));
|
---|
622 | symbols.add(new Event<String>("r"));
|
---|
623 | symbols.add(Event.STARTEVENT);
|
---|
624 | symbols.add(Event.ENDEVENT);
|
---|
625 | }
|
---|
626 |
|
---|
627 | public static void main(String[] args) {
|
---|
628 | new org.junit.runner.JUnitCore().run(TrieBasedModelTest.class);
|
---|
629 | }
|
---|
630 | } |
---|