diff options
Diffstat (limited to 'subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/typehierarchy/TypeAnalysisExampleHierarchyTest.java')
-rw-r--r-- | subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/typehierarchy/TypeAnalysisExampleHierarchyTest.java | 208 |
1 files changed, 208 insertions, 0 deletions
diff --git a/subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/typehierarchy/TypeAnalysisExampleHierarchyTest.java b/subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/typehierarchy/TypeAnalysisExampleHierarchyTest.java new file mode 100644 index 00000000..d9a5477e --- /dev/null +++ b/subprojects/store-reasoning/src/test/java/tools/refinery/store/reasoning/translator/typehierarchy/TypeAnalysisExampleHierarchyTest.java | |||
@@ -0,0 +1,208 @@ | |||
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.reasoning.translator.typehierarchy; | ||
7 | |||
8 | import org.hamcrest.Matchers; | ||
9 | import org.junit.jupiter.api.BeforeEach; | ||
10 | import org.junit.jupiter.api.Test; | ||
11 | import tools.refinery.store.reasoning.representation.PartialRelation; | ||
12 | import tools.refinery.store.representation.TruthValue; | ||
13 | |||
14 | import java.util.Set; | ||
15 | |||
16 | import static org.hamcrest.MatcherAssert.assertThat; | ||
17 | import static org.hamcrest.Matchers.is; | ||
18 | import static org.junit.jupiter.api.Assertions.assertAll; | ||
19 | |||
20 | class TypeAnalysisExampleHierarchyTest { | ||
21 | private final PartialRelation a1 = new PartialRelation("A1", 1); | ||
22 | private final PartialRelation a2 = new PartialRelation("A2", 1); | ||
23 | private final PartialRelation a3 = new PartialRelation("A3", 1); | ||
24 | private final PartialRelation a4 = new PartialRelation("A4", 1); | ||
25 | private final PartialRelation a5 = new PartialRelation("A5", 1); | ||
26 | private final PartialRelation c1 = new PartialRelation("C1", 1); | ||
27 | private final PartialRelation c2 = new PartialRelation("C2", 1); | ||
28 | private final PartialRelation c3 = new PartialRelation("C3", 1); | ||
29 | private final PartialRelation c4 = new PartialRelation("C4", 1); | ||
30 | |||
31 | private TypeHierarchy sut; | ||
32 | private TypeHierarchyTester tester; | ||
33 | |||
34 | @BeforeEach | ||
35 | void beforeEach() { | ||
36 | sut = TypeHierarchy.builder() | ||
37 | .type(a1, true) | ||
38 | .type(a2, true) | ||
39 | .type(a3, true) | ||
40 | .type(a4, true) | ||
41 | .type(a5, true) | ||
42 | .type(c1, a1, a4) | ||
43 | .type(c2, a1, a2, a3, a4) | ||
44 | .type(c3, a3) | ||
45 | .type(c4, a4) | ||
46 | .build(); | ||
47 | tester = new TypeHierarchyTester(sut); | ||
48 | } | ||
49 | |||
50 | @Test | ||
51 | void analysisResultsTest() { | ||
52 | assertAll( | ||
53 | () -> tester.assertAbstractType(a1, c1, c2), | ||
54 | () -> tester.assertEliminatedType(a2, c2), | ||
55 | () -> tester.assertAbstractType(a3, c2, c3), | ||
56 | () -> tester.assertAbstractType(a4, c1, c2, c4), | ||
57 | () -> tester.assertVacuousType(a5), | ||
58 | () -> tester.assertConcreteType(c1), | ||
59 | () -> tester.assertConcreteType(c2), | ||
60 | () -> tester.assertConcreteType(c3), | ||
61 | () -> tester.assertConcreteType(c4) | ||
62 | ); | ||
63 | } | ||
64 | |||
65 | @Test | ||
66 | void inferredTypesTest() { | ||
67 | assertAll( | ||
68 | () -> assertThat(sut.getUnknownType(), Matchers.is(new InferredType(Set.of(), Set.of(c1, c2, c3, c4), null))), | ||
69 | () -> assertThat(tester.getInferredType(a1), Matchers.is(new InferredType(Set.of(a1, a4), Set.of(c1, c2), c1))), | ||
70 | () -> assertThat(tester.getInferredType(a3), Matchers.is(new InferredType(Set.of(a3), Set.of(c2, c3), c2))), | ||
71 | () -> assertThat(tester.getInferredType(a4), Matchers.is(new InferredType(Set.of(a4), Set.of(c1, c2, c4), c1))), | ||
72 | () -> assertThat(tester.getInferredType(a5), Matchers.is(new InferredType(Set.of(a5), Set.of(), null))), | ||
73 | () -> assertThat(tester.getInferredType(c1), Matchers.is(new InferredType(Set.of(a1, a4, c1), Set.of(c1), c1))), | ||
74 | () -> assertThat(tester.getInferredType(c2), | ||
75 | Matchers.is(new InferredType(Set.of(a1, a3, a4, c2), Set.of(c2), c2))), | ||
76 | () -> assertThat(tester.getInferredType(c3), Matchers.is(new InferredType(Set.of(a3, c3), Set.of(c3), c3))), | ||
77 | () -> assertThat(tester.getInferredType(c4), Matchers.is(new InferredType(Set.of(a4, c4), Set.of(c4), c4))) | ||
78 | ); | ||
79 | } | ||
80 | |||
81 | @Test | ||
82 | void consistentMustTest() { | ||
83 | var a1Result = tester.getPreservedType(a1); | ||
84 | var a3Result = tester.getPreservedType(a3); | ||
85 | var expected = new InferredType(Set.of(a1, a3, a4, c2), Set.of(c2), c2); | ||
86 | assertAll( | ||
87 | () -> assertThat(a1Result.merge(a3Result.asInferredType(), TruthValue.TRUE), Matchers.is(expected)), | ||
88 | () -> assertThat(a3Result.merge(a1Result.asInferredType(), TruthValue.TRUE), Matchers.is(expected)), | ||
89 | () -> assertThat(a1Result.merge(sut.getUnknownType(), TruthValue.TRUE), is(a1Result.asInferredType())), | ||
90 | () -> assertThat(a3Result.merge(sut.getUnknownType(), TruthValue.TRUE), is(a3Result.asInferredType())), | ||
91 | () -> assertThat(a1Result.merge(a1Result.asInferredType(), TruthValue.TRUE), | ||
92 | is(a1Result.asInferredType())) | ||
93 | ); | ||
94 | } | ||
95 | |||
96 | @Test | ||
97 | void consistentMayNotTest() { | ||
98 | var a1Result = tester.getPreservedType(a1); | ||
99 | var a3Result = tester.getPreservedType(a3); | ||
100 | var a4Result = tester.getPreservedType(a4); | ||
101 | assertAll( | ||
102 | () -> assertThat(a1Result.merge(a3Result.asInferredType(), TruthValue.FALSE), | ||
103 | Matchers.is(new InferredType(Set.of(a3, c3), Set.of(c3), c3))), | ||
104 | () -> assertThat(a3Result.merge(a1Result.asInferredType(), TruthValue.FALSE), | ||
105 | Matchers.is(new InferredType(Set.of(a1, a4, c1), Set.of(c1), c1))), | ||
106 | () -> assertThat(a4Result.merge(a3Result.asInferredType(), TruthValue.FALSE), | ||
107 | Matchers.is(new InferredType(Set.of(a3, c3), Set.of(c3), c3))), | ||
108 | () -> assertThat(a3Result.merge(a4Result.asInferredType(), TruthValue.FALSE), | ||
109 | Matchers.is(new InferredType(Set.of(a4), Set.of(c1, c4), c1))), | ||
110 | () -> assertThat(a1Result.merge(sut.getUnknownType(), TruthValue.FALSE), | ||
111 | Matchers.is(new InferredType(Set.of(), Set.of(c3, c4), null))), | ||
112 | () -> assertThat(a3Result.merge(sut.getUnknownType(), TruthValue.FALSE), | ||
113 | Matchers.is(new InferredType(Set.of(), Set.of(c1, c4), null))), | ||
114 | () -> assertThat(a4Result.merge(sut.getUnknownType(), TruthValue.FALSE), | ||
115 | Matchers.is(new InferredType(Set.of(), Set.of(c3), null))) | ||
116 | ); | ||
117 | } | ||
118 | |||
119 | @Test | ||
120 | void consistentErrorTest() { | ||
121 | var c1Result = tester.getPreservedType(c1); | ||
122 | var a4Result = tester.getPreservedType(a4); | ||
123 | var expected = new InferredType(Set.of(c1, a1, a4), Set.of(), null); | ||
124 | assertAll( | ||
125 | () -> assertThat(c1Result.merge(a4Result.asInferredType(), TruthValue.ERROR), Matchers.is(expected)), | ||
126 | () -> assertThat(a4Result.merge(c1Result.asInferredType(), TruthValue.ERROR), Matchers.is(expected)) | ||
127 | ); | ||
128 | } | ||
129 | |||
130 | @Test | ||
131 | void consistentUnknownTest() { | ||
132 | var c1Result = tester.getPreservedType(c1); | ||
133 | var a4Result = tester.getPreservedType(a4); | ||
134 | assertAll( | ||
135 | () -> assertThat(c1Result.merge(a4Result.asInferredType(), TruthValue.UNKNOWN), | ||
136 | is(a4Result.asInferredType())), | ||
137 | () -> assertThat(a4Result.merge(c1Result.asInferredType(), TruthValue.UNKNOWN), | ||
138 | is(c1Result.asInferredType())) | ||
139 | ); | ||
140 | } | ||
141 | |||
142 | @Test | ||
143 | void inconsistentMustTest() { | ||
144 | var a1Result = tester.getPreservedType(a1); | ||
145 | var c3Result = tester.getPreservedType(c3); | ||
146 | assertAll( | ||
147 | () -> assertThat(a1Result.merge(c3Result.asInferredType(), TruthValue.TRUE), | ||
148 | Matchers.is(new InferredType(Set.of(a1, a3, c3), Set.of(), null))), | ||
149 | () -> assertThat(c3Result.merge(a1Result.asInferredType(), TruthValue.TRUE), | ||
150 | Matchers.is(new InferredType(Set.of(a1, a3, a4, c3), Set.of(), null))) | ||
151 | ); | ||
152 | } | ||
153 | |||
154 | @Test | ||
155 | void inconsistentMayNotTest() { | ||
156 | var a1Result = tester.getPreservedType(a1); | ||
157 | var a4Result = tester.getPreservedType(a4); | ||
158 | var c1Result = tester.getPreservedType(c1); | ||
159 | assertAll( | ||
160 | () -> assertThat(a4Result.merge(a1Result.asInferredType(), TruthValue.FALSE), | ||
161 | Matchers.is(new InferredType(Set.of(a1, a4), Set.of(), null))), | ||
162 | () -> assertThat(a1Result.merge(c1Result.asInferredType(), TruthValue.FALSE), | ||
163 | Matchers.is(new InferredType(Set.of(a1, a4, c1), Set.of(), null))), | ||
164 | () -> assertThat(a4Result.merge(c1Result.asInferredType(), TruthValue.FALSE), | ||
165 | Matchers.is(new InferredType(Set.of(a1, a4, c1), Set.of(), null))), | ||
166 | () -> assertThat(a1Result.merge(a1Result.asInferredType(), TruthValue.FALSE), | ||
167 | Matchers.is(new InferredType(Set.of(a1, a4), Set.of(), null))) | ||
168 | ); | ||
169 | } | ||
170 | |||
171 | @Test | ||
172 | void vacuousMustTest() { | ||
173 | var c1Result = tester.getPreservedType(c1); | ||
174 | var a5Result = tester.getPreservedType(a5); | ||
175 | assertAll( | ||
176 | () -> assertThat(c1Result.merge(a5Result.asInferredType(), TruthValue.TRUE), | ||
177 | Matchers.is(new InferredType(Set.of(a1, a4, a5, c1), Set.of(), null))), | ||
178 | () -> assertThat(a5Result.merge(c1Result.asInferredType(), TruthValue.TRUE), | ||
179 | Matchers.is(new InferredType(Set.of(a1, a4, a5, c1), Set.of(), null))) | ||
180 | ); | ||
181 | } | ||
182 | |||
183 | @Test | ||
184 | void vacuousMayNotTest() { | ||
185 | var c1Result = tester.getPreservedType(c1); | ||
186 | var a5Result = tester.getPreservedType(a5); | ||
187 | assertAll( | ||
188 | () -> assertThat(c1Result.merge(a5Result.asInferredType(), TruthValue.FALSE), | ||
189 | is(a5Result.asInferredType())), | ||
190 | () -> assertThat(a5Result.merge(c1Result.asInferredType(), TruthValue.FALSE), | ||
191 | is(c1Result.asInferredType())) | ||
192 | ); | ||
193 | } | ||
194 | |||
195 | @Test | ||
196 | void vacuousErrorTest() { | ||
197 | var c1Result = tester.getPreservedType(c1); | ||
198 | var a5Result = tester.getPreservedType(a5); | ||
199 | assertAll( | ||
200 | () -> assertThat(c1Result.merge(a5Result.asInferredType(), TruthValue.ERROR), | ||
201 | Matchers.is(new InferredType(Set.of(a1, a4, a5, c1), Set.of(), null))), | ||
202 | () -> assertThat(a5Result.merge(c1Result.asInferredType(), TruthValue.ERROR), | ||
203 | Matchers.is(new InferredType(Set.of(a1, a4, a5, c1), Set.of(), null))), | ||
204 | () -> assertThat(a5Result.merge(a5Result.asInferredType(), TruthValue.ERROR), | ||
205 | is(a5Result.asInferredType())) | ||
206 | ); | ||
207 | } | ||
208 | } | ||