diff options
Diffstat (limited to 'subprojects/store-query-viatra/src/test')
-rw-r--r-- | subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryTest.java | 97 |
1 files changed, 89 insertions, 8 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 8984cb2c..224df362 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 | |||
@@ -4,10 +4,7 @@ import org.junit.jupiter.api.Test; | |||
4 | import tools.refinery.store.model.representation.Relation; | 4 | import tools.refinery.store.model.representation.Relation; |
5 | import tools.refinery.store.model.representation.TruthValue; | 5 | import tools.refinery.store.model.representation.TruthValue; |
6 | import tools.refinery.store.query.*; | 6 | import tools.refinery.store.query.*; |
7 | import tools.refinery.store.query.atom.CallKind; | 7 | import tools.refinery.store.query.atom.*; |
8 | import tools.refinery.store.query.atom.EquivalenceAtom; | ||
9 | import tools.refinery.store.query.atom.DNFCallAtom; | ||
10 | import tools.refinery.store.query.atom.RelationViewAtom; | ||
11 | import tools.refinery.store.query.viatra.ViatraQueryableModelStore; | 8 | import tools.refinery.store.query.viatra.ViatraQueryableModelStore; |
12 | import tools.refinery.store.query.view.FilteredRelationView; | 9 | import tools.refinery.store.query.view.FilteredRelationView; |
13 | import tools.refinery.store.query.view.KeyOnlyRelationView; | 10 | import tools.refinery.store.query.view.KeyOnlyRelationView; |
@@ -61,7 +58,7 @@ class QueryTest { | |||
61 | .parameters(p1, p2) | 58 | .parameters(p1, p2) |
62 | .clause( | 59 | .clause( |
63 | new RelationViewAtom(personView, p1), | 60 | new RelationViewAtom(personView, p1), |
64 | new RelationViewAtom(personView, p1), | 61 | new RelationViewAtom(personView, p2), |
65 | new RelationViewAtom(friendMustView, p1, p2) | 62 | new RelationViewAtom(friendMustView, p1, p2) |
66 | ) | 63 | ) |
67 | .build(); | 64 | .build(); |
@@ -308,7 +305,7 @@ class QueryTest { | |||
308 | .clause( | 305 | .clause( |
309 | new RelationViewAtom(personView, p3), | 306 | new RelationViewAtom(personView, p3), |
310 | new RelationViewAtom(personView, p4), | 307 | new RelationViewAtom(personView, p4), |
311 | new DNFCallAtom(friendPredicate, p3, p4) | 308 | new CallAtom<>(friendPredicate, p3, p4) |
312 | ) | 309 | ) |
313 | .build(); | 310 | .build(); |
314 | 311 | ||
@@ -354,7 +351,7 @@ class QueryTest { | |||
354 | .clause( | 351 | .clause( |
355 | new RelationViewAtom(personView, p3), | 352 | new RelationViewAtom(personView, p3), |
356 | new RelationViewAtom(personView, p4), | 353 | new RelationViewAtom(personView, p4), |
357 | new DNFCallAtom(CallKind.NEGATIVE, friendPredicate, p3, p4) | 354 | new CallAtom<>(false, friendPredicate, p3, p4) |
358 | ) | 355 | ) |
359 | .build(); | 356 | .build(); |
360 | 357 | ||
@@ -374,6 +371,48 @@ class QueryTest { | |||
374 | } | 371 | } |
375 | 372 | ||
376 | @Test | 373 | @Test |
374 | void negativeWithQuantificationTest() { | ||
375 | Relation<Boolean> person = new Relation<>("Person", 1, false); | ||
376 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | ||
377 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | ||
378 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", | ||
379 | TruthValue::must); | ||
380 | |||
381 | Variable p1 = new Variable("p1"); | ||
382 | Variable p2 = new Variable("p2"); | ||
383 | |||
384 | DNF called = DNF.builder("Called") | ||
385 | .parameters(p1, p2) | ||
386 | .clause( | ||
387 | new RelationViewAtom(personView, p1), | ||
388 | new RelationViewAtom(personView, p2), | ||
389 | new RelationViewAtom(friendMustView, p1, p2) | ||
390 | ) | ||
391 | .build(); | ||
392 | |||
393 | DNF predicate = DNF.builder("Count") | ||
394 | .parameters(p1) | ||
395 | .clause( | ||
396 | new RelationViewAtom(personView, p1), | ||
397 | new CallAtom<>(false, called, p1, p2) | ||
398 | ) | ||
399 | .build(); | ||
400 | |||
401 | QueryableModelStore store = new ViatraQueryableModelStore(Set.of(person, friend), | ||
402 | Set.of(personView, friendMustView), Set.of(called, predicate)); | ||
403 | QueryableModel model = store.createModel(); | ||
404 | |||
405 | model.put(person, Tuple.of(0), true); | ||
406 | model.put(person, Tuple.of(1), true); | ||
407 | model.put(person, Tuple.of(2), true); | ||
408 | model.put(friend, Tuple.of(0, 1), TruthValue.TRUE); | ||
409 | model.put(friend, Tuple.of(0, 2), TruthValue.TRUE); | ||
410 | |||
411 | model.flushChanges(); | ||
412 | assertEquals(2, model.countResults(predicate)); | ||
413 | } | ||
414 | |||
415 | @Test | ||
377 | void transitivePatternCallTest() { | 416 | void transitivePatternCallTest() { |
378 | Relation<Boolean> person = new Relation<>("Person", 1, false); | 417 | Relation<Boolean> person = new Relation<>("Person", 1, false); |
379 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | 418 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); |
@@ -399,7 +438,7 @@ class QueryTest { | |||
399 | .clause( | 438 | .clause( |
400 | new RelationViewAtom(personView, p3), | 439 | new RelationViewAtom(personView, p3), |
401 | new RelationViewAtom(personView, p4), | 440 | new RelationViewAtom(personView, p4), |
402 | new DNFCallAtom(CallKind.TRANSITIVE, friendPredicate, p3, p4) | 441 | new CallAtom<>(BasicCallKind.TRANSITIVE, friendPredicate, p3, p4) |
403 | ) | 442 | ) |
404 | .build(); | 443 | .build(); |
405 | 444 | ||
@@ -417,6 +456,48 @@ class QueryTest { | |||
417 | assertEquals(3, model.countResults(predicate)); | 456 | assertEquals(3, model.countResults(predicate)); |
418 | } | 457 | } |
419 | 458 | ||
459 | @Test | ||
460 | void countMatchTest() { | ||
461 | Relation<Boolean> person = new Relation<>("Person", 1, false); | ||
462 | Relation<TruthValue> friend = new Relation<>("friend", 2, TruthValue.FALSE); | ||
463 | RelationView<Boolean> personView = new KeyOnlyRelationView(person); | ||
464 | RelationView<TruthValue> friendMustView = new FilteredRelationView<>(friend, "must", | ||
465 | TruthValue::must); | ||
466 | |||
467 | Variable p1 = new Variable("p1"); | ||
468 | Variable p2 = new Variable("p2"); | ||
469 | |||
470 | DNF called = DNF.builder("Called") | ||
471 | .parameters(p1, p2) | ||
472 | .clause( | ||
473 | new RelationViewAtom(personView, p1), | ||
474 | new RelationViewAtom(personView, p2), | ||
475 | new RelationViewAtom(friendMustView, p1, p2) | ||
476 | ) | ||
477 | .build(); | ||
478 | |||
479 | DNF predicate = DNF.builder("Count") | ||
480 | .parameters(p1) | ||
481 | .clause( | ||
482 | new RelationViewAtom(personView, p1), | ||
483 | new CallAtom<>(new CountCallKind(ComparisonOperator.EQUALS, 2), called, p1, p2) | ||
484 | ) | ||
485 | .build(); | ||
486 | |||
487 | QueryableModelStore store = new ViatraQueryableModelStore(Set.of(person, friend), | ||
488 | Set.of(personView, friendMustView), Set.of(called, predicate)); | ||
489 | QueryableModel model = store.createModel(); | ||
490 | |||
491 | model.put(person, Tuple.of(0), true); | ||
492 | model.put(person, Tuple.of(1), true); | ||
493 | model.put(person, Tuple.of(2), true); | ||
494 | model.put(friend, Tuple.of(0, 1), TruthValue.TRUE); | ||
495 | model.put(friend, Tuple.of(0, 2), TruthValue.TRUE); | ||
496 | |||
497 | model.flushChanges(); | ||
498 | assertEquals(1, model.countResults(predicate)); | ||
499 | } | ||
500 | |||
420 | static void compareMatchSets(Stream<TupleLike> matchSet, Set<Tuple> expected) { | 501 | static void compareMatchSets(Stream<TupleLike> matchSet, Set<Tuple> expected) { |
421 | Set<Tuple> translatedMatchSet = new HashSet<>(); | 502 | Set<Tuple> translatedMatchSet = new HashSet<>(); |
422 | var iterator = matchSet.iterator(); | 503 | var iterator = matchSet.iterator(); |