1 | package de.ugoe.cs.quest.coverage;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.Collection;
|
---|
5 |
|
---|
6 | import java.util.LinkedHashSet;
|
---|
7 | import java.util.LinkedList;
|
---|
8 | import java.util.List;
|
---|
9 | import java.util.Random;
|
---|
10 | import java.util.Set;
|
---|
11 | import de.ugoe.cs.quest.coverage.CoverageCalculatorProcess;
|
---|
12 | import de.ugoe.cs.quest.eventcore.Event;
|
---|
13 | import de.ugoe.cs.quest.eventcore.StringEventType;
|
---|
14 | import de.ugoe.cs.quest.usageprofiles.MockTrieBasedModel;
|
---|
15 |
|
---|
16 | import org.junit.*;
|
---|
17 |
|
---|
18 | import static org.junit.Assert.*;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * The class <code>CoverageCalculatorProcessTest</code> contains tests for the
|
---|
22 | * class <code>{@link CoverageCalculatorProcess}</code>.
|
---|
23 | *
|
---|
24 | * @author Steffen Herbold
|
---|
25 | * @version 1.0
|
---|
26 | */
|
---|
27 | public class CoverageCalculatorProcessTest {
|
---|
28 |
|
---|
29 | Set<List<Event>> sequencesCovered;
|
---|
30 | Set<List<Event>> sequencesCovered2;
|
---|
31 | MockTrieBasedModel mockProcess;
|
---|
32 |
|
---|
33 | @Test
|
---|
34 | public void testCoverageCalculatorProcess_1() throws Exception {
|
---|
35 | int length = 2;
|
---|
36 |
|
---|
37 | CoverageCalculatorProcess result = new CoverageCalculatorProcess(
|
---|
38 | mockProcess, sequencesCovered, length);
|
---|
39 | assertNotNull(result);
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Test(expected = java.security.InvalidParameterException.class)
|
---|
43 | public void testCoverageCalculatorProcess_2() throws Exception {
|
---|
44 | int length = 2;
|
---|
45 |
|
---|
46 | new CoverageCalculatorProcess(null,sequencesCovered, length);
|
---|
47 | }
|
---|
48 |
|
---|
49 | @Test(expected = java.security.InvalidParameterException.class)
|
---|
50 | public void testCoverageCalculatorProcess_3() throws Exception {
|
---|
51 | int length = 2;
|
---|
52 |
|
---|
53 | new CoverageCalculatorProcess(mockProcess, null, length);
|
---|
54 | }
|
---|
55 |
|
---|
56 | @Test(expected = java.security.InvalidParameterException.class)
|
---|
57 | public void testCoverageCalculatorProcess_4() throws Exception {
|
---|
58 | int length = 0;
|
---|
59 |
|
---|
60 | new CoverageCalculatorProcess(mockProcess, sequencesCovered, length);
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Test(expected = java.security.InvalidParameterException.class)
|
---|
64 | public void testCoverageCalculatorProcess_5() throws Exception {
|
---|
65 | int length = -1;
|
---|
66 |
|
---|
67 | new CoverageCalculatorProcess(mockProcess, sequencesCovered, length);
|
---|
68 | }
|
---|
69 |
|
---|
70 | @Test
|
---|
71 | public void testGetCoverageAllNoWeight_1() throws Exception {
|
---|
72 | int length = 2;
|
---|
73 | CoverageCalculatorProcess fixture = new CoverageCalculatorProcess(
|
---|
74 | mockProcess, sequencesCovered, length);
|
---|
75 |
|
---|
76 | double result = fixture.getCoverageAllNoWeight();
|
---|
77 |
|
---|
78 | assertEquals(3.0 / 49.0, result, 0.0001);
|
---|
79 | }
|
---|
80 |
|
---|
81 | @Test
|
---|
82 | public void testGetCoverageAllNoWeight_2() throws Exception {
|
---|
83 | int length = 2;
|
---|
84 | CoverageCalculatorProcess fixture = new CoverageCalculatorProcess(
|
---|
85 | mockProcess, sequencesCovered2, length);
|
---|
86 |
|
---|
87 | double result = fixture.getCoverageAllNoWeight();
|
---|
88 |
|
---|
89 | assertEquals(2.0 / 49.0, result, 0.0001);
|
---|
90 | }
|
---|
91 |
|
---|
92 | @Test
|
---|
93 | public void testGetCoveragePossibleNoWeight_1() throws Exception {
|
---|
94 | int length = 2;
|
---|
95 | CoverageCalculatorProcess fixture = new CoverageCalculatorProcess(
|
---|
96 | mockProcess, sequencesCovered, length);
|
---|
97 |
|
---|
98 | double result = fixture.getCoveragePossibleNoWeight();
|
---|
99 |
|
---|
100 | assertEquals(3.0 / 9.0, result, 0.0001);
|
---|
101 | }
|
---|
102 |
|
---|
103 | @Test
|
---|
104 | public void testGetCoveragePossibleNoWeight_2() throws Exception {
|
---|
105 | int length = 2;
|
---|
106 | CoverageCalculatorProcess fixture = new CoverageCalculatorProcess(
|
---|
107 | mockProcess, sequencesCovered2, length);
|
---|
108 |
|
---|
109 | double result = fixture.getCoveragePossibleNoWeight();
|
---|
110 |
|
---|
111 | assertEquals(2.0 / 9.0, result, 0.0001);
|
---|
112 | }
|
---|
113 |
|
---|
114 | @Test
|
---|
115 | public void testGetCoveragePossibleWeight_1() throws Exception {
|
---|
116 | int length = 2;
|
---|
117 | CoverageCalculatorProcess fixture = new CoverageCalculatorProcess(
|
---|
118 | mockProcess, sequencesCovered, length);
|
---|
119 |
|
---|
120 | double result = fixture.getCoveragePossibleWeight();
|
---|
121 |
|
---|
122 | assertEquals(6.0, result, 0.0001);
|
---|
123 | }
|
---|
124 |
|
---|
125 | @Test
|
---|
126 | public void testGetCoveragePossibleWeight_2() throws Exception {
|
---|
127 | int length = 2;
|
---|
128 | CoverageCalculatorProcess fixture = new CoverageCalculatorProcess(
|
---|
129 | mockProcess, sequencesCovered2, length);
|
---|
130 |
|
---|
131 | double result = fixture.getCoveragePossibleWeight();
|
---|
132 |
|
---|
133 | assertEquals(4.0, result, 0.0001);
|
---|
134 | }
|
---|
135 |
|
---|
136 | @Test
|
---|
137 | public void testGetNumCovered_1() throws Exception {
|
---|
138 | int length = 2;
|
---|
139 | CoverageCalculatorProcess fixture = new CoverageCalculatorProcess(
|
---|
140 | mockProcess, sequencesCovered, length);
|
---|
141 |
|
---|
142 | int result = fixture.getNumCovered();
|
---|
143 |
|
---|
144 | assertEquals(3, result);
|
---|
145 | }
|
---|
146 |
|
---|
147 | @Test
|
---|
148 | public void testGetNumCovered_2() throws Exception {
|
---|
149 | int length = 2;
|
---|
150 | CoverageCalculatorProcess fixture = new CoverageCalculatorProcess(
|
---|
151 | mockProcess, sequencesCovered2, length);
|
---|
152 |
|
---|
153 | int result = fixture.getNumCovered();
|
---|
154 |
|
---|
155 | assertEquals(2, result);
|
---|
156 | }
|
---|
157 |
|
---|
158 | @Test
|
---|
159 | public void testGetNumPossible_1() throws Exception {
|
---|
160 | int length = 2;
|
---|
161 | CoverageCalculatorProcess fixture = new CoverageCalculatorProcess(
|
---|
162 | mockProcess, sequencesCovered, length);
|
---|
163 |
|
---|
164 | int result = fixture.getNumPossible();
|
---|
165 |
|
---|
166 | assertEquals(9, result);
|
---|
167 | }
|
---|
168 |
|
---|
169 | @Test
|
---|
170 | public void testSetSequences_1() throws Exception {
|
---|
171 | int length = 2;
|
---|
172 | CoverageCalculatorProcess fixture = new CoverageCalculatorProcess(
|
---|
173 | mockProcess, sequencesCovered, length);
|
---|
174 |
|
---|
175 | fixture.setSequences(sequencesCovered2);
|
---|
176 |
|
---|
177 | // testing indirectly if sequences were changed
|
---|
178 | assertEquals(2, fixture.getNumCovered());
|
---|
179 | }
|
---|
180 |
|
---|
181 | @Test(expected = java.security.InvalidParameterException.class)
|
---|
182 | public void testSetSequences_2() throws Exception {
|
---|
183 | int length = 2;
|
---|
184 | CoverageCalculatorProcess fixture = new CoverageCalculatorProcess(
|
---|
185 | mockProcess, sequencesCovered, length);
|
---|
186 |
|
---|
187 | fixture.setSequences(null);
|
---|
188 | }
|
---|
189 |
|
---|
190 | @Before
|
---|
191 | public void setUp() throws Exception {
|
---|
192 | Collection<List<Event>> sequences = new LinkedList<List<Event>>();
|
---|
193 | List<Event> sequence1 = new ArrayList<Event>();
|
---|
194 | sequence1.add(new Event(new StringEventType("a")));
|
---|
195 | sequence1.add(new Event(new StringEventType("b")));
|
---|
196 | sequence1.add(new Event(new StringEventType("r")));
|
---|
197 | sequence1.add(new Event(new StringEventType("a")));
|
---|
198 | List<Event> sequence2 = new ArrayList<Event>();
|
---|
199 | sequence2.add(new Event(new StringEventType("c")));
|
---|
200 | sequence2.add(new Event(new StringEventType("a")));
|
---|
201 | sequence2.add(new Event(new StringEventType("d")));
|
---|
202 | sequence2.add(new Event(new StringEventType("a")));
|
---|
203 | sequence2.add(new Event(new StringEventType("b")));
|
---|
204 | sequence2.add(new Event(new StringEventType("r")));
|
---|
205 | sequence2.add(new Event(new StringEventType("a")));
|
---|
206 | sequences.add(sequence1);
|
---|
207 | sequences.add(sequence2);
|
---|
208 |
|
---|
209 | sequencesCovered = new LinkedHashSet<List<Event>>();
|
---|
210 | List<Event> tmpList = new ArrayList<Event>();
|
---|
211 | tmpList.add(new Event(new StringEventType("a")));
|
---|
212 | tmpList.add(new Event(new StringEventType("b")));
|
---|
213 | tmpList.add(new Event(new StringEventType("r")));
|
---|
214 | sequencesCovered.add(tmpList);
|
---|
215 | tmpList = new ArrayList<Event>();
|
---|
216 | tmpList.add(new Event(new StringEventType("b")));
|
---|
217 | tmpList.add(new Event(new StringEventType("r")));
|
---|
218 | tmpList.add(new Event(new StringEventType("a")));
|
---|
219 | sequencesCovered.add(tmpList);
|
---|
220 |
|
---|
221 | sequencesCovered2 = new LinkedHashSet<List<Event>>();
|
---|
222 | tmpList = new ArrayList<Event>();
|
---|
223 | tmpList.add(new Event(new StringEventType("a")));
|
---|
224 | tmpList.add(new Event(new StringEventType("b")));
|
---|
225 | tmpList.add(new Event(new StringEventType("r")));
|
---|
226 | sequencesCovered2.add(tmpList);
|
---|
227 |
|
---|
228 | int markovOrder = 2;
|
---|
229 | mockProcess = new MockTrieBasedModel(markovOrder, new Random());
|
---|
230 | mockProcess.train(sequences);
|
---|
231 | }
|
---|
232 |
|
---|
233 | public static void main(String[] args) {
|
---|
234 | new org.junit.runner.JUnitCore()
|
---|
235 | .run(CoverageCalculatorProcessTest.class);
|
---|
236 | }
|
---|
237 | } |
---|