1 | package de.ugoe.cs.eventbench.models;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.Collection;
|
---|
5 | import java.util.List;
|
---|
6 | import de.ugoe.cs.eventbench.data.Event;
|
---|
7 | import java.util.Random;
|
---|
8 | import org.junit.*;
|
---|
9 |
|
---|
10 | import static org.junit.Assert.*;
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * The class <code>DeterministicFiniteAutomatonTest</code> contains tests for
|
---|
14 | * the class <code>{@link DeterministicFiniteAutomaton}</code>.
|
---|
15 | *
|
---|
16 | * @author Steffen Herbold
|
---|
17 | * @version 1.0
|
---|
18 | */
|
---|
19 | public class DeterministicFiniteAutomatonTest {
|
---|
20 |
|
---|
21 | Collection<List<? extends Event<?>>> sequences;
|
---|
22 |
|
---|
23 | @Test
|
---|
24 | public void testDeterministicFiniteAutomaton_1() throws Exception {
|
---|
25 | Random r = new Random();
|
---|
26 |
|
---|
27 | DeterministicFiniteAutomaton result = new DeterministicFiniteAutomaton(
|
---|
28 | r);
|
---|
29 |
|
---|
30 | assertNotNull(result);
|
---|
31 | assertEquals(2, result.trieOrder);
|
---|
32 | }
|
---|
33 |
|
---|
34 | @Test(expected = java.security.InvalidParameterException.class)
|
---|
35 | public void testDeterministicFiniteAutomaton_2() throws Exception {
|
---|
36 | new DeterministicFiniteAutomaton(null);
|
---|
37 | }
|
---|
38 |
|
---|
39 | @Test
|
---|
40 | public void testGetProbability_1() throws Exception {
|
---|
41 | DeterministicFiniteAutomaton fixture = new DeterministicFiniteAutomaton(
|
---|
42 | new Random());
|
---|
43 | fixture.train(sequences);
|
---|
44 |
|
---|
45 | List<Event<String>> context = new ArrayList<Event<String>>();
|
---|
46 | context.add(new Event<String>("a"));
|
---|
47 | context.add(new Event<String>("b"));
|
---|
48 |
|
---|
49 | Event<String> symbol = new Event<String>("r");
|
---|
50 |
|
---|
51 | double result = fixture.getProbability(context, symbol);
|
---|
52 |
|
---|
53 | assertEquals(1.0d, result, 0.0001);
|
---|
54 | }
|
---|
55 |
|
---|
56 | @Test
|
---|
57 | public void testGetProbability_2() throws Exception {
|
---|
58 | DeterministicFiniteAutomaton fixture = new DeterministicFiniteAutomaton(
|
---|
59 | new Random());
|
---|
60 | fixture.train(sequences);
|
---|
61 |
|
---|
62 | List<Event<String>> context = new ArrayList<Event<String>>();
|
---|
63 | context.add(new Event<String>("a"));
|
---|
64 |
|
---|
65 | Event<String> symbol = new Event<String>("b");
|
---|
66 |
|
---|
67 | double result = fixture.getProbability(context, symbol);
|
---|
68 |
|
---|
69 | assertEquals(1.0d / 4.0, result, 0.0001);
|
---|
70 | }
|
---|
71 |
|
---|
72 | @Test
|
---|
73 | public void testGetProbability_3() throws Exception {
|
---|
74 | DeterministicFiniteAutomaton fixture = new DeterministicFiniteAutomaton(
|
---|
75 | new Random());
|
---|
76 | fixture.train(sequences);
|
---|
77 |
|
---|
78 | List<Event<String>> context = new ArrayList<Event<String>>();
|
---|
79 | context.add(new Event<String>("a"));
|
---|
80 |
|
---|
81 | Event<String> symbol = new Event<String>("c");
|
---|
82 |
|
---|
83 | double result = fixture.getProbability(context, symbol);
|
---|
84 |
|
---|
85 | assertEquals(1.0d / 4.0, result, 0.0001);
|
---|
86 | }
|
---|
87 |
|
---|
88 | @Test
|
---|
89 | public void testGetProbability_4() throws Exception {
|
---|
90 | DeterministicFiniteAutomaton fixture = new DeterministicFiniteAutomaton(
|
---|
91 | new Random());
|
---|
92 | fixture.train(sequences);
|
---|
93 |
|
---|
94 | List<Event<String>> context = new ArrayList<Event<String>>();
|
---|
95 | context.add(new Event<String>("a"));
|
---|
96 |
|
---|
97 | Event<String> symbol = new Event<String>("e");
|
---|
98 |
|
---|
99 | double result = fixture.getProbability(context, symbol);
|
---|
100 |
|
---|
101 | assertEquals(0.0d, result, 0.0001);
|
---|
102 | }
|
---|
103 |
|
---|
104 | @Test(expected = java.security.InvalidParameterException.class)
|
---|
105 | public void testGetProbability_5() throws Exception {
|
---|
106 | DeterministicFiniteAutomaton fixture = new DeterministicFiniteAutomaton(
|
---|
107 | new Random());
|
---|
108 | fixture.train(sequences);
|
---|
109 |
|
---|
110 | List<Event<String>> context = new ArrayList<Event<String>>();
|
---|
111 | context.add(new Event<String>("a"));
|
---|
112 |
|
---|
113 | Event<String> symbol = null;
|
---|
114 |
|
---|
115 | fixture.getProbability(context, symbol);
|
---|
116 | }
|
---|
117 |
|
---|
118 | @Test(expected = java.security.InvalidParameterException.class)
|
---|
119 | public void testGetProbability_6() throws Exception {
|
---|
120 | DeterministicFiniteAutomaton fixture = new DeterministicFiniteAutomaton(
|
---|
121 | new Random());
|
---|
122 | fixture.train(sequences);
|
---|
123 |
|
---|
124 | List<Event<String>> context = null;
|
---|
125 |
|
---|
126 | Event<String> symbol = new Event<String>("a");
|
---|
127 |
|
---|
128 | fixture.getProbability(context, symbol);
|
---|
129 | }
|
---|
130 |
|
---|
131 | @Before
|
---|
132 | public void setUp() throws Exception {
|
---|
133 | List<Event<?>> sequence = new ArrayList<Event<?>>();
|
---|
134 | sequence.add(new Event<String>("a"));
|
---|
135 | sequence.add(new Event<String>("b"));
|
---|
136 | sequence.add(new Event<String>("r"));
|
---|
137 | sequence.add(new Event<String>("a"));
|
---|
138 | sequence.add(new Event<String>("c"));
|
---|
139 | sequence.add(new Event<String>("a"));
|
---|
140 | sequence.add(new Event<String>("d"));
|
---|
141 | sequence.add(new Event<String>("a"));
|
---|
142 | sequence.add(new Event<String>("b"));
|
---|
143 | sequence.add(new Event<String>("r"));
|
---|
144 | sequence.add(new Event<String>("a"));
|
---|
145 |
|
---|
146 | sequences = new ArrayList<List<? extends Event<?>>>();
|
---|
147 | sequences.add(sequence);
|
---|
148 | }
|
---|
149 |
|
---|
150 | public static void main(String[] args) {
|
---|
151 | new org.junit.runner.JUnitCore()
|
---|
152 | .run(DeterministicFiniteAutomatonTest.class);
|
---|
153 | }
|
---|
154 | } |
---|