diff options
author | 2023-07-10 21:42:52 +0200 | |
---|---|---|
committer | 2023-07-15 14:37:26 +0200 | |
commit | 60e90db11d1a6898aa8b2e1d82ea647a7898f9f0 (patch) | |
tree | f0248c9b1148054357a74795bb8e9b20405fe8c9 /subprojects/store-query-viatra/src/test/java/tools | |
parent | feat: DNF rewriting (diff) | |
download | refinery-60e90db11d1a6898aa8b2e1d82ea647a7898f9f0.tar.gz refinery-60e90db11d1a6898aa8b2e1d82ea647a7898f9f0.tar.zst refinery-60e90db11d1a6898aa8b2e1d82ea647a7898f9f0.zip |
feat: query rewriters for Viatra
Diffstat (limited to 'subprojects/store-query-viatra/src/test/java/tools')
3 files changed, 51 insertions, 1 deletions
diff --git a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/DiagonalQueryTest.java b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/DiagonalQueryTest.java index 6aae2ebe..3d2d5f83 100644 --- a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/DiagonalQueryTest.java +++ b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/DiagonalQueryTest.java | |||
@@ -98,6 +98,7 @@ class DiagonalQueryTest { | |||
98 | .build(); | 98 | .build(); |
99 | 99 | ||
100 | var model = store.createEmptyModel(); | 100 | var model = store.createEmptyModel(); |
101 | |||
101 | var personInterpretation = model.getInterpretation(person); | 102 | var personInterpretation = model.getInterpretation(person); |
102 | var symbolInterpretation = model.getInterpretation(symbol); | 103 | var symbolInterpretation = model.getInterpretation(symbol); |
103 | var queryEngine = model.getAdapter(ModelQueryAdapter.class); | 104 | var queryEngine = model.getAdapter(ModelQueryAdapter.class); |
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 be05b5e6..8ecbe11a 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 | |||
@@ -9,7 +9,9 @@ import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | |||
9 | import org.junit.jupiter.api.Test; | 9 | import org.junit.jupiter.api.Test; |
10 | import tools.refinery.store.model.ModelStore; | 10 | import tools.refinery.store.model.ModelStore; |
11 | import tools.refinery.store.query.ModelQueryAdapter; | 11 | import tools.refinery.store.query.ModelQueryAdapter; |
12 | import tools.refinery.store.query.dnf.Dnf; | ||
12 | import tools.refinery.store.query.dnf.Query; | 13 | import tools.refinery.store.query.dnf.Query; |
14 | import tools.refinery.store.query.term.ParameterDirection; | ||
13 | import tools.refinery.store.query.term.Variable; | 15 | import tools.refinery.store.query.term.Variable; |
14 | import tools.refinery.store.query.viatra.tests.QueryEngineTest; | 16 | import tools.refinery.store.query.viatra.tests.QueryEngineTest; |
15 | import tools.refinery.store.query.view.AnySymbolView; | 17 | import tools.refinery.store.query.view.AnySymbolView; |
@@ -312,6 +314,53 @@ class QueryTest { | |||
312 | } | 314 | } |
313 | 315 | ||
314 | @QueryEngineTest | 316 | @QueryEngineTest |
317 | void patternCallInputArgumentTest(QueryEvaluationHint hint) { | ||
318 | var friendPredicate = Dnf.of("Friend", builder -> { | ||
319 | var p1 = builder.parameter("p1", ParameterDirection.IN); | ||
320 | var p2 = builder.parameter("p2", ParameterDirection.IN); | ||
321 | builder.clause( | ||
322 | personView.call(p1), | ||
323 | personView.call(p2), | ||
324 | friendMustView.call(p1, p2) | ||
325 | ); | ||
326 | }); | ||
327 | var predicate = Query.of("PositivePatternCall", (builder, p3, p4) -> builder.clause( | ||
328 | personView.call(p3), | ||
329 | personView.call(p4), | ||
330 | friendPredicate.call(p3, p4) | ||
331 | )); | ||
332 | |||
333 | var store = ModelStore.builder() | ||
334 | .symbols(person, friend) | ||
335 | .with(ViatraModelQueryAdapter.builder() | ||
336 | .defaultHint(hint) | ||
337 | .queries(predicate)) | ||
338 | .build(); | ||
339 | |||
340 | var model = store.createEmptyModel(); | ||
341 | var personInterpretation = model.getInterpretation(person); | ||
342 | var friendInterpretation = model.getInterpretation(friend); | ||
343 | var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
344 | var predicateResultSet = queryEngine.getResultSet(predicate); | ||
345 | |||
346 | personInterpretation.put(Tuple.of(0), true); | ||
347 | personInterpretation.put(Tuple.of(1), true); | ||
348 | personInterpretation.put(Tuple.of(2), true); | ||
349 | |||
350 | friendInterpretation.put(Tuple.of(0, 1), TruthValue.TRUE); | ||
351 | friendInterpretation.put(Tuple.of(1, 0), TruthValue.TRUE); | ||
352 | friendInterpretation.put(Tuple.of(1, 2), TruthValue.TRUE); | ||
353 | |||
354 | queryEngine.flushChanges(); | ||
355 | assertResults(Map.of( | ||
356 | Tuple.of(0, 1), true, | ||
357 | Tuple.of(1, 0), true, | ||
358 | Tuple.of(1, 2), true, | ||
359 | Tuple.of(2, 1), false | ||
360 | ), predicateResultSet); | ||
361 | } | ||
362 | |||
363 | @QueryEngineTest | ||
315 | void negativeRelationViewTest(QueryEvaluationHint hint) { | 364 | void negativeRelationViewTest(QueryEvaluationHint hint) { |
316 | var predicate = Query.of("NegativePatternCall", (builder, p1, p2) -> builder.clause( | 365 | var predicate = Query.of("NegativePatternCall", (builder, p1, p2) -> builder.clause( |
317 | personView.call(p1), | 366 | personView.call(p1), |
diff --git a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryAssertions.java b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryAssertions.java index ca089a9d..5c1c4fc1 100644 --- a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryAssertions.java +++ b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/tests/QueryAssertions.java | |||
@@ -30,7 +30,7 @@ public final class QueryAssertions { | |||
30 | } | 30 | } |
31 | 31 | ||
32 | public static <T> void assertResults(Map<Tuple, T> expected, ResultSet<T> resultSet) { | 32 | public static <T> void assertResults(Map<Tuple, T> expected, ResultSet<T> resultSet) { |
33 | var defaultValue = resultSet.getQuery().defaultValue(); | 33 | var defaultValue = resultSet.getCanonicalQuery().defaultValue(); |
34 | var filteredExpected = new LinkedHashMap<Tuple, T>(); | 34 | var filteredExpected = new LinkedHashMap<Tuple, T>(); |
35 | var executables = new ArrayList<Executable>(); | 35 | var executables = new ArrayList<Executable>(); |
36 | for (var entry : expected.entrySet()) { | 36 | for (var entry : expected.entrySet()) { |