diff options
author | 2023-04-23 23:39:39 +0200 | |
---|---|---|
committer | 2023-04-23 23:42:53 +0200 | |
commit | 565de1cb116e5e4f116544aaa035be58336656ec (patch) | |
tree | 5d4cff8e77e280552f13b9c7f8aafa79a39a0090 /subprojects/store-query-viatra/src/test | |
parent | refactor: simplify ModelAdapter (diff) | |
download | refinery-565de1cb116e5e4f116544aaa035be58336656ec.tar.gz refinery-565de1cb116e5e4f116544aaa035be58336656ec.tar.zst refinery-565de1cb116e5e4f116544aaa035be58336656ec.zip |
refactor: query terms
* Separate different operators into different classes to make it easier to add
functionality (e.g., simplification) later.
* Add UpperCardinality terms.
* Move UpperCardinality aggregator and tests into refinery-store-query.
Diffstat (limited to 'subprojects/store-query-viatra/src/test')
2 files changed, 0 insertions, 148 deletions
diff --git a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/internal/cardinality/UpperCardinalitySumAggregationOperatorStreamTest.java b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/internal/cardinality/UpperCardinalitySumAggregationOperatorStreamTest.java deleted file mode 100644 index 53d03cbd..00000000 --- a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/internal/cardinality/UpperCardinalitySumAggregationOperatorStreamTest.java +++ /dev/null | |||
@@ -1,56 +0,0 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.query.viatra.internal.cardinality; | ||
7 | |||
8 | import org.junit.jupiter.params.ParameterizedTest; | ||
9 | import org.junit.jupiter.params.provider.Arguments; | ||
10 | import org.junit.jupiter.params.provider.MethodSource; | ||
11 | import tools.refinery.store.representation.cardinality.UpperCardinalities; | ||
12 | import tools.refinery.store.representation.cardinality.UpperCardinality; | ||
13 | |||
14 | import java.util.List; | ||
15 | import java.util.stream.Stream; | ||
16 | |||
17 | import static org.hamcrest.MatcherAssert.assertThat; | ||
18 | import static org.hamcrest.Matchers.equalTo; | ||
19 | |||
20 | class UpperCardinalitySumAggregationOperatorStreamTest { | ||
21 | @ParameterizedTest | ||
22 | @MethodSource | ||
23 | void testStream(List<UpperCardinality> list, UpperCardinality expected) { | ||
24 | var result = UpperCardinalitySumAggregationOperator.INSTANCE.aggregateStream(list.stream()); | ||
25 | assertThat(result, equalTo(expected)); | ||
26 | } | ||
27 | |||
28 | static Stream<Arguments> testStream() { | ||
29 | return Stream.of( | ||
30 | Arguments.of(List.of(), UpperCardinalities.ZERO), | ||
31 | Arguments.of(List.of(UpperCardinality.of(3)), UpperCardinality.of(3)), | ||
32 | Arguments.of( | ||
33 | List.of( | ||
34 | UpperCardinality.of(2), | ||
35 | UpperCardinality.of(3) | ||
36 | ), | ||
37 | UpperCardinality.of(5) | ||
38 | ), | ||
39 | Arguments.of(List.of(UpperCardinalities.UNBOUNDED), UpperCardinalities.UNBOUNDED), | ||
40 | Arguments.of( | ||
41 | List.of( | ||
42 | UpperCardinalities.UNBOUNDED, | ||
43 | UpperCardinalities.UNBOUNDED | ||
44 | ), | ||
45 | UpperCardinalities.UNBOUNDED | ||
46 | ), | ||
47 | Arguments.of( | ||
48 | List.of( | ||
49 | UpperCardinalities.UNBOUNDED, | ||
50 | UpperCardinality.of(3) | ||
51 | ), | ||
52 | UpperCardinalities.UNBOUNDED | ||
53 | ) | ||
54 | ); | ||
55 | } | ||
56 | } | ||
diff --git a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/internal/cardinality/UpperCardinalitySumAggregationOperatorTest.java b/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/internal/cardinality/UpperCardinalitySumAggregationOperatorTest.java deleted file mode 100644 index 677eeeac..00000000 --- a/subprojects/store-query-viatra/src/test/java/tools/refinery/store/query/viatra/internal/cardinality/UpperCardinalitySumAggregationOperatorTest.java +++ /dev/null | |||
@@ -1,92 +0,0 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.query.viatra.internal.cardinality; | ||
7 | |||
8 | import org.junit.jupiter.api.BeforeEach; | ||
9 | import org.junit.jupiter.api.Test; | ||
10 | import tools.refinery.store.representation.cardinality.UpperCardinalities; | ||
11 | import tools.refinery.store.representation.cardinality.UpperCardinality; | ||
12 | |||
13 | import static org.hamcrest.MatcherAssert.assertThat; | ||
14 | import static org.hamcrest.Matchers.equalTo; | ||
15 | |||
16 | class UpperCardinalitySumAggregationOperatorTest { | ||
17 | private UpperCardinalitySumAggregationOperator.Accumulator accumulator; | ||
18 | |||
19 | @BeforeEach | ||
20 | void beforeEach() { | ||
21 | accumulator = UpperCardinalitySumAggregationOperator.INSTANCE.createNeutral(); | ||
22 | } | ||
23 | |||
24 | @Test | ||
25 | void emptyAggregationTest() { | ||
26 | assertResult(UpperCardinality.of(0)); | ||
27 | } | ||
28 | |||
29 | @Test | ||
30 | void singleBoundedTest() { | ||
31 | insert(UpperCardinality.of(3)); | ||
32 | assertResult(UpperCardinality.of(3)); | ||
33 | } | ||
34 | |||
35 | @Test | ||
36 | void multipleBoundedTest() { | ||
37 | insert(UpperCardinality.of(2)); | ||
38 | insert(UpperCardinality.of(3)); | ||
39 | assertResult(UpperCardinality.of(5)); | ||
40 | } | ||
41 | |||
42 | @Test | ||
43 | void singleUnboundedTest() { | ||
44 | insert(UpperCardinalities.UNBOUNDED); | ||
45 | assertResult(UpperCardinalities.UNBOUNDED); | ||
46 | } | ||
47 | |||
48 | @Test | ||
49 | void multipleUnboundedTest() { | ||
50 | insert(UpperCardinalities.UNBOUNDED); | ||
51 | insert(UpperCardinalities.UNBOUNDED); | ||
52 | assertResult(UpperCardinalities.UNBOUNDED); | ||
53 | } | ||
54 | |||
55 | @Test | ||
56 | void removeBoundedTest() { | ||
57 | insert(UpperCardinality.of(2)); | ||
58 | insert(UpperCardinality.of(3)); | ||
59 | remove(UpperCardinality.of(2)); | ||
60 | assertResult(UpperCardinality.of(3)); | ||
61 | } | ||
62 | |||
63 | @Test | ||
64 | void removeAllUnboundedTest() { | ||
65 | insert(UpperCardinalities.UNBOUNDED); | ||
66 | insert(UpperCardinality.of(3)); | ||
67 | remove(UpperCardinalities.UNBOUNDED); | ||
68 | assertResult(UpperCardinality.of(3)); | ||
69 | } | ||
70 | |||
71 | @Test | ||
72 | void removeSomeUnboundedTest() { | ||
73 | insert(UpperCardinalities.UNBOUNDED); | ||
74 | insert(UpperCardinalities.UNBOUNDED); | ||
75 | insert(UpperCardinality.of(3)); | ||
76 | remove(UpperCardinalities.UNBOUNDED); | ||
77 | assertResult(UpperCardinalities.UNBOUNDED); | ||
78 | } | ||
79 | |||
80 | private void insert(UpperCardinality value) { | ||
81 | accumulator = UpperCardinalitySumAggregationOperator.INSTANCE.update(accumulator, value, true); | ||
82 | } | ||
83 | |||
84 | private void remove(UpperCardinality value) { | ||
85 | accumulator = UpperCardinalitySumAggregationOperator.INSTANCE.update(accumulator, value, false); | ||
86 | } | ||
87 | |||
88 | private void assertResult(UpperCardinality expected) { | ||
89 | var result = UpperCardinalitySumAggregationOperator.INSTANCE.getAggregate(accumulator); | ||
90 | assertThat(result, equalTo(expected)); | ||
91 | } | ||
92 | } | ||