[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] | 15 | package de.ugoe.cs.autoquest.usageprofiles;
|
---|
[518] | 16 |
|
---|
| 17 | import java.util.ArrayList;
|
---|
| 18 | import java.util.Collection;
|
---|
| 19 | import java.util.List;
|
---|
| 20 |
|
---|
[922] | 21 | import de.ugoe.cs.autoquest.eventcore.Event;
|
---|
| 22 | import de.ugoe.cs.autoquest.eventcore.StringEventType;
|
---|
| 23 | import de.ugoe.cs.autoquest.usageprofiles.DeterministicFiniteAutomaton;
|
---|
[518] | 24 |
|
---|
| 25 | import java.util.Random;
|
---|
| 26 | import org.junit.*;
|
---|
| 27 |
|
---|
| 28 | import 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 | */
|
---|
| 37 | public 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 | } |
---|