1 | package de.ugoe.cs.autoquest.usageprofiles;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.Collection;
|
---|
5 | import java.util.List;
|
---|
6 |
|
---|
7 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
8 | import de.ugoe.cs.autoquest.eventcore.StringEventType;
|
---|
9 | import de.ugoe.cs.autoquest.usageprofiles.HighOrderMarkovModel;
|
---|
10 |
|
---|
11 | import java.util.Random;
|
---|
12 | import org.junit.*;
|
---|
13 |
|
---|
14 | import static org.junit.Assert.*;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * The class <code>HighOrderMarkovModelTest</code> contains tests for the class
|
---|
18 | * <code>{@link HighOrderMarkovModel}</code>.
|
---|
19 | *
|
---|
20 | * @author Steffen Herbold
|
---|
21 | * @version 1.0
|
---|
22 | */
|
---|
23 | public class HighOrderMarkovModelTest {
|
---|
24 |
|
---|
25 | Collection<List<Event>> sequences;
|
---|
26 |
|
---|
27 | @Test
|
---|
28 | public void testHighOrderMarkovModel_1() throws Exception {
|
---|
29 | int maxOrder = 1;
|
---|
30 | Random r = new Random();
|
---|
31 |
|
---|
32 | HighOrderMarkovModel result = new HighOrderMarkovModel(maxOrder, r);
|
---|
33 |
|
---|
34 | assertNotNull(result);
|
---|
35 | assertEquals(r, result.r);
|
---|
36 | assertEquals(maxOrder + 1, result.trieOrder);
|
---|
37 | }
|
---|
38 |
|
---|
39 | @Test
|
---|
40 | public void testHighOrderMarkovModel_2() throws Exception {
|
---|
41 | int maxOrder = 0;
|
---|
42 | Random r = new Random();
|
---|
43 |
|
---|
44 | HighOrderMarkovModel result = new HighOrderMarkovModel(maxOrder, r);
|
---|
45 |
|
---|
46 | assertNotNull(result);
|
---|
47 | assertEquals(r, result.r);
|
---|
48 | assertEquals(maxOrder + 1, result.trieOrder);
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Test(expected = java.lang.IllegalArgumentException.class)
|
---|
52 | public void testHighOrderMarkovModel_3() throws Exception {
|
---|
53 | int maxOrder = 1;
|
---|
54 | Random r = null;
|
---|
55 |
|
---|
56 | new HighOrderMarkovModel(maxOrder, r);
|
---|
57 | }
|
---|
58 |
|
---|
59 | @Test(expected = java.lang.IllegalArgumentException.class)
|
---|
60 | public void testHighOrderMarkovModel_4() throws Exception {
|
---|
61 | int maxOrder = -1;
|
---|
62 | Random r = new Random();
|
---|
63 |
|
---|
64 | new HighOrderMarkovModel(maxOrder, r);
|
---|
65 | }
|
---|
66 |
|
---|
67 | @Test
|
---|
68 | public void testGetProbability_1() throws Exception {
|
---|
69 | int markovOrder = 1;
|
---|
70 | HighOrderMarkovModel fixture = new HighOrderMarkovModel(markovOrder,
|
---|
71 | new Random());
|
---|
72 | fixture.train(sequences);
|
---|
73 |
|
---|
74 | List<Event> context = new ArrayList<Event>();
|
---|
75 | context.add(new Event(new StringEventType("a")));
|
---|
76 |
|
---|
77 | Event symbol = new Event(new StringEventType("b"));
|
---|
78 |
|
---|
79 | double result = fixture.getProbability(context, symbol);
|
---|
80 |
|
---|
81 | assertEquals(2.0d / 5.0, result, 0.0001);
|
---|
82 | }
|
---|
83 |
|
---|
84 | @Test
|
---|
85 | public void testGetProbability_2() throws Exception {
|
---|
86 | int markovOrder = 1;
|
---|
87 | HighOrderMarkovModel fixture = new HighOrderMarkovModel(markovOrder,
|
---|
88 | new Random());
|
---|
89 | fixture.train(sequences);
|
---|
90 |
|
---|
91 | List<Event> context = new ArrayList<Event>();
|
---|
92 | context.add(new Event(new StringEventType("a")));
|
---|
93 |
|
---|
94 | Event symbol = new Event(new StringEventType("r"));
|
---|
95 |
|
---|
96 | double result = fixture.getProbability(context, symbol);
|
---|
97 |
|
---|
98 | assertEquals(0.0d / 5.0, result, 0.0001);
|
---|
99 | }
|
---|
100 |
|
---|
101 | @Test
|
---|
102 | public void testGetProbability_3() throws Exception {
|
---|
103 | int markovOrder = 1;
|
---|
104 | HighOrderMarkovModel fixture = new HighOrderMarkovModel(markovOrder,
|
---|
105 | new Random());
|
---|
106 | fixture.train(sequences);
|
---|
107 |
|
---|
108 | List<Event> context = new ArrayList<Event>();
|
---|
109 | context.add(new Event(new StringEventType("a")));
|
---|
110 |
|
---|
111 | Event symbol = new Event(new StringEventType("c"));
|
---|
112 |
|
---|
113 | double result = fixture.getProbability(context, symbol);
|
---|
114 |
|
---|
115 | assertEquals(1.0d / 5.0, result, 0.0001);
|
---|
116 | }
|
---|
117 |
|
---|
118 | @Test
|
---|
119 | public void testGetProbability_4() throws Exception {
|
---|
120 | int markovOrder = 1;
|
---|
121 | HighOrderMarkovModel fixture = new HighOrderMarkovModel(markovOrder,
|
---|
122 | new Random());
|
---|
123 | fixture.train(sequences);
|
---|
124 |
|
---|
125 | List<Event> context = new ArrayList<Event>();
|
---|
126 | context.add(Event.STARTEVENT);
|
---|
127 | context.add(new Event(new StringEventType("a")));
|
---|
128 |
|
---|
129 | Event symbol = new Event(new StringEventType("b"));
|
---|
130 |
|
---|
131 | double result = fixture.getProbability(context, symbol);
|
---|
132 |
|
---|
133 | assertEquals(2.0d / 5.0, result, 0.0001);
|
---|
134 | }
|
---|
135 |
|
---|
136 | @Test
|
---|
137 | public void testGetProbability_5() throws Exception {
|
---|
138 | int markovOrder = 2;
|
---|
139 | HighOrderMarkovModel fixture = new HighOrderMarkovModel(markovOrder,
|
---|
140 | new Random());
|
---|
141 | fixture.train(sequences);
|
---|
142 |
|
---|
143 | List<Event> context = new ArrayList<Event>();
|
---|
144 | context.add(Event.STARTEVENT);
|
---|
145 | context.add(new Event(new StringEventType("a")));
|
---|
146 |
|
---|
147 | Event symbol = new Event(new StringEventType("b"));
|
---|
148 |
|
---|
149 | double result = fixture.getProbability(context, symbol);
|
---|
150 |
|
---|
151 | assertEquals(1.0d, result, 0.0001);
|
---|
152 | }
|
---|
153 |
|
---|
154 | @Test
|
---|
155 | public void testGetProbability_6() throws Exception {
|
---|
156 | int markovOrder = 2;
|
---|
157 | HighOrderMarkovModel fixture = new HighOrderMarkovModel(markovOrder,
|
---|
158 | new Random());
|
---|
159 | fixture.train(sequences);
|
---|
160 |
|
---|
161 | List<Event> context = new ArrayList<Event>();
|
---|
162 | context.add(Event.STARTEVENT);
|
---|
163 | context.add(new Event(new StringEventType("b")));
|
---|
164 |
|
---|
165 | Event symbol = new Event(new StringEventType("b"));
|
---|
166 |
|
---|
167 | double result = fixture.getProbability(context, symbol);
|
---|
168 |
|
---|
169 | assertEquals(0.0d, result, 0.0001);
|
---|
170 | }
|
---|
171 |
|
---|
172 | @Test
|
---|
173 | public void testGetProbability_7() throws Exception {
|
---|
174 | int markovOrder = 0;
|
---|
175 | HighOrderMarkovModel fixture = new HighOrderMarkovModel(markovOrder,
|
---|
176 | new Random());
|
---|
177 | fixture.train(sequences);
|
---|
178 |
|
---|
179 | List<Event> context = new ArrayList<Event>();
|
---|
180 | context.add(Event.STARTEVENT);
|
---|
181 | context.add(new Event(new StringEventType("b")));
|
---|
182 |
|
---|
183 | Event symbol = new Event(new StringEventType("a"));
|
---|
184 |
|
---|
185 | double result = fixture.getProbability(context, symbol);
|
---|
186 |
|
---|
187 | assertEquals(5.0d / 13.0, result, 0.0001);
|
---|
188 | }
|
---|
189 |
|
---|
190 | @Test(expected = java.lang.IllegalArgumentException.class)
|
---|
191 | public void testGetProbability_8() throws Exception {
|
---|
192 | int markovOrder = 0;
|
---|
193 | HighOrderMarkovModel fixture = new HighOrderMarkovModel(markovOrder,
|
---|
194 | new Random());
|
---|
195 | fixture.train(sequences);
|
---|
196 |
|
---|
197 | List<Event> context = new ArrayList<Event>();
|
---|
198 | context.add(Event.STARTEVENT);
|
---|
199 | context.add(new Event(new StringEventType("b")));
|
---|
200 |
|
---|
201 | Event symbol = null;
|
---|
202 |
|
---|
203 | fixture.getProbability(context, symbol);
|
---|
204 | }
|
---|
205 |
|
---|
206 | @Test(expected = java.lang.IllegalArgumentException.class)
|
---|
207 | public void testGetProbability_9() throws Exception {
|
---|
208 | int markovOrder = 0;
|
---|
209 | HighOrderMarkovModel fixture = new HighOrderMarkovModel(markovOrder,
|
---|
210 | new Random());
|
---|
211 | fixture.train(sequences);
|
---|
212 |
|
---|
213 | List<Event> context = null;
|
---|
214 |
|
---|
215 | Event symbol = new Event(new StringEventType("b"));
|
---|
216 |
|
---|
217 | fixture.getProbability(context, symbol);
|
---|
218 | }
|
---|
219 |
|
---|
220 | @Before
|
---|
221 | public void setUp() throws Exception {
|
---|
222 | List<Event> sequence = new ArrayList<Event>();
|
---|
223 | sequence.add(new Event(new StringEventType("a")));
|
---|
224 | sequence.add(new Event(new StringEventType("b")));
|
---|
225 | sequence.add(new Event(new StringEventType("r")));
|
---|
226 | sequence.add(new Event(new StringEventType("a")));
|
---|
227 | sequence.add(new Event(new StringEventType("c")));
|
---|
228 | sequence.add(new Event(new StringEventType("a")));
|
---|
229 | sequence.add(new Event(new StringEventType("d")));
|
---|
230 | sequence.add(new Event(new StringEventType("a")));
|
---|
231 | sequence.add(new Event(new StringEventType("b")));
|
---|
232 | sequence.add(new Event(new StringEventType("r")));
|
---|
233 | sequence.add(new Event(new StringEventType("a")));
|
---|
234 |
|
---|
235 | sequences = new ArrayList<List<Event>>();
|
---|
236 | sequences.add(sequence);
|
---|
237 | }
|
---|
238 |
|
---|
239 | public static void main(String[] args) {
|
---|
240 | new org.junit.runner.JUnitCore().run(HighOrderMarkovModelTest.class);
|
---|
241 | }
|
---|
242 | } |
---|