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

Last change on this file since 1258 was 927, checked in by sherbold, 12 years ago
  • added copyright under the Apache License, Version 2.0
  • Property svn:mime-type set to text/plain
File size: 5.3 KB
RevLine 
[927]1//   Copyright 2012 Georg-August-Universität Göttingen, Germany
2//
3//   Licensed under the Apache License, Version 2.0 (the "License");
4//   you may not use this file except in compliance with the License.
5//   You may obtain a copy of the License at
6//
7//       http://www.apache.org/licenses/LICENSE-2.0
8//
9//   Unless required by applicable law or agreed to in writing, software
10//   distributed under the License is distributed on an "AS IS" BASIS,
11//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//   See the License for the specific language governing permissions and
13//   limitations under the License.
14
[922]15package de.ugoe.cs.autoquest.usageprofiles;
[518]16
17import java.util.ArrayList;
18import java.util.Collection;
19import java.util.List;
20
[922]21import de.ugoe.cs.autoquest.eventcore.Event;
22import de.ugoe.cs.autoquest.eventcore.StringEventType;
23import de.ugoe.cs.autoquest.usageprofiles.DeterministicFiniteAutomaton;
[518]24
25import java.util.Random;
26import org.junit.*;
27
28import static org.junit.Assert.*;
29
30/**
31 * The class <code>DeterministicFiniteAutomatonTest</code> contains tests for
32 * the class <code>{@link DeterministicFiniteAutomaton}</code>.
33 *
34 * @author Steffen Herbold
35 * @version 1.0
36 */
37public class DeterministicFiniteAutomatonTest {
38
[548]39        Collection<List<Event>> sequences;
[518]40
41        @Test
42        public void testDeterministicFiniteAutomaton_1() throws Exception {
43                Random r = new Random();
44
45                DeterministicFiniteAutomaton result = new DeterministicFiniteAutomaton(
46                                r);
47
48                assertNotNull(result);
49                assertEquals(2, result.trieOrder);
50        }
51
[766]52        @Test(expected = java.lang.IllegalArgumentException.class)
[518]53        public void testDeterministicFiniteAutomaton_2() throws Exception {
54                new DeterministicFiniteAutomaton(null);
55        }
56
57        @Test
58        public void testGetProbability_1() throws Exception {
59                DeterministicFiniteAutomaton fixture = new DeterministicFiniteAutomaton(
60                                new Random());
61                fixture.train(sequences);
62
[548]63                List<Event> context = new ArrayList<Event>();
64                context.add(new Event(new StringEventType("a")));
65                context.add(new Event(new StringEventType("b")));
[518]66
[548]67                Event symbol = new Event(new StringEventType("r"));
[518]68
69                double result = fixture.getProbability(context, symbol);
70
71                assertEquals(1.0d, result, 0.0001);
72        }
73
74        @Test
75        public void testGetProbability_2() throws Exception {
76                DeterministicFiniteAutomaton fixture = new DeterministicFiniteAutomaton(
77                                new Random());
78                fixture.train(sequences);
79
[548]80                List<Event> context = new ArrayList<Event>();
81                context.add(new Event(new StringEventType("a")));
[518]82
[548]83                Event symbol = new Event(new StringEventType("b"));
[518]84
85                double result = fixture.getProbability(context, symbol);
86
87                assertEquals(1.0d / 4.0, result, 0.0001);
88        }
89
90        @Test
91        public void testGetProbability_3() throws Exception {
92                DeterministicFiniteAutomaton fixture = new DeterministicFiniteAutomaton(
93                                new Random());
94                fixture.train(sequences);
95
[548]96                List<Event> context = new ArrayList<Event>();
97                context.add(new Event(new StringEventType("a")));
[518]98
[548]99                Event symbol = new Event(new StringEventType("c"));
[518]100
101                double result = fixture.getProbability(context, symbol);
102
103                assertEquals(1.0d / 4.0, result, 0.0001);
104        }
105
106        @Test
107        public void testGetProbability_4() throws Exception {
108                DeterministicFiniteAutomaton fixture = new DeterministicFiniteAutomaton(
109                                new Random());
110                fixture.train(sequences);
111
[548]112                List<Event> context = new ArrayList<Event>();
113                context.add(new Event(new StringEventType("a")));
[518]114
[548]115                Event symbol = new Event(new StringEventType("e"));
[518]116
117                double result = fixture.getProbability(context, symbol);
118
119                assertEquals(0.0d, result, 0.0001);
120        }
121
[766]122        @Test(expected = java.lang.IllegalArgumentException.class)
[518]123        public void testGetProbability_5() throws Exception {
124                DeterministicFiniteAutomaton fixture = new DeterministicFiniteAutomaton(
125                                new Random());
126                fixture.train(sequences);
127
[548]128                List<Event> context = new ArrayList<Event>();
129                context.add(new Event(new StringEventType("a")));
[518]130
[548]131                Event symbol = null;
[518]132
133                fixture.getProbability(context, symbol);
134        }
135
[766]136        @Test(expected = java.lang.IllegalArgumentException.class)
[518]137        public void testGetProbability_6() throws Exception {
138                DeterministicFiniteAutomaton fixture = new DeterministicFiniteAutomaton(
139                                new Random());
140                fixture.train(sequences);
141
[548]142                List<Event> context = null;
[518]143
[548]144                Event symbol = new Event(new StringEventType("a"));
[518]145
146                fixture.getProbability(context, symbol);
147        }
148
149        @Before
150        public void setUp() throws Exception {
[548]151                List<Event> sequence = new ArrayList<Event>();
152                sequence.add(new Event(new StringEventType("a")));
153                sequence.add(new Event(new StringEventType("b")));
154                sequence.add(new Event(new StringEventType("r")));
155                sequence.add(new Event(new StringEventType("a")));
156                sequence.add(new Event(new StringEventType("c")));
157                sequence.add(new Event(new StringEventType("a")));
158                sequence.add(new Event(new StringEventType("d")));
159                sequence.add(new Event(new StringEventType("a")));
160                sequence.add(new Event(new StringEventType("b")));
161                sequence.add(new Event(new StringEventType("r")));
162                sequence.add(new Event(new StringEventType("a")));
[518]163
[548]164                sequences = new ArrayList<List<Event>>();
[518]165                sequences.add(sequence);
166        }
167
168        public static void main(String[] args) {
169                new org.junit.runner.JUnitCore()
170                                .run(DeterministicFiniteAutomatonTest.class);
171        }
172}
Note: See TracBrowser for help on using the repository browser.