Changeset 343 for trunk/EventBenchCoreTest/src/de
- Timestamp:
- 12/21/11 16:55:26 (13 years ago)
- Location:
- trunk/EventBenchCoreTest/src/de/ugoe/cs/eventbench/models
- Files:
-
- 4 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/EventBenchCoreTest/src/de/ugoe/cs/eventbench/models/TestAll.java
r274 r343 10 10 * package. 11 11 * 12 * @generatedBy CodePro at 10/14/11 11:01 AM 13 * @author sherbold 14 * @version $Revision: 1.0 $ 12 * @author Steffen Herbold 13 * @version 1.0 15 14 */ 16 15 @RunWith(Suite.class) 17 16 @Suite.SuiteClasses({ 17 DeterministicFiniteAutomatonTest.class, 18 FirstOrderMarkovModelTest.class, 19 HighOrderMarkovModelTest.class, 20 IncompleteMemoryTest.class, 18 21 ModelFlattenerTest.class, 19 TrieBasedModelTest.class,20 IncompleteMemoryTest.class,22 PredictionByPartialMatchTest.class, 23 TrieBasedModelTest.class, 21 24 TrieTest.class 22 25 }) 23 26 public class TestAll { 24 27 25 /**26 * Launch the test.27 *28 * @param args the command line arguments29 *30 * @generatedBy CodePro at 10/14/11 11:01 AM31 */32 28 public static void main(String[] args) { 33 29 JUnitCore.runClasses(new Class[] { TestAll.class }); -
trunk/EventBenchCoreTest/src/de/ugoe/cs/eventbench/models/TrieBasedModelTest.java
r326 r343 11 11 12 12 /** 13 * The class <code>TrieBasedModelTest</code> contains tests for the class <code>{@link TrieBasedModel}</code>. 14 * 13 * The class <code>TrieBasedModelTest</code> contains tests for the class 14 * <code>{@link TrieBasedModel}</code>. 15 * 15 16 * @author Steffen Herbold 16 17 * @version 1.0 17 18 */ 18 19 public class TrieBasedModelTest { 19 20 20 21 List<Event<?>> sequence; 21 22 Collection<Event<?>> symbols; 22 23 23 24 private void assertTrieStructure(Trie<Event<?>> trie, int numSequences) { 24 25 TrieNode<Event<?>> root = trie.find(null); … … 26 27 TrieNode<Event<?>> root_a_a = root_a.getChild(new Event<String>("a")); 27 28 TrieNode<Event<?>> root_a_b = root_a.getChild(new Event<String>("b")); 28 TrieNode<Event<?>> root_a_b_a = root_a_b.getChild(new Event<String>("a")); 29 TrieNode<Event<?>> root_a_b_b = root_a_b.getChild(new Event<String>("b")); 30 TrieNode<Event<?>> root_a_b_c = root_a_b.getChild(new Event<String>("c")); 31 TrieNode<Event<?>> root_a_b_d = root_a_b.getChild(new Event<String>("d")); 32 TrieNode<Event<?>> root_a_b_r = root_a_b.getChild(new Event<String>("r")); 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")); 33 39 TrieNode<Event<?>> root_a_c = root_a.getChild(new Event<String>("c")); 34 TrieNode<Event<?>> root_a_c_a = root_a_c.getChild(new Event<String>("a")); 35 TrieNode<Event<?>> root_a_c_b = root_a_c.getChild(new Event<String>("b")); 36 TrieNode<Event<?>> root_a_c_c = root_a_c.getChild(new Event<String>("c")); 37 TrieNode<Event<?>> root_a_c_d = root_a_c.getChild(new Event<String>("d")); 38 TrieNode<Event<?>> root_a_c_r = root_a_c.getChild(new Event<String>("r")); 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")); 39 50 TrieNode<Event<?>> root_a_d = root_a.getChild(new Event<String>("d")); 40 TrieNode<Event<?>> root_a_d_a = root_a_d.getChild(new Event<String>("a")); 41 TrieNode<Event<?>> root_a_d_b = root_a_d.getChild(new Event<String>("b")); 42 TrieNode<Event<?>> root_a_d_c = root_a_d.getChild(new Event<String>("c")); 43 TrieNode<Event<?>> root_a_d_d = root_a_d.getChild(new Event<String>("d")); 44 TrieNode<Event<?>> root_a_d_r = root_a_d.getChild(new Event<String>("r")); 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")); 45 61 TrieNode<Event<?>> root_a_r = root_a.getChild(new Event<String>("r")); 46 62 TrieNode<Event<?>> root_b = root.getChild(new Event<String>("b")); … … 50 66 TrieNode<Event<?>> root_b_d = root_b.getChild(new Event<String>("d")); 51 67 TrieNode<Event<?>> root_b_r = root_b.getChild(new Event<String>("r")); 52 TrieNode<Event<?>> root_b_r_a = root_b_r.getChild(new Event<String>("a")); 53 TrieNode<Event<?>> root_b_r_b = root_b_r.getChild(new Event<String>("b")); 54 TrieNode<Event<?>> root_b_r_c = root_b_r.getChild(new Event<String>("c")); 55 TrieNode<Event<?>> root_b_r_d = root_b_r.getChild(new Event<String>("d")); 56 TrieNode<Event<?>> root_b_r_r = root_b_r.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")); 57 78 TrieNode<Event<?>> root_c = root.getChild(new Event<String>("c")); 58 79 TrieNode<Event<?>> root_c_a = root_c.getChild(new Event<String>("a")); 59 TrieNode<Event<?>> root_c_a_a = root_c_a.getChild(new Event<String>("a")); 60 TrieNode<Event<?>> root_c_a_b = root_c_a.getChild(new Event<String>("b")); 61 TrieNode<Event<?>> root_c_a_c = root_c_a.getChild(new Event<String>("c")); 62 TrieNode<Event<?>> root_c_a_d = root_c_a.getChild(new Event<String>("d")); 63 TrieNode<Event<?>> root_c_a_r = root_c_a.getChild(new Event<String>("r")); 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")); 64 90 TrieNode<Event<?>> root_c_b = root_c.getChild(new Event<String>("b")); 65 91 TrieNode<Event<?>> root_c_c = root_c.getChild(new Event<String>("c")); … … 68 94 TrieNode<Event<?>> root_d = root.getChild(new Event<String>("d")); 69 95 TrieNode<Event<?>> root_d_a = root_d.getChild(new Event<String>("a")); 70 TrieNode<Event<?>> root_d_a_a = root_d_a.getChild(new Event<String>("a")); 71 TrieNode<Event<?>> root_d_a_b = root_d_a.getChild(new Event<String>("b")); 72 TrieNode<Event<?>> root_d_a_c = root_d_a.getChild(new Event<String>("c")); 73 TrieNode<Event<?>> root_d_a_d = root_d_a.getChild(new Event<String>("d")); 74 TrieNode<Event<?>> root_d_a_r = root_d_a.getChild(new Event<String>("r")); 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")); 75 106 TrieNode<Event<?>> root_d_b = root_d.getChild(new Event<String>("b")); 76 107 TrieNode<Event<?>> root_d_c = root_d.getChild(new Event<String>("c")); … … 79 110 TrieNode<Event<?>> root_r = root.getChild(new Event<String>("r")); 80 111 TrieNode<Event<?>> root_r_a = root_r.getChild(new Event<String>("a")); 81 TrieNode<Event<?>> root_r_a_a = root_r_a.getChild(new Event<String>("a")); 82 TrieNode<Event<?>> root_r_a_b = root_r_a.getChild(new Event<String>("b")); 83 TrieNode<Event<?>> root_r_a_c = root_r_a.getChild(new Event<String>("c")); 84 TrieNode<Event<?>> root_r_a_d = root_r_a.getChild(new Event<String>("d")); 85 TrieNode<Event<?>> root_r_a_r = root_r_a.getChild(new Event<String>("r")); 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")); 86 122 TrieNode<Event<?>> root_r_a_end = root_r_a.getChild(Event.ENDEVENT); 87 123 TrieNode<Event<?>> root_r_b = root_r.getChild(new Event<String>("b")); … … 90 126 TrieNode<Event<?>> root_r_r = root_r.getChild(new Event<String>("r")); 91 127 TrieNode<Event<?>> root_start = root.getChild(Event.STARTEVENT); 92 TrieNode<Event<?>> root_start_a = root_start.getChild(new Event<String>("a")); 93 TrieNode<Event<?>> root_start_a_a = root_start_a.getChild(new Event<String>("a")); 94 TrieNode<Event<?>> root_start_a_b = root_start_a.getChild(new Event<String>("b")); 95 TrieNode<Event<?>> root_start_a_c = root_start_a.getChild(new Event<String>("c")); 96 TrieNode<Event<?>> root_start_a_d = root_start_a.getChild(new Event<String>("d")); 97 TrieNode<Event<?>> root_start_a_r = root_start_a.getChild(new Event<String>("r")); 98 TrieNode<Event<?>> root_start_b = root_start.getChild(new Event<String>("b")); 99 TrieNode<Event<?>> root_start_c = root_start.getChild(new Event<String>("c")); 100 TrieNode<Event<?>> root_start_d = root_start.getChild(new Event<String>("d")); 101 TrieNode<Event<?>> root_start_r = root_start.getChild(new Event<String>("r")); 102 103 assertEquals(numSequences*5, root_a.getCount()); 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()); 104 150 assertNull(root_a_a); 105 assertEquals(numSequences *2, root_a_b.getCount());151 assertEquals(numSequences * 2, root_a_b.getCount()); 106 152 assertNull(root_a_b_a); 107 153 assertNull(root_a_b_b); 108 154 assertNull(root_a_b_c); 109 155 assertNull(root_a_b_d); 110 assertEquals(numSequences *2, root_a_b_r.getCount());111 assertEquals(numSequences *1, root_a_c.getCount());112 assertEquals(numSequences *1, root_a_c_a.getCount());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()); 113 159 assertNull(root_a_c_b); 114 160 assertNull(root_a_c_c); 115 161 assertNull(root_a_c_d); 116 162 assertNull(root_a_c_r); 117 assertEquals(numSequences *1, root_a_d.getCount());118 assertEquals(numSequences *1, root_a_d_a.getCount());163 assertEquals(numSequences * 1, root_a_d.getCount()); 164 assertEquals(numSequences * 1, root_a_d_a.getCount()); 119 165 assertNull(root_a_d_b); 120 166 assertNull(root_a_d_c); … … 122 168 assertNull(root_a_d_r); 123 169 assertNull(root_a_r); 124 125 assertEquals(numSequences *2, root_b.getCount());170 171 assertEquals(numSequences * 2, root_b.getCount()); 126 172 assertNull(root_b_a); 127 173 assertNull(root_b_b); 128 174 assertNull(root_b_c); 129 175 assertNull(root_b_d); 130 assertEquals(numSequences *2, root_b_r.getCount());131 assertEquals(numSequences *2, root_b_r_a.getCount());176 assertEquals(numSequences * 2, root_b_r.getCount()); 177 assertEquals(numSequences * 2, root_b_r_a.getCount()); 132 178 assertNull(root_b_r_b); 133 179 assertNull(root_b_r_c); 134 180 assertNull(root_b_r_d); 135 181 assertNull(root_b_r_r); 136 137 assertEquals(numSequences *1, root_c.getCount());138 assertEquals(numSequences *1, root_c_a.getCount());182 183 assertEquals(numSequences * 1, root_c.getCount()); 184 assertEquals(numSequences * 1, root_c_a.getCount()); 139 185 assertNull(root_c_a_a); 140 186 assertNull(root_c_a_b); 141 187 assertNull(root_c_a_c); 142 assertEquals(numSequences *1, root_c_a_d.getCount());188 assertEquals(numSequences * 1, root_c_a_d.getCount()); 143 189 assertNull(root_c_a_r); 144 190 assertNull(root_c_b); … … 146 192 assertNull(root_c_d); 147 193 assertNull(root_c_r); 148 149 assertEquals(numSequences *1, root_d.getCount());150 assertEquals(numSequences *1, root_d_a.getCount());194 195 assertEquals(numSequences * 1, root_d.getCount()); 196 assertEquals(numSequences * 1, root_d_a.getCount()); 151 197 assertNull(root_d_a_a); 152 assertEquals(numSequences *1, root_d_a_b.getCount());198 assertEquals(numSequences * 1, root_d_a_b.getCount()); 153 199 assertNull(root_d_a_c); 154 200 assertNull(root_d_a_d); … … 158 204 assertNull(root_d_d); 159 205 assertNull(root_d_r); 160 161 assertEquals(numSequences *2, root_r.getCount());162 assertEquals(numSequences *2, root_r_a.getCount());206 207 assertEquals(numSequences * 2, root_r.getCount()); 208 assertEquals(numSequences * 2, root_r_a.getCount()); 163 209 assertNull(root_r_a_a); 164 210 assertNull(root_r_a_b); 165 assertEquals(numSequences *1, root_r_a_c.getCount());211 assertEquals(numSequences * 1, root_r_a_c.getCount()); 166 212 assertNull(root_r_a_d); 167 213 assertNull(root_r_a_r); 168 assertEquals(numSequences *1, root_r_a_end.getCount());214 assertEquals(numSequences * 1, root_r_a_end.getCount()); 169 215 assertNull(root_r_b); 170 216 assertNull(root_r_c); 171 217 assertNull(root_r_d); 172 218 assertNull(root_r_r); 173 174 assertEquals(numSequences *1, root_start.getCount());175 assertEquals(numSequences *1, root_start_a.getCount());219 220 assertEquals(numSequences * 1, root_start.getCount()); 221 assertEquals(numSequences * 1, root_start_a.getCount()); 176 222 assertNull(root_start_a_a); 177 assertEquals(numSequences *1, root_start_a_b.getCount());223 assertEquals(numSequences * 1, root_start_a_b.getCount()); 178 224 assertNull(root_start_a_c); 179 225 assertNull(root_start_a_d); … … 183 229 assertNull(root_start_d); 184 230 assertNull(root_start_r); 185 231 186 232 // check if leafs are really leafs 187 233 assertTrue(root_a_b_r.isLeaf()); … … 194 240 assertTrue(root_r_a_end.isLeaf()); 195 241 } 196 197 private static void assertCollectionContent(Collection<?> c1, Collection<?> c2) { 242 243 private static void assertCollectionContent(Collection<?> c1, 244 Collection<?> c2) { 198 245 assertEquals(c1.size(), c2.size()); 199 for ( Object obj : c1) {246 for (Object obj : c1) { 200 247 assertTrue(c2.contains(obj)); 201 248 } 202 249 } 203 204 @Test 205 public void testGenerateSequences_1() 206 throws Exception { 207 int markovOrder = 2; 208 MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder, new Random()); 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()); 209 284 Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>(); 210 285 sequences.add(sequence); 211 286 fixture.train(sequences); 212 287 int length = 2; 213 288 214 289 Collection<List<Event<?>>> expected = new HashSet<List<Event<?>>>(); 215 290 ArrayList<Event<?>> list; … … 251 326 expected.add(list); 252 327 253 254 Collection<List<? extends Event<?>>> result = fixture.generateSequences(length);328 Collection<List<? extends Event<?>>> result = fixture 329 .generateSequences(length); 255 330 256 331 assertCollectionContent(expected, result); … … 258 333 259 334 @Test 260 public void testGenerateSequences_2() 261 throws Exception {262 int markovOrder = 2;263 MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder,new Random());335 public void testGenerateSequences_2() throws Exception { 336 int markovOrder = 2; 337 MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder, 338 new Random()); 264 339 Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>(); 265 340 sequences.add(sequence); 266 341 fixture.train(sequences); 267 342 int length = 3; 268 343 269 344 Collection<List<Event<?>>> expected = new HashSet<List<Event<?>>>(); 270 345 ArrayList<Event<?>> list; … … 290 365 expected.add(list); 291 366 292 Collection<List<? extends Event<?>>> result = fixture.generateSequences(length, true); 367 Collection<List<? extends Event<?>>> result = fixture 368 .generateSequences(length, true); 293 369 294 370 assertCollectionContent(expected, result); 295 371 } 296 372 297 @Test( expected = java.security.InvalidParameterException.class)298 public void testGenerateSequences_3() 299 throws Exception {300 int markovOrder = 2;301 MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder,new Random());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()); 302 378 Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>(); 303 379 sequences.add(sequence); … … 309 385 310 386 @Test 311 public void testGenerateValidSequences_1() 312 throws Exception {313 int markovOrder = 2;314 MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder,new Random());387 public void testGenerateValidSequences_1() throws Exception { 388 int markovOrder = 2; 389 MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder, 390 new Random()); 315 391 Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>(); 316 392 sequences.add(sequence); 317 393 fixture.train(sequences); 318 394 int length = 5; 319 395 320 396 Collection<List<Event<?>>> expected = new HashSet<List<Event<?>>>(); 321 397 ArrayList<Event<?>> list; … … 335 411 expected.add(list); 336 412 337 Collection<List<? extends Event<?>>> result = fixture.generateValidSequences(length); 413 Collection<List<? extends Event<?>>> result = fixture 414 .generateValidSequences(length); 338 415 339 416 assertCollectionContent(expected, result); 340 417 } 341 418 342 @Test(expected = java.security.InvalidParameterException.class 343 public void testGenerateValidSequences_2() 344 throws Exception {345 int markovOrder = 2;346 MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder,new Random());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()); 347 424 Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>(); 348 425 sequences.add(sequence); … … 352 429 fixture.generateValidSequences(length); 353 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 } 354 565 355 @Test 356 public void testGetEvents_1() 357 throws Exception { 358 int markovOrder = 2; 359 MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder, new Random()); 360 Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>(); 361 sequences.add(sequence); 362 363 fixture.train(sequences); 364 365 Collection<? extends Event<?>> result = fixture.getEvents(); 366 367 assertCollectionContent(symbols, result); 368 } 369 370 @Test 371 public void testGetEvents_2() 372 throws Exception { 373 int markovOrder = 2; 374 MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder, new Random()); 375 376 Collection<? extends Event<?>> result = fixture.getEvents(); 377 378 assertCollectionContent(new HashSet<Event<?>>(), result); 379 } 380 381 @Test 382 public void testGetNumFOMStates_1() 383 throws Exception { 384 int markovOrder = 2; 385 MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder, new Random()); 386 Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>(); 387 sequences.add(sequence); 388 389 fixture.train(sequences); 390 391 int result = fixture.getNumFOMStates(); 392 393 assertEquals(10, result); 394 } 395 396 @Test 397 public void testGetNumFOMStates_2() 398 throws Exception { 399 int markovOrder = 2; 400 MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder, new Random());; 401 402 int result = fixture.getNumFOMStates(); 403 404 assertEquals(0, result); 405 } 406 407 @Test 408 public void testGetNumSymbols_1() 409 throws Exception { 410 int markovOrder = 2; 411 MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder, new Random()); 412 Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>(); 413 sequences.add(sequence); 414 fixture.train(sequences); 415 416 int result = fixture.getNumSymbols(); 417 418 assertEquals(7, result); 419 } 420 421 @Test 422 public void testGetNumSymbols_2() 423 throws Exception { 424 int markovOrder = 2; 425 MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder, new Random()); 426 427 int result = fixture.getNumSymbols(); 428 429 assertEquals(0, result); 430 } 431 432 @Test 433 public void testGetNumTransitions_1() 434 throws Exception { 435 int markovOrder = 2; 436 MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder, new Random()); 437 Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>(); 438 sequences.add(sequence); 439 fixture.train(sequences); 440 441 int result = fixture.getNumTransitions(); 442 443 assertEquals(11, result); 444 } 445 446 @Test 447 public void testGetNumTransitions_2() 448 throws Exception { 449 int markovOrder = 2; 450 MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder, new Random()); 451 452 int result = fixture.getNumTransitions(); 453 454 assertEquals(0, result); 455 } 456 457 @Test 458 public void testTrain_1 () 459 throws Exception { 460 int markovOrder = 2; 461 MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder, new Random()); 462 Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>(); 463 sequences.add(sequence); 464 465 fixture.train(sequences); 466 467 assertCollectionContent(symbols, fixture.getEvents()); 468 469 assertTrieStructure(fixture.trie, 1); } 470 471 @Test 472 public void testTrain_2 () 473 throws Exception { 474 int markovOrder = 2; 475 MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder, new Random()); 476 Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>(); 477 sequences.add(sequence); 478 sequences.add(sequence); 479 480 fixture.train(sequences); 481 482 assertCollectionContent(symbols, fixture.getEvents()); 483 484 assertTrieStructure(fixture.trie, 2); 485 } 486 487 @Test 488 public void testUpdate_1() 489 throws Exception { 490 int markovOrder = 2; 491 MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder, new Random()); 492 Collection<List<? extends Event<?>>> sequences = new ArrayList<List<? extends Event<?>>>(); 493 sequences.add(sequence); 494 fixture.train(sequences); 495 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 496 585 fixture.update(sequences); 497 586 … … 500 589 } 501 590 502 @Test 503 public void testUpdate_2() 504 throws Exception {505 int markovOrder = 2;506 MockTrieBasedModel fixture = new MockTrieBasedModel(markovOrder,new Random());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()); 507 596 Collection<List<? extends Event<?>>> sequences = null; 508 597 fixture.trie = null; 509 598 510 599 fixture.update(sequences); 511 512 assertNull(fixture.trie);513 600 } 514 601 515 602 @Before 516 public void setUp() 517 throws Exception { 603 public void setUp() throws Exception { 518 604 sequence = new ArrayList<Event<?>>(); 519 605 sequence.add(new Event<String>("a")); … … 528 614 sequence.add(new Event<String>("r")); 529 615 sequence.add(new Event<String>("a")); 530 616 531 617 symbols = new HashSet<Event<?>>(); 532 618 symbols.add(new Event<String>("a")); … … 539 625 } 540 626 541 @After542 public void tearDown()543 throws Exception {544 // Add additional tear down code here545 }546 547 627 public static void main(String[] args) { 548 628 new org.junit.runner.JUnitCore().run(TrieBasedModelTest.class);
Note: See TracChangeset
for help on using the changeset viewer.