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