diff options
author | 2023-02-09 18:18:03 +0100 | |
---|---|---|
committer | 2023-02-09 18:22:08 +0100 | |
commit | 1f8a0c703b7c221e09333cca3208a084e0109269 (patch) | |
tree | fc9c8bf942b4a4fc6d08e667f2a602f9cecbad99 /subprojects/store-query-viatra/src/test | |
parent | refactor: Atom -> Literal naming convention (diff) | |
download | refinery-1f8a0c703b7c221e09333cca3208a084e0109269.tar.gz refinery-1f8a0c703b7c221e09333cca3208a084e0109269.tar.zst refinery-1f8a0c703b7c221e09333cca3208a084e0109269.zip |
refactor: EDSL for DNF literals
Diffstat (limited to 'subprojects/store-query-viatra/src/test')
2 files changed, 58 insertions, 62 deletions
diff --git a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTest.java b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTest.java index 471fdfc9..6a3a62e3 100644 --- a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTest.java +++ b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTest.java | |||
@@ -5,10 +5,6 @@ import tools.refinery.store.model.ModelStore; | |||
5 | import tools.refinery.store.query.Dnf; | 5 | import tools.refinery.store.query.Dnf; |
6 | import tools.refinery.store.query.ModelQuery; | 6 | import tools.refinery.store.query.ModelQuery; |
7 | import tools.refinery.store.query.Variable; | 7 | import tools.refinery.store.query.Variable; |
8 | import tools.refinery.store.query.literal.CallPolarity; | ||
9 | import tools.refinery.store.query.literal.DnfCallLiteral; | ||
10 | import tools.refinery.store.query.literal.EquivalenceLiteral; | ||
11 | import tools.refinery.store.query.literal.RelationViewLiteral; | ||
12 | import tools.refinery.store.query.view.FilteredRelationView; | 8 | import tools.refinery.store.query.view.FilteredRelationView; |
13 | import tools.refinery.store.query.view.KeyOnlyRelationView; | 9 | import tools.refinery.store.query.view.KeyOnlyRelationView; |
14 | import tools.refinery.store.representation.Symbol; | 10 | import tools.refinery.store.representation.Symbol; |
@@ -21,6 +17,7 @@ import java.util.Set; | |||
21 | import java.util.stream.Stream; | 17 | import java.util.stream.Stream; |
22 | 18 | ||
23 | import static org.junit.jupiter.api.Assertions.assertEquals; | 19 | import static org.junit.jupiter.api.Assertions.assertEquals; |
20 | import static tools.refinery.store.query.literal.Literals.not; | ||
24 | 21 | ||
25 | class QueryTest { | 22 | class QueryTest { |
26 | @Test | 23 | @Test |
@@ -32,7 +29,7 @@ class QueryTest { | |||
32 | var p1 = new Variable("p1"); | 29 | var p1 = new Variable("p1"); |
33 | var predicate = Dnf.builder("TypeConstraint") | 30 | var predicate = Dnf.builder("TypeConstraint") |
34 | .parameters(p1) | 31 | .parameters(p1) |
35 | .clause(new RelationViewLiteral(personView, p1)) | 32 | .clause(personView.call(p1)) |
36 | .build(); | 33 | .build(); |
37 | 34 | ||
38 | var store = ModelStore.builder() | 35 | var store = ModelStore.builder() |
@@ -70,9 +67,9 @@ class QueryTest { | |||
70 | var predicate = Dnf.builder("RelationConstraint") | 67 | var predicate = Dnf.builder("RelationConstraint") |
71 | .parameters(p1, p2) | 68 | .parameters(p1, p2) |
72 | .clause( | 69 | .clause( |
73 | new RelationViewLiteral(personView, p1), | 70 | personView.call(p1), |
74 | new RelationViewLiteral(personView, p2), | 71 | personView.call(p2), |
75 | new RelationViewLiteral(friendMustView, p1, p2) | 72 | friendMustView.call(p1, p2) |
76 | ) | 73 | ) |
77 | .build(); | 74 | .build(); |
78 | 75 | ||
@@ -117,10 +114,10 @@ class QueryTest { | |||
117 | var predicate = Dnf.builder("RelationConstraint") | 114 | var predicate = Dnf.builder("RelationConstraint") |
118 | .parameters(p1, p2) | 115 | .parameters(p1, p2) |
119 | .clause( | 116 | .clause( |
120 | new RelationViewLiteral(personView, p1), | 117 | personView.call(p1), |
121 | new RelationViewLiteral(personView, p2), | 118 | personView.call(p2), |
122 | new RelationViewLiteral(friendMustView, p1, p2), | 119 | friendMustView.call(p1, p2), |
123 | new RelationViewLiteral(friendMustView, p2, p1) | 120 | friendMustView.call(p2, p1) |
124 | ) | 121 | ) |
125 | .build(); | 122 | .build(); |
126 | 123 | ||
@@ -172,9 +169,9 @@ class QueryTest { | |||
172 | var predicate = Dnf.builder("RelationConstraint") | 169 | var predicate = Dnf.builder("RelationConstraint") |
173 | .parameters(p1) | 170 | .parameters(p1) |
174 | .clause( | 171 | .clause( |
175 | new RelationViewLiteral(personView, p1), | 172 | personView.call(p1), |
176 | new RelationViewLiteral(personView, p2), | 173 | personView.call(p2), |
177 | new RelationViewLiteral(friendMustView, p1, p2) | 174 | friendMustView.call(p1, p2) |
178 | ) | 175 | ) |
179 | .build(); | 176 | .build(); |
180 | 177 | ||
@@ -219,14 +216,14 @@ class QueryTest { | |||
219 | var predicate = Dnf.builder("Or") | 216 | var predicate = Dnf.builder("Or") |
220 | .parameters(p1, p2) | 217 | .parameters(p1, p2) |
221 | .clause( | 218 | .clause( |
222 | new RelationViewLiteral(personView, p1), | 219 | personView.call(p1), |
223 | new RelationViewLiteral(personView, p2), | 220 | personView.call(p2), |
224 | new RelationViewLiteral(friendMustView, p1, p2) | 221 | friendMustView.call(p1, p2) |
225 | ) | 222 | ) |
226 | .clause( | 223 | .clause( |
227 | new RelationViewLiteral(animalView, p1), | 224 | animalView.call(p1), |
228 | new RelationViewLiteral(animalView, p2), | 225 | animalView.call(p2), |
229 | new RelationViewLiteral(friendMustView, p1, p2) | 226 | friendMustView.call(p1, p2) |
230 | ) | 227 | ) |
231 | .build(); | 228 | .build(); |
232 | 229 | ||
@@ -269,9 +266,9 @@ class QueryTest { | |||
269 | var predicate = Dnf.builder("Equality") | 266 | var predicate = Dnf.builder("Equality") |
270 | .parameters(p1, p2) | 267 | .parameters(p1, p2) |
271 | .clause( | 268 | .clause( |
272 | new RelationViewLiteral(personView, p1), | 269 | personView.call(p1), |
273 | new RelationViewLiteral(personView, p2), | 270 | personView.call(p2), |
274 | new EquivalenceLiteral(p1, p2) | 271 | p1.isEquivalent(p2) |
275 | ) | 272 | ) |
276 | .build(); | 273 | .build(); |
277 | 274 | ||
@@ -308,11 +305,11 @@ class QueryTest { | |||
308 | var predicate = Dnf.builder("Inequality") | 305 | var predicate = Dnf.builder("Inequality") |
309 | .parameters(p1, p2, p3) | 306 | .parameters(p1, p2, p3) |
310 | .clause( | 307 | .clause( |
311 | new RelationViewLiteral(personView, p1), | 308 | personView.call(p1), |
312 | new RelationViewLiteral(personView, p2), | 309 | personView.call(p2), |
313 | new RelationViewLiteral(friendMustView, p1, p3), | 310 | friendMustView.call(p1, p3), |
314 | new RelationViewLiteral(friendMustView, p2, p3), | 311 | friendMustView.call(p2, p3), |
315 | new EquivalenceLiteral(false, p1, p2) | 312 | p1.notEquivalent(p2) |
316 | ) | 313 | ) |
317 | .build(); | 314 | .build(); |
318 | 315 | ||
@@ -352,9 +349,9 @@ class QueryTest { | |||
352 | var friendPredicate = Dnf.builder("RelationConstraint") | 349 | var friendPredicate = Dnf.builder("RelationConstraint") |
353 | .parameters(p1, p2) | 350 | .parameters(p1, p2) |
354 | .clause( | 351 | .clause( |
355 | new RelationViewLiteral(personView, p1), | 352 | personView.call(p1), |
356 | new RelationViewLiteral(personView, p2), | 353 | personView.call(p2), |
357 | new RelationViewLiteral(friendMustView, p1, p2) | 354 | friendMustView.call(p1, p2) |
358 | ) | 355 | ) |
359 | .build(); | 356 | .build(); |
360 | 357 | ||
@@ -363,9 +360,9 @@ class QueryTest { | |||
363 | var predicate = Dnf.builder("PositivePatternCall") | 360 | var predicate = Dnf.builder("PositivePatternCall") |
364 | .parameters(p3, p4) | 361 | .parameters(p3, p4) |
365 | .clause( | 362 | .clause( |
366 | new RelationViewLiteral(personView, p3), | 363 | personView.call(p3), |
367 | new RelationViewLiteral(personView, p4), | 364 | personView.call(p4), |
368 | new DnfCallLiteral(friendPredicate, p3, p4) | 365 | friendPredicate.call(p3, p4) |
369 | ) | 366 | ) |
370 | .build(); | 367 | .build(); |
371 | 368 | ||
@@ -405,9 +402,9 @@ class QueryTest { | |||
405 | var predicate = Dnf.builder("NegativePatternCall") | 402 | var predicate = Dnf.builder("NegativePatternCall") |
406 | .parameters(p1, p2) | 403 | .parameters(p1, p2) |
407 | .clause( | 404 | .clause( |
408 | new RelationViewLiteral(personView, p1), | 405 | personView.call(p1), |
409 | new RelationViewLiteral(personView, p2), | 406 | personView.call(p2), |
410 | new RelationViewLiteral(false, friendMustView, p1, p2) | 407 | not(friendMustView.call(p1, p2)) |
411 | ) | 408 | ) |
412 | .build(); | 409 | .build(); |
413 | 410 | ||
@@ -447,9 +444,9 @@ class QueryTest { | |||
447 | var friendPredicate = Dnf.builder("RelationConstraint") | 444 | var friendPredicate = Dnf.builder("RelationConstraint") |
448 | .parameters(p1, p2) | 445 | .parameters(p1, p2) |
449 | .clause( | 446 | .clause( |
450 | new RelationViewLiteral(personView, p1), | 447 | personView.call(p1), |
451 | new RelationViewLiteral(personView, p2), | 448 | personView.call(p2), |
452 | new RelationViewLiteral(friendMustView, p1, p2) | 449 | friendMustView.call(p1, p2) |
453 | ) | 450 | ) |
454 | .build(); | 451 | .build(); |
455 | 452 | ||
@@ -458,9 +455,9 @@ class QueryTest { | |||
458 | var predicate = Dnf.builder("NegativePatternCall") | 455 | var predicate = Dnf.builder("NegativePatternCall") |
459 | .parameters(p3, p4) | 456 | .parameters(p3, p4) |
460 | .clause( | 457 | .clause( |
461 | new RelationViewLiteral(personView, p3), | 458 | personView.call(p3), |
462 | new RelationViewLiteral(personView, p4), | 459 | personView.call(p4), |
463 | new DnfCallLiteral(false, friendPredicate, p3, p4) | 460 | not(friendPredicate.call(p3, p4)) |
464 | ) | 461 | ) |
465 | .build(); | 462 | .build(); |
466 | 463 | ||
@@ -501,8 +498,8 @@ class QueryTest { | |||
501 | var predicate = Dnf.builder("Count") | 498 | var predicate = Dnf.builder("Count") |
502 | .parameters(p1) | 499 | .parameters(p1) |
503 | .clause( | 500 | .clause( |
504 | new RelationViewLiteral(personView, p1), | 501 | personView.call(p1), |
505 | new RelationViewLiteral(false, friendMustView, p1, p2) | 502 | not(friendMustView.call(p1, p2)) |
506 | ) | 503 | ) |
507 | .build(); | 504 | .build(); |
508 | 505 | ||
@@ -542,17 +539,17 @@ class QueryTest { | |||
542 | var called = Dnf.builder("Called") | 539 | var called = Dnf.builder("Called") |
543 | .parameters(p1, p2) | 540 | .parameters(p1, p2) |
544 | .clause( | 541 | .clause( |
545 | new RelationViewLiteral(personView, p1), | 542 | personView.call(p1), |
546 | new RelationViewLiteral(personView, p2), | 543 | personView.call(p2), |
547 | new RelationViewLiteral(friendMustView, p1, p2) | 544 | friendMustView.call(p1, p2) |
548 | ) | 545 | ) |
549 | .build(); | 546 | .build(); |
550 | 547 | ||
551 | var predicate = Dnf.builder("Count") | 548 | var predicate = Dnf.builder("Count") |
552 | .parameters(p1) | 549 | .parameters(p1) |
553 | .clause( | 550 | .clause( |
554 | new RelationViewLiteral(personView, p1), | 551 | personView.call(p1), |
555 | new DnfCallLiteral(false, called, p1, p2) | 552 | not(called.call(p1, p2)) |
556 | ) | 553 | ) |
557 | .build(); | 554 | .build(); |
558 | 555 | ||
@@ -591,9 +588,9 @@ class QueryTest { | |||
591 | var predicate = Dnf.builder("TransitivePatternCall") | 588 | var predicate = Dnf.builder("TransitivePatternCall") |
592 | .parameters(p1, p2) | 589 | .parameters(p1, p2) |
593 | .clause( | 590 | .clause( |
594 | new RelationViewLiteral(personView, p1), | 591 | personView.call(p1), |
595 | new RelationViewLiteral(personView, p2), | 592 | personView.call(p2), |
596 | new RelationViewLiteral(CallPolarity.TRANSITIVE, friendMustView, p1, p2) | 593 | friendMustView.callTransitive(p1, p2) |
597 | ) | 594 | ) |
598 | .build(); | 595 | .build(); |
599 | 596 | ||
@@ -632,9 +629,9 @@ class QueryTest { | |||
632 | var friendPredicate = Dnf.builder("RelationConstraint") | 629 | var friendPredicate = Dnf.builder("RelationConstraint") |
633 | .parameters(p1, p2) | 630 | .parameters(p1, p2) |
634 | .clause( | 631 | .clause( |
635 | new RelationViewLiteral(personView, p1), | 632 | personView.call(p1), |
636 | new RelationViewLiteral(personView, p2), | 633 | personView.call(p2), |
637 | new RelationViewLiteral(friendMustView, p1, p2) | 634 | friendMustView.call(p1, p2) |
638 | ) | 635 | ) |
639 | .build(); | 636 | .build(); |
640 | 637 | ||
@@ -643,9 +640,9 @@ class QueryTest { | |||
643 | var predicate = Dnf.builder("TransitivePatternCall") | 640 | var predicate = Dnf.builder("TransitivePatternCall") |
644 | .parameters(p3, p4) | 641 | .parameters(p3, p4) |
645 | .clause( | 642 | .clause( |
646 | new RelationViewLiteral(personView, p3), | 643 | personView.call(p3), |
647 | new RelationViewLiteral(personView, p4), | 644 | personView.call(p4), |
648 | new DnfCallLiteral(CallPolarity.TRANSITIVE, friendPredicate, p3, p4) | 645 | friendPredicate.callTransitive(p3, p4) |
649 | ) | 646 | ) |
650 | .build(); | 647 | .build(); |
651 | 648 | ||
diff --git a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTransactionTest.java b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTransactionTest.java index 99b942d2..461685b5 100644 --- a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTransactionTest.java +++ b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/QueryTransactionTest.java | |||
@@ -5,7 +5,6 @@ import tools.refinery.store.model.ModelStore; | |||
5 | import tools.refinery.store.query.Dnf; | 5 | import tools.refinery.store.query.Dnf; |
6 | import tools.refinery.store.query.ModelQuery; | 6 | import tools.refinery.store.query.ModelQuery; |
7 | import tools.refinery.store.query.Variable; | 7 | import tools.refinery.store.query.Variable; |
8 | import tools.refinery.store.query.literal.RelationViewLiteral; | ||
9 | import tools.refinery.store.query.view.KeyOnlyRelationView; | 8 | import tools.refinery.store.query.view.KeyOnlyRelationView; |
10 | import tools.refinery.store.representation.Symbol; | 9 | import tools.refinery.store.representation.Symbol; |
11 | import tools.refinery.store.tuple.Tuple; | 10 | import tools.refinery.store.tuple.Tuple; |
@@ -22,7 +21,7 @@ class QueryTransactionTest { | |||
22 | var p1 = new Variable("p1"); | 21 | var p1 = new Variable("p1"); |
23 | var predicate = Dnf.builder("TypeConstraint") | 22 | var predicate = Dnf.builder("TypeConstraint") |
24 | .parameters(p1) | 23 | .parameters(p1) |
25 | .clause(new RelationViewLiteral(personView, p1)) | 24 | .clause(personView.call(p1)) |
26 | .build(); | 25 | .build(); |
27 | 26 | ||
28 | var store = ModelStore.builder() | 27 | var store = ModelStore.builder() |