diff options
Diffstat (limited to 'subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/FunctionalQueryTest.java')
-rw-r--r-- | subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/FunctionalQueryTest.java | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/FunctionalQueryTest.java b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/FunctionalQueryTest.java index 258127e7..7190d8f1 100644 --- a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/FunctionalQueryTest.java +++ b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/FunctionalQueryTest.java | |||
@@ -5,7 +5,7 @@ | |||
5 | */ | 5 | */ |
6 | package tools.refinery.store.query.viatra; | 6 | package tools.refinery.store.query.viatra; |
7 | 7 | ||
8 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | 8 | import tools.refinery.viatra.runtime.matchers.backend.QueryEvaluationHint; |
9 | import tools.refinery.store.map.Cursor; | 9 | import tools.refinery.store.map.Cursor; |
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; |
@@ -29,7 +29,7 @@ import static org.hamcrest.Matchers.is; | |||
29 | import static org.hamcrest.Matchers.nullValue; | 29 | import static org.hamcrest.Matchers.nullValue; |
30 | import static org.junit.jupiter.api.Assertions.assertAll; | 30 | import static org.junit.jupiter.api.Assertions.assertAll; |
31 | import static org.junit.jupiter.api.Assertions.assertThrows; | 31 | import static org.junit.jupiter.api.Assertions.assertThrows; |
32 | import static tools.refinery.store.query.literal.Literals.assume; | 32 | import static tools.refinery.store.query.literal.Literals.check; |
33 | import static tools.refinery.store.query.term.int_.IntTerms.*; | 33 | import static tools.refinery.store.query.term.int_.IntTerms.*; |
34 | import static tools.refinery.store.query.viatra.tests.QueryAssertions.assertNullableResults; | 34 | import static tools.refinery.store.query.viatra.tests.QueryAssertions.assertNullableResults; |
35 | import static tools.refinery.store.query.viatra.tests.QueryAssertions.assertResults; | 35 | import static tools.refinery.store.query.viatra.tests.QueryAssertions.assertResults; |
@@ -390,7 +390,7 @@ class FunctionalQueryTest { | |||
390 | var query = Query.of("InvalidAssume", (builder, p1) -> builder.clause(Integer.class, (x) -> List.of( | 390 | var query = Query.of("InvalidAssume", (builder, p1) -> builder.clause(Integer.class, (x) -> List.of( |
391 | personView.call(p1), | 391 | personView.call(p1), |
392 | ageView.call(p1, x), | 392 | ageView.call(p1, x), |
393 | assume(lessEq(div(constant(120), x), constant(5))) | 393 | check(lessEq(div(constant(120), x), constant(5))) |
394 | ))); | 394 | ))); |
395 | 395 | ||
396 | var store = ModelStore.builder() | 396 | var store = ModelStore.builder() |
@@ -424,6 +424,42 @@ class FunctionalQueryTest { | |||
424 | } | 424 | } |
425 | 425 | ||
426 | @QueryEngineTest | 426 | @QueryEngineTest |
427 | void multipleAssignmentTest(QueryEvaluationHint hint) { | ||
428 | var query = Query.of("MultipleAssignment", Integer.class, (builder, p1, p2, output) -> builder | ||
429 | .clause(Integer.class, Integer.class, (x1, x2) -> List.of( | ||
430 | ageView.call(p1, x1), | ||
431 | ageView.call(p2, x2), | ||
432 | output.assign(mul(x1, constant(2))), | ||
433 | output.assign(mul(x2, constant(3))) | ||
434 | ))); | ||
435 | |||
436 | var store = ModelStore.builder() | ||
437 | .symbols(age) | ||
438 | .with(ViatraModelQueryAdapter.builder() | ||
439 | .defaultHint(hint) | ||
440 | .queries(query)) | ||
441 | .build(); | ||
442 | |||
443 | var model = store.createEmptyModel(); | ||
444 | var ageInterpretation = model.getInterpretation(age); | ||
445 | var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
446 | var queryResultSet = queryEngine.getResultSet(query); | ||
447 | |||
448 | ageInterpretation.put(Tuple.of(0), 3); | ||
449 | ageInterpretation.put(Tuple.of(1), 2); | ||
450 | ageInterpretation.put(Tuple.of(2), 15); | ||
451 | ageInterpretation.put(Tuple.of(3), 10); | ||
452 | |||
453 | queryEngine.flushChanges(); | ||
454 | assertNullableResults(Map.of( | ||
455 | Tuple.of(0, 1), Optional.of(6), | ||
456 | Tuple.of(1, 0), Optional.empty(), | ||
457 | Tuple.of(2, 3), Optional.of(30), | ||
458 | Tuple.of(3, 2), Optional.empty() | ||
459 | ), queryResultSet); | ||
460 | } | ||
461 | |||
462 | @QueryEngineTest | ||
427 | void notFunctionalTest(QueryEvaluationHint hint) { | 463 | void notFunctionalTest(QueryEvaluationHint hint) { |
428 | var query = Query.of("NotFunctional", Integer.class, (builder, p1, output) -> builder.clause((p2) -> List.of( | 464 | var query = Query.of("NotFunctional", Integer.class, (builder, p1, output) -> builder.clause((p2) -> List.of( |
429 | personView.call(p1), | 465 | personView.call(p1), |