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