diff options
author | 2022-09-27 02:08:44 +0200 | |
---|---|---|
committer | 2022-10-03 20:06:52 +0200 | |
commit | 7a310819cbbdd70767a9ed17e1bf84c2add9faed (patch) | |
tree | a381add842a69115d778ac902b47b40159a7feaf /subprojects/store-query-viatra/src/test/java | |
parent | refactor: remove viatra dependency from store (diff) | |
download | refinery-7a310819cbbdd70767a9ed17e1bf84c2add9faed.tar.gz refinery-7a310819cbbdd70767a9ed17e1bf84c2add9faed.tar.zst refinery-7a310819cbbdd70767a9ed17e1bf84c2add9faed.zip |
refactor: tuples in QueryableModel
Diffstat (limited to 'subprojects/store-query-viatra/src/test/java')
2 files changed, 41 insertions, 43 deletions
diff --git a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTest.java b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTest.java index 4307ab6b..d6213b02 100644 --- a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTest.java +++ b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTest.java | |||
@@ -1,7 +1,6 @@ | |||
1 | package tools.refinery.store.query.viatra.tests; | 1 | package tools.refinery.store.query.viatra.tests; |
2 | 2 | ||
3 | import org.junit.jupiter.api.Test; | 3 | import org.junit.jupiter.api.Test; |
4 | import tools.refinery.store.model.Tuple; | ||
5 | import tools.refinery.store.model.representation.Relation; | 4 | import tools.refinery.store.model.representation.Relation; |
6 | import tools.refinery.store.model.representation.TruthValue; | 5 | import tools.refinery.store.model.representation.TruthValue; |
7 | import tools.refinery.store.query.QueryableModel; | 6 | import tools.refinery.store.query.QueryableModel; |
@@ -11,6 +10,8 @@ import tools.refinery.store.query.viatra.ViatraQueryableModelStore; | |||
11 | import tools.refinery.store.query.view.FilteredRelationView; | 10 | import tools.refinery.store.query.view.FilteredRelationView; |
12 | import tools.refinery.store.query.view.KeyOnlyRelationView; | 11 | import tools.refinery.store.query.view.KeyOnlyRelationView; |
13 | import tools.refinery.store.query.view.RelationView; | 12 | import tools.refinery.store.query.view.RelationView; |
13 | import tools.refinery.store.tuple.Tuple; | ||
14 | import tools.refinery.store.tuple.TupleLike; | ||
14 | 15 | ||
15 | import java.util.*; | 16 | import java.util.*; |
16 | import java.util.stream.Stream; | 17 | import java.util.stream.Stream; |
@@ -40,15 +41,16 @@ class QueryTest { | |||
40 | 41 | ||
41 | model.flushChanges(); | 42 | model.flushChanges(); |
42 | assertEquals(2, model.countResults(predicate)); | 43 | assertEquals(2, model.countResults(predicate)); |
43 | compareMatchSets(model.allResults(predicate), Set.of(List.of(Tuple.of(0)), List.of(Tuple.of(1)))); | 44 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0), Tuple.of(1))); |
44 | } | 45 | } |
45 | 46 | ||
46 | @Test | 47 | @Test |
47 | void relationConstraintTest() { | 48 | void relationConstraintTest() { |
48 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 49 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
49 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 50 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
50 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 51 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
51 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 52 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
53 | TruthValue::must); | ||
52 | 54 | ||
53 | Variable p1 = new Variable("p1"); | 55 | Variable p1 = new Variable("p1"); |
54 | Variable p2 = new Variable("p2"); | 56 | Variable p2 = new Variable("p2"); |
@@ -78,16 +80,16 @@ class QueryTest { | |||
78 | 80 | ||
79 | model.flushChanges(); | 81 | model.flushChanges(); |
80 | assertEquals(3, model.countResults(predicate)); | 82 | assertEquals(3, model.countResults(predicate)); |
81 | compareMatchSets(model.allResults(predicate), Set.of(List.of(Tuple.of(0), Tuple.of(1)), | 83 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 1), Tuple.of(1, 0), Tuple.of(1, 2))); |
82 | List.of(Tuple.of(1), Tuple.of(0)), List.of(Tuple.of(1), Tuple.of(2)))); | ||
83 | } | 84 | } |
84 | 85 | ||
85 | @Test | 86 | @Test |
86 | void andTest() { | 87 | void andTest() { |
87 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 88 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
88 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 89 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
89 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 90 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
90 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 91 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
92 | TruthValue::must); | ||
91 | 93 | ||
92 | Variable p1 = new Variable("p1"); | 94 | Variable p1 = new Variable("p1"); |
93 | Variable p2 = new Variable("p2"); | 95 | Variable p2 = new Variable("p2"); |
@@ -120,23 +122,22 @@ class QueryTest { | |||
120 | model.put(friend, Tuple.of(1, 0), TruthValue.TRUE); | 122 | model.put(friend, Tuple.of(1, 0), TruthValue.TRUE); |
121 | model.flushChanges(); | 123 | model.flushChanges(); |
122 | assertEquals(2, model.countResults(predicate)); | 124 | assertEquals(2, model.countResults(predicate)); |
123 | compareMatchSets(model.allResults(predicate), | 125 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 1), Tuple.of(1, 0))); |
124 | Set.of(List.of(Tuple.of(0), Tuple.of(1)), List.of(Tuple.of(1), Tuple.of(0)))); | ||
125 | 126 | ||
126 | model.put(friend, Tuple.of(2, 0), TruthValue.TRUE); | 127 | model.put(friend, Tuple.of(2, 0), TruthValue.TRUE); |
127 | model.flushChanges(); | 128 | model.flushChanges(); |
128 | assertEquals(4, model.countResults(predicate)); | 129 | assertEquals(4, model.countResults(predicate)); |
129 | compareMatchSets(model.allResults(predicate), | 130 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 1), Tuple.of(1, 0), Tuple.of(0, 2), |
130 | Set.of(List.of(Tuple.of(0), Tuple.of(1)), List.of(Tuple.of(1), Tuple.of(0)), | 131 | Tuple.of(2, 0))); |
131 | List.of(Tuple.of(0), Tuple.of(2)), List.of(Tuple.of(2), Tuple.of(0)))); | ||
132 | } | 132 | } |
133 | 133 | ||
134 | @Test | 134 | @Test |
135 | void existTest() { | 135 | void existTest() { |
136 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 136 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
137 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 137 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
138 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 138 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
139 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 139 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
140 | TruthValue::must); | ||
140 | 141 | ||
141 | Variable p1 = new Variable("p1"); | 142 | Variable p1 = new Variable("p1"); |
142 | Variable p2 = new Variable("p2"); | 143 | Variable p2 = new Variable("p2"); |
@@ -166,7 +167,7 @@ class QueryTest { | |||
166 | 167 | ||
167 | model.flushChanges(); | 168 | model.flushChanges(); |
168 | assertEquals(2, model.countResults(predicate)); | 169 | assertEquals(2, model.countResults(predicate)); |
169 | compareMatchSets(model.allResults(predicate), Set.of(List.of(Tuple.of(0)), List.of(Tuple.of(1)))); | 170 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0), Tuple.of(1))); |
170 | } | 171 | } |
171 | 172 | ||
172 | @Test | 173 | @Test |
@@ -176,7 +177,8 @@ class QueryTest { | |||
176 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 177 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
177 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 178 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
178 | RelationView<Boolean> animalView = new KeyOnlyRelationView(animal); | 179 | RelationView<Boolean> animalView = new KeyOnlyRelationView(animal); |
179 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 180 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
181 | TruthValue::must); | ||
180 | 182 | ||
181 | Variable p1 = new Variable("p1"); | 183 | Variable p1 = new Variable("p1"); |
182 | Variable p2 = new Variable("p2"); | 184 | Variable p2 = new Variable("p2"); |
@@ -196,8 +198,7 @@ class QueryTest { | |||
196 | DNFAnd clause2 = new DNFAnd(Collections.emptySet(), | 198 | DNFAnd clause2 = new DNFAnd(Collections.emptySet(), |
197 | Arrays.asList(animalRelationAtom1, animalRelationAtom2, friendRelationAtom2)); | 199 | Arrays.asList(animalRelationAtom1, animalRelationAtom2, friendRelationAtom2)); |
198 | 200 | ||
199 | // No inter-species friendship | 201 | // No friendship between species |
200 | |||
201 | DNFPredicate predicate = new DNFPredicate("Or", parameters, Arrays.asList(clause1, clause2)); | 202 | DNFPredicate predicate = new DNFPredicate("Or", parameters, Arrays.asList(clause1, clause2)); |
202 | 203 | ||
203 | QueryableModelStore store = new ViatraQueryableModelStore(Set.of(person, animal, friend), | 204 | QueryableModelStore store = new ViatraQueryableModelStore(Set.of(person, animal, friend), |
@@ -215,13 +216,12 @@ class QueryTest { | |||
215 | 216 | ||
216 | model.flushChanges(); | 217 | model.flushChanges(); |
217 | assertEquals(2, model.countResults(predicate)); | 218 | assertEquals(2, model.countResults(predicate)); |
218 | compareMatchSets(model.allResults(predicate), | 219 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 1), Tuple.of(2, 3))); |
219 | Set.of(List.of(Tuple.of(0), Tuple.of(1)), List.of(Tuple.of(2), Tuple.of(3)))); | ||
220 | } | 220 | } |
221 | 221 | ||
222 | @Test | 222 | @Test |
223 | void equalityTest() { | 223 | void equalityTest() { |
224 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 224 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
225 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 225 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
226 | 226 | ||
227 | Variable p1 = new Variable("p1"); | 227 | Variable p1 = new Variable("p1"); |
@@ -244,16 +244,16 @@ class QueryTest { | |||
244 | 244 | ||
245 | model.flushChanges(); | 245 | model.flushChanges(); |
246 | assertEquals(3, model.countResults(predicate)); | 246 | assertEquals(3, model.countResults(predicate)); |
247 | compareMatchSets(model.allResults(predicate), Set.of(List.of(Tuple.of(0), Tuple.of(0)), | 247 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 0), Tuple.of(1, 1), Tuple.of(2, 2))); |
248 | List.of(Tuple.of(1), Tuple.of(1)), List.of(Tuple.of(2), Tuple.of(2)))); | ||
249 | } | 248 | } |
250 | 249 | ||
251 | @Test | 250 | @Test |
252 | void inequalityTest() { | 251 | void inequalityTest() { |
253 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 252 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
254 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 253 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
255 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 254 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
256 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 255 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
256 | TruthValue::must); | ||
257 | 257 | ||
258 | Variable p1 = new Variable("p1"); | 258 | Variable p1 = new Variable("p1"); |
259 | Variable p2 = new Variable("p2"); | 259 | Variable p2 = new Variable("p2"); |
@@ -281,16 +281,16 @@ class QueryTest { | |||
281 | 281 | ||
282 | model.flushChanges(); | 282 | model.flushChanges(); |
283 | assertEquals(2, model.countResults(predicate)); | 283 | assertEquals(2, model.countResults(predicate)); |
284 | compareMatchSets(model.allResults(predicate), | 284 | compareMatchSets(model.allResults(predicate), Set.of(Tuple.of(0, 1, 2), Tuple.of(1, 0, 2))); |
285 | Set.of(List.of(Tuple.of(0), Tuple.of(1), Tuple.of(2)), List.of(Tuple.of(1), Tuple.of(0), Tuple.of(2)))); | ||
286 | } | 285 | } |
287 | 286 | ||
288 | @Test | 287 | @Test |
289 | void patternCallTest() { | 288 | void patternCallTest() { |
290 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 289 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
291 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 290 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
292 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 291 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
293 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 292 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
293 | TruthValue::must); | ||
294 | 294 | ||
295 | Variable p1 = new Variable("p1"); | 295 | Variable p1 = new Variable("p1"); |
296 | Variable p2 = new Variable("p2"); | 296 | Variable p2 = new Variable("p2"); |
@@ -331,10 +331,11 @@ class QueryTest { | |||
331 | 331 | ||
332 | @Test | 332 | @Test |
333 | void negativePatternCallTest() { | 333 | void negativePatternCallTest() { |
334 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 334 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
335 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 335 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
336 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 336 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
337 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 337 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
338 | TruthValue::must); | ||
338 | 339 | ||
339 | Variable p1 = new Variable("p1"); | 340 | Variable p1 = new Variable("p1"); |
340 | Variable p2 = new Variable("p2"); | 341 | Variable p2 = new Variable("p2"); |
@@ -375,10 +376,11 @@ class QueryTest { | |||
375 | 376 | ||
376 | @Test | 377 | @Test |
377 | void transitivePatternCallTest() { | 378 | void transitivePatternCallTest() { |
378 | Relation<Boolean> person = new Relation<Boolean>("Person", 1, false); | 379 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
379 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 380 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
380 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | 381 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); |
381 | RelationView<TruthValue> friendMustView = new FilteredRelationView<TruthValue>(friend, (k, v) -> v.must()); | 382 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", |
383 | TruthValue::must); | ||
382 | 384 | ||
383 | Variable p1 = new Variable("p1"); | 385 | Variable p1 = new Variable("p1"); |
384 | Variable p2 = new Variable("p2"); | 386 | Variable p2 = new Variable("p2"); |
@@ -415,18 +417,14 @@ class QueryTest { | |||
415 | model.flushChanges(); | 417 | model.flushChanges(); |
416 | assertEquals(3, model.countResults(predicate)); | 418 | assertEquals(3, model.countResults(predicate)); |
417 | } | 419 | } |
418 | static void compareMatchSets(Stream<Object[]> matchSet, Set<List<Tuple>> expected) { | 420 | |
419 | Set<List<Tuple>> translatedMatchSet = new HashSet<>(); | 421 | static void compareMatchSets(Stream<TupleLike> matchSet, Set<Tuple> expected) { |
422 | Set<Tuple> translatedMatchSet = new HashSet<>(); | ||
420 | var iterator = matchSet.iterator(); | 423 | var iterator = matchSet.iterator(); |
421 | while (iterator.hasNext()) { | 424 | while (iterator.hasNext()) { |
422 | var element = iterator.next(); | 425 | var element = iterator.next(); |
423 | List<Tuple> elementToTranslatedMatchSet = new ArrayList<>(); | 426 | translatedMatchSet.add(element.toTuple()); |
424 | for (Object o : element) { | ||
425 | elementToTranslatedMatchSet.add((Tuple) o); | ||
426 | } | ||
427 | translatedMatchSet.add(elementToTranslatedMatchSet); | ||
428 | } | 427 | } |
429 | |||
430 | assertEquals(expected, translatedMatchSet); | 428 | assertEquals(expected, translatedMatchSet); |
431 | } | 429 | } |
432 | } | 430 | } |
diff --git a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTransactionTest.java b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTransactionTest.java index 613d0074..f57bca2b 100644 --- a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTransactionTest.java +++ b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTransactionTest.java | |||
@@ -1,7 +1,7 @@ | |||
1 | package tools.refinery.store.query.viatra.tests; | 1 | package tools.refinery.store.query.viatra.tests; |
2 | 2 | ||
3 | import org.junit.jupiter.api.Test; | 3 | import org.junit.jupiter.api.Test; |
4 | import tools.refinery.store.model.Tuple; | 4 | import tools.refinery.store.tuple.Tuple; |
5 | import tools.refinery.store.model.representation.Relation; | 5 | import tools.refinery.store.model.representation.Relation; |
6 | import tools.refinery.store.query.QueryableModel; | 6 | import tools.refinery.store.query.QueryableModel; |
7 | import tools.refinery.store.query.QueryableModelStore; | 7 | import tools.refinery.store.query.QueryableModelStore; |