diff options
Diffstat (limited to 'subprojects/store-reasoning-scope/src/test/java/tools/refinery/store/reasoning/scope/MultiObjectTest.java')
-rw-r--r-- | subprojects/store-reasoning-scope/src/test/java/tools/refinery/store/reasoning/scope/MultiObjectTest.java | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/subprojects/store-reasoning-scope/src/test/java/tools/refinery/store/reasoning/scope/MultiObjectTest.java b/subprojects/store-reasoning-scope/src/test/java/tools/refinery/store/reasoning/scope/MultiObjectTest.java index 5fc70ae1..0132b3f9 100644 --- a/subprojects/store-reasoning-scope/src/test/java/tools/refinery/store/reasoning/scope/MultiObjectTest.java +++ b/subprojects/store-reasoning-scope/src/test/java/tools/refinery/store/reasoning/scope/MultiObjectTest.java | |||
@@ -27,11 +27,13 @@ import tools.refinery.store.tuple.Tuple; | |||
27 | 27 | ||
28 | import static org.hamcrest.MatcherAssert.assertThat; | 28 | import static org.hamcrest.MatcherAssert.assertThat; |
29 | import static org.hamcrest.Matchers.is; | 29 | import static org.hamcrest.Matchers.is; |
30 | import static org.junit.jupiter.api.Assertions.assertThrows; | ||
30 | 31 | ||
31 | class MultiObjectTest { | 32 | class MultiObjectTest { |
32 | private static final PartialRelation person = new PartialRelation("Person", 1); | 33 | private static final PartialRelation person = new PartialRelation("Person", 1); |
33 | 34 | ||
34 | private ModelStore store; | 35 | private ModelStore store; |
36 | private ReasoningStoreAdapter reasoningStoreAdapter; | ||
35 | private Model model; | 37 | private Model model; |
36 | private Interpretation<CardinalityInterval> countStorage; | 38 | private Interpretation<CardinalityInterval> countStorage; |
37 | 39 | ||
@@ -47,6 +49,7 @@ class MultiObjectTest { | |||
47 | .with(new ScopePropagator() | 49 | .with(new ScopePropagator() |
48 | .scope(person, CardinalityIntervals.between(5, 15))) | 50 | .scope(person, CardinalityIntervals.between(5, 15))) |
49 | .build(); | 51 | .build(); |
52 | reasoningStoreAdapter = store.getAdapter(ReasoningStoreAdapter.class); | ||
50 | model = null; | 53 | model = null; |
51 | countStorage = null; | 54 | countStorage = null; |
52 | } | 55 | } |
@@ -59,7 +62,6 @@ class MultiObjectTest { | |||
59 | .put(Tuple.of(0), CardinalityIntervals.SET)) | 62 | .put(Tuple.of(0), CardinalityIntervals.SET)) |
60 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) | 63 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) |
61 | .build()); | 64 | .build()); |
62 | assertThat(propagate(), is(PropagationResult.PROPAGATED)); | ||
63 | assertThat(countStorage.get(Tuple.of(0)), is(CardinalityIntervals.between(2, 12))); | 65 | assertThat(countStorage.get(Tuple.of(0)), is(CardinalityIntervals.between(2, 12))); |
64 | } | 66 | } |
65 | 67 | ||
@@ -71,19 +73,18 @@ class MultiObjectTest { | |||
71 | .put(Tuple.of(0), CardinalityIntervals.between(5, 20))) | 73 | .put(Tuple.of(0), CardinalityIntervals.between(5, 20))) |
72 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) | 74 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) |
73 | .build()); | 75 | .build()); |
74 | assertThat(propagate(), is(PropagationResult.PROPAGATED)); | ||
75 | assertThat(countStorage.get(Tuple.of(0)), is(CardinalityIntervals.between(5, 12))); | 76 | assertThat(countStorage.get(Tuple.of(0)), is(CardinalityIntervals.between(5, 12))); |
76 | } | 77 | } |
77 | 78 | ||
78 | @Test | 79 | @Test |
79 | void oneMultiObjectUnsatisfiableUpperTest() { | 80 | void oneMultiObjectUnsatisfiableUpperTest() { |
80 | createModel(ModelSeed.builder(21) | 81 | var seed = ModelSeed.builder(21) |
81 | .seed(MultiObjectTranslator.COUNT_SYMBOL, builder -> builder | 82 | .seed(MultiObjectTranslator.COUNT_SYMBOL, builder -> builder |
82 | .reducedValue(CardinalityIntervals.ONE) | 83 | .reducedValue(CardinalityIntervals.ONE) |
83 | .put(Tuple.of(0), CardinalityIntervals.SET)) | 84 | .put(Tuple.of(0), CardinalityIntervals.SET)) |
84 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) | 85 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) |
85 | .build()); | 86 | .build(); |
86 | assertThat(propagate(), is(PropagationResult.REJECTED)); | 87 | assertThrows(IllegalArgumentException.class, () -> reasoningStoreAdapter.createInitialModel(seed)); |
87 | } | 88 | } |
88 | 89 | ||
89 | @Test | 90 | @Test |
@@ -97,33 +98,33 @@ class MultiObjectTest { | |||
97 | 98 | ||
98 | @Test | 99 | @Test |
99 | void noMultiObjectUnsatisfiableTest() { | 100 | void noMultiObjectUnsatisfiableTest() { |
100 | createModel(ModelSeed.builder(2) | 101 | var seed = ModelSeed.builder(2) |
101 | .seed(MultiObjectTranslator.COUNT_SYMBOL, builder -> builder.reducedValue(CardinalityIntervals.ONE)) | 102 | .seed(MultiObjectTranslator.COUNT_SYMBOL, builder -> builder.reducedValue(CardinalityIntervals.ONE)) |
102 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) | 103 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) |
103 | .build()); | 104 | .build(); |
104 | assertThat(propagate(), is(PropagationResult.REJECTED)); | 105 | assertThrows(IllegalArgumentException.class, () -> reasoningStoreAdapter.createInitialModel(seed)); |
105 | } | 106 | } |
106 | 107 | ||
107 | @Test | 108 | @Test |
108 | void oneMultiObjectExistingBoundUnsatisfiableLowerTest() { | 109 | void oneMultiObjectExistingBoundUnsatisfiableLowerTest() { |
109 | createModel(ModelSeed.builder(4) | 110 | var seed = ModelSeed.builder(4) |
110 | .seed(MultiObjectTranslator.COUNT_SYMBOL, builder -> builder | 111 | .seed(MultiObjectTranslator.COUNT_SYMBOL, builder -> builder |
111 | .reducedValue(CardinalityIntervals.ONE) | 112 | .reducedValue(CardinalityIntervals.ONE) |
112 | .put(Tuple.of(0), CardinalityIntervals.atLeast(20))) | 113 | .put(Tuple.of(0), CardinalityIntervals.atLeast(20))) |
113 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) | 114 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) |
114 | .build()); | 115 | .build(); |
115 | assertThat(propagate(), is(PropagationResult.REJECTED)); | 116 | assertThrows(IllegalArgumentException.class, () -> reasoningStoreAdapter.createInitialModel(seed)); |
116 | } | 117 | } |
117 | 118 | ||
118 | @Test | 119 | @Test |
119 | void oneMultiObjectExistingBoundUnsatisfiableUpperTest() { | 120 | void oneMultiObjectExistingBoundUnsatisfiableUpperTest() { |
120 | createModel(ModelSeed.builder(4) | 121 | var seed = ModelSeed.builder(4) |
121 | .seed(MultiObjectTranslator.COUNT_SYMBOL, builder -> builder | 122 | .seed(MultiObjectTranslator.COUNT_SYMBOL, builder -> builder |
122 | .reducedValue(CardinalityIntervals.ONE) | 123 | .reducedValue(CardinalityIntervals.ONE) |
123 | .put(Tuple.of(0), CardinalityIntervals.atMost(1))) | 124 | .put(Tuple.of(0), CardinalityIntervals.atMost(1))) |
124 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) | 125 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) |
125 | .build()); | 126 | .build(); |
126 | assertThat(propagate(), is(PropagationResult.REJECTED)); | 127 | assertThrows(IllegalArgumentException.class, () -> reasoningStoreAdapter.createInitialModel(seed)); |
127 | } | 128 | } |
128 | 129 | ||
129 | @Test | 130 | @Test |
@@ -135,7 +136,6 @@ class MultiObjectTest { | |||
135 | .put(Tuple.of(1), CardinalityIntervals.SET)) | 136 | .put(Tuple.of(1), CardinalityIntervals.SET)) |
136 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) | 137 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) |
137 | .build()); | 138 | .build()); |
138 | assertThat(propagate(), is(PropagationResult.PROPAGATED)); | ||
139 | assertThat(countStorage.get(Tuple.of(0)), is(CardinalityIntervals.atMost(12))); | 139 | assertThat(countStorage.get(Tuple.of(0)), is(CardinalityIntervals.atMost(12))); |
140 | assertThat(countStorage.get(Tuple.of(1)), is(CardinalityIntervals.atMost(12))); | 140 | assertThat(countStorage.get(Tuple.of(1)), is(CardinalityIntervals.atMost(12))); |
141 | } | 141 | } |
@@ -149,33 +149,32 @@ class MultiObjectTest { | |||
149 | .put(Tuple.of(1), CardinalityIntervals.atMost(11))) | 149 | .put(Tuple.of(1), CardinalityIntervals.atMost(11))) |
150 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) | 150 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) |
151 | .build()); | 151 | .build()); |
152 | assertThat(propagate(), is(PropagationResult.PROPAGATED)); | ||
153 | assertThat(countStorage.get(Tuple.of(0)), is(CardinalityIntervals.between(7, 12))); | 152 | assertThat(countStorage.get(Tuple.of(0)), is(CardinalityIntervals.between(7, 12))); |
154 | assertThat(countStorage.get(Tuple.of(1)), is(CardinalityIntervals.atMost(5))); | 153 | assertThat(countStorage.get(Tuple.of(1)), is(CardinalityIntervals.atMost(5))); |
155 | } | 154 | } |
156 | 155 | ||
157 | @Test | 156 | @Test |
158 | void twoMultiObjectsExistingBoundUnsatisfiableUpperTest() { | 157 | void twoMultiObjectsExistingBoundUnsatisfiableUpperTest() { |
159 | createModel(ModelSeed.builder(5) | 158 | var seed = ModelSeed.builder(5) |
160 | .seed(MultiObjectTranslator.COUNT_SYMBOL, builder -> builder | 159 | .seed(MultiObjectTranslator.COUNT_SYMBOL, builder -> builder |
161 | .reducedValue(CardinalityIntervals.ONE) | 160 | .reducedValue(CardinalityIntervals.ONE) |
162 | .put(Tuple.of(0), CardinalityIntervals.between(7, 20)) | 161 | .put(Tuple.of(0), CardinalityIntervals.between(7, 20)) |
163 | .put(Tuple.of(1), CardinalityIntervals.exactly(11))) | 162 | .put(Tuple.of(1), CardinalityIntervals.exactly(11))) |
164 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) | 163 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) |
165 | .build()); | 164 | .build(); |
166 | assertThat(propagate(), is(PropagationResult.REJECTED)); | 165 | assertThrows(IllegalArgumentException.class, () -> reasoningStoreAdapter.createInitialModel(seed)); |
167 | } | 166 | } |
168 | 167 | ||
169 | @Test | 168 | @Test |
170 | void twoMultiObjectsExistingBoundUnsatisfiableLowerTest() { | 169 | void twoMultiObjectsExistingBoundUnsatisfiableLowerTest() { |
171 | createModel(ModelSeed.builder(3) | 170 | var seed = ModelSeed.builder(3) |
172 | .seed(MultiObjectTranslator.COUNT_SYMBOL, builder -> builder | 171 | .seed(MultiObjectTranslator.COUNT_SYMBOL, builder -> builder |
173 | .reducedValue(CardinalityIntervals.ONE) | 172 | .reducedValue(CardinalityIntervals.ONE) |
174 | .put(Tuple.of(0), CardinalityIntervals.LONE) | 173 | .put(Tuple.of(0), CardinalityIntervals.LONE) |
175 | .put(Tuple.of(1), CardinalityIntervals.atMost(2))) | 174 | .put(Tuple.of(1), CardinalityIntervals.atMost(2))) |
176 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) | 175 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) |
177 | .build()); | 176 | .build(); |
178 | assertThat(propagate(), is(PropagationResult.REJECTED)); | 177 | assertThrows(IllegalArgumentException.class, () -> reasoningStoreAdapter.createInitialModel(seed)); |
179 | } | 178 | } |
180 | 179 | ||
181 | @Test | 180 | @Test |
@@ -187,7 +186,6 @@ class MultiObjectTest { | |||
187 | .put(Tuple.of(1), CardinalityIntervals.SET)) | 186 | .put(Tuple.of(1), CardinalityIntervals.SET)) |
188 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) | 187 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) |
189 | .build()); | 188 | .build()); |
190 | assertThat(propagate(), is(PropagationResult.PROPAGATED)); | ||
191 | assertThat(countStorage.get(Tuple.of(0)), is(CardinalityIntervals.LONE)); | 189 | assertThat(countStorage.get(Tuple.of(0)), is(CardinalityIntervals.LONE)); |
192 | assertThat(countStorage.get(Tuple.of(1)), is(CardinalityIntervals.between(1, 12))); | 190 | assertThat(countStorage.get(Tuple.of(1)), is(CardinalityIntervals.between(1, 12))); |
193 | countStorage.put(Tuple.of(0), CardinalityIntervals.ONE); | 191 | countStorage.put(Tuple.of(0), CardinalityIntervals.ONE); |