source: trunk/quest-core-usageprofiles-test/src/test/java/de/ugoe/cs/quest/usageprofiles/DeterministicFiniteAutomatonTest.java @ 553

Last change on this file since 553 was 553, checked in by sherbold, 12 years ago
  • countless adaptations throughout nearly all components to remove errors introduced due to the refactoring of the event core
  • added StringEventType? as a simple-to-use event type instead of DummyEventType?
  • Property svn:mime-type set to text/plain
File size: 4.6 KB
Line 
1package de.ugoe.cs.quest.usageprofiles;
2
3import java.util.ArrayList;
4import java.util.Collection;
5import java.util.List;
6
7import de.ugoe.cs.quest.eventcore.Event;
8import de.ugoe.cs.quest.eventcore.StringEventType;
9import de.ugoe.cs.quest.usageprofiles.DeterministicFiniteAutomaton;
10
11import java.util.Random;
12import org.junit.*;
13
14import 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 */
23public 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.security.InvalidParameterException.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.security.InvalidParameterException.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.security.InvalidParameterException.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}
Note: See TracBrowser for help on using the repository browser.