diff options
Diffstat (limited to 'subprojects/language-semantics/src/test')
-rw-r--r-- | subprojects/language-semantics/src/test/java/tools/refinery/language/semantics/model/tests/DecisionTreeTests.java | 89 |
1 files changed, 88 insertions, 1 deletions
diff --git a/subprojects/language-semantics/src/test/java/tools/refinery/language/semantics/model/tests/DecisionTreeTests.java b/subprojects/language-semantics/src/test/java/tools/refinery/language/semantics/model/tests/DecisionTreeTests.java index 5268eb8a..f171e5c7 100644 --- a/subprojects/language-semantics/src/test/java/tools/refinery/language/semantics/model/tests/DecisionTreeTests.java +++ b/subprojects/language-semantics/src/test/java/tools/refinery/language/semantics/model/tests/DecisionTreeTests.java | |||
@@ -2,14 +2,15 @@ package tools.refinery.language.semantics.model.tests; | |||
2 | 2 | ||
3 | import org.junit.jupiter.api.Test; | 3 | import org.junit.jupiter.api.Test; |
4 | import tools.refinery.language.semantics.model.internal.DecisionTree; | 4 | import tools.refinery.language.semantics.model.internal.DecisionTree; |
5 | import tools.refinery.store.tuple.Tuple; | ||
6 | import tools.refinery.store.model.representation.TruthValue; | 5 | import tools.refinery.store.model.representation.TruthValue; |
6 | import tools.refinery.store.tuple.Tuple; | ||
7 | 7 | ||
8 | import java.util.LinkedHashMap; | 8 | import java.util.LinkedHashMap; |
9 | import java.util.Map; | 9 | import java.util.Map; |
10 | 10 | ||
11 | import static org.hamcrest.MatcherAssert.assertThat; | 11 | import static org.hamcrest.MatcherAssert.assertThat; |
12 | import static org.hamcrest.Matchers.*; | 12 | import static org.hamcrest.Matchers.*; |
13 | import static org.junit.jupiter.api.Assertions.assertThrows; | ||
13 | 14 | ||
14 | class DecisionTreeTests { | 15 | class DecisionTreeTests { |
15 | @Test | 16 | @Test |
@@ -165,6 +166,25 @@ class DecisionTreeTests { | |||
165 | } | 166 | } |
166 | 167 | ||
167 | @Test | 168 | @Test |
169 | void reducedValueEmptyTest() { | ||
170 | var sut = new DecisionTree(2, TruthValue.TRUE); | ||
171 | assertThat(sut.getReducedValue(), is(TruthValue.TRUE)); | ||
172 | } | ||
173 | |||
174 | @Test | ||
175 | void reducedValueUnsetTest() { | ||
176 | var sut = new DecisionTree(2); | ||
177 | assertThat(sut.getReducedValue(), is(nullValue())); | ||
178 | } | ||
179 | |||
180 | @Test | ||
181 | void reducedValueNonEmptyTest() { | ||
182 | var sut = new DecisionTree(2, TruthValue.UNKNOWN); | ||
183 | sut.mergeValue(Tuple.of(1, 2), TruthValue.TRUE); | ||
184 | assertThat(sut.getReducedValue(), is(nullValue())); | ||
185 | } | ||
186 | |||
187 | @Test | ||
168 | void removeIntermediateChildTest() { | 188 | void removeIntermediateChildTest() { |
169 | var sut = new DecisionTree(3, TruthValue.TRUE); | 189 | var sut = new DecisionTree(3, TruthValue.TRUE); |
170 | var values = new DecisionTree(3, null); | 190 | var values = new DecisionTree(3, null); |
@@ -172,6 +192,73 @@ class DecisionTreeTests { | |||
172 | sut.overwriteValues(values); | 192 | sut.overwriteValues(values); |
173 | sut.mergeValue(Tuple.of(1, 1, 1), TruthValue.TRUE); | 193 | sut.mergeValue(Tuple.of(1, 1, 1), TruthValue.TRUE); |
174 | assertThat(sut.get(Tuple.of(1, 1, 1)), is(TruthValue.TRUE)); | 194 | assertThat(sut.get(Tuple.of(1, 1, 1)), is(TruthValue.TRUE)); |
195 | assertThat(sut.getReducedValue(), is(TruthValue.TRUE)); | ||
196 | } | ||
197 | |||
198 | @Test | ||
199 | void setMissingValueTest() { | ||
200 | var sut = new DecisionTree(2); | ||
201 | sut.setIfMissing(Tuple.of(0, 0), TruthValue.FALSE); | ||
202 | assertThat(sut.get(Tuple.of(0, 0)), is(TruthValue.FALSE)); | ||
203 | } | ||
204 | |||
205 | @Test | ||
206 | void setNotMissingValueTest() { | ||
207 | var sut = new DecisionTree(2); | ||
208 | sut.mergeValue(Tuple.of(0, 0), TruthValue.TRUE); | ||
209 | sut.setIfMissing(Tuple.of(0, 0), TruthValue.FALSE); | ||
210 | assertThat(sut.get(Tuple.of(0, 0)), is(TruthValue.TRUE)); | ||
211 | } | ||
212 | |||
213 | @Test | ||
214 | void setNotMissingDefaultValueTest() { | ||
215 | var sut = new DecisionTree(2, TruthValue.TRUE); | ||
216 | sut.setIfMissing(Tuple.of(0, 0), TruthValue.FALSE); | ||
217 | assertThat(sut.get(Tuple.of(0, 0)), is(TruthValue.TRUE)); | ||
218 | } | ||
219 | |||
220 | @Test | ||
221 | void setMissingValueWildcardTest() { | ||
222 | var sut = new DecisionTree(2); | ||
223 | sut.mergeValue(Tuple.of(-1, 0), TruthValue.TRUE); | ||
224 | sut.mergeValue(Tuple.of(1, -1), TruthValue.TRUE); | ||
225 | sut.setIfMissing(Tuple.of(0, 0), TruthValue.FALSE); | ||
226 | sut.setIfMissing(Tuple.of(1, 1), TruthValue.FALSE); | ||
227 | sut.setIfMissing(Tuple.of(2, 2), TruthValue.FALSE); | ||
228 | assertThat(sut.get(Tuple.of(0, 0)), is(TruthValue.TRUE)); | ||
229 | assertThat(sut.get(Tuple.of(1, 1)), is(TruthValue.TRUE)); | ||
230 | assertThat(sut.get(Tuple.of(2, 2)), is(TruthValue.FALSE)); | ||
231 | assertThat(sut.get(Tuple.of(2, 3)), is(nullValue())); | ||
232 | } | ||
233 | |||
234 | @Test | ||
235 | void setMissingValueInvalidTupleTest() { | ||
236 | var sut = new DecisionTree(2); | ||
237 | var tuple = Tuple.of(-1, -1); | ||
238 | assertThrows(IllegalArgumentException.class, () -> sut.setIfMissing(tuple, TruthValue.TRUE)); | ||
239 | } | ||
240 | |||
241 | @Test | ||
242 | void setAllMissingTest() { | ||
243 | var sut = new DecisionTree(2); | ||
244 | sut.mergeValue(Tuple.of(-1, 0), TruthValue.TRUE); | ||
245 | sut.mergeValue(Tuple.of(1, -1), TruthValue.TRUE); | ||
246 | sut.mergeValue(Tuple.of(2, 2), TruthValue.TRUE); | ||
247 | sut.setAllMissing(TruthValue.FALSE); | ||
248 | assertThat(sut.get(Tuple.of(0, 0)), is(TruthValue.TRUE)); | ||
249 | assertThat(sut.get(Tuple.of(2, 0)), is(TruthValue.TRUE)); | ||
250 | assertThat(sut.get(Tuple.of(1, 1)), is(TruthValue.TRUE)); | ||
251 | assertThat(sut.get(Tuple.of(1, 2)), is(TruthValue.TRUE)); | ||
252 | assertThat(sut.get(Tuple.of(2, 2)), is(TruthValue.TRUE)); | ||
253 | assertThat(sut.get(Tuple.of(2, 3)), is(TruthValue.FALSE)); | ||
254 | assertThat(sut.get(Tuple.of(3, 2)), is(TruthValue.FALSE)); | ||
255 | } | ||
256 | |||
257 | @Test | ||
258 | void setAllMissingEmptyTest() { | ||
259 | var sut = new DecisionTree(2); | ||
260 | sut.setAllMissing(TruthValue.TRUE); | ||
261 | assertThat(sut.getReducedValue(), is(TruthValue.TRUE)); | ||
175 | } | 262 | } |
176 | 263 | ||
177 | private Map<Tuple, TruthValue> iterateAll(DecisionTree sut, TruthValue defaultValue, int nodeCount) { | 264 | private Map<Tuple, TruthValue> iterateAll(DecisionTree sut, TruthValue defaultValue, int nodeCount) { |