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