diff options
Diffstat (limited to 'subprojects/logic/src/testFixtures/java/tools/refinery/logic/tests/StructurallyEqualTo.java')
-rw-r--r-- | subprojects/logic/src/testFixtures/java/tools/refinery/logic/tests/StructurallyEqualTo.java | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/subprojects/logic/src/testFixtures/java/tools/refinery/logic/tests/StructurallyEqualTo.java b/subprojects/logic/src/testFixtures/java/tools/refinery/logic/tests/StructurallyEqualTo.java new file mode 100644 index 00000000..257e6850 --- /dev/null +++ b/subprojects/logic/src/testFixtures/java/tools/refinery/logic/tests/StructurallyEqualTo.java | |||
@@ -0,0 +1,41 @@ | |||
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.logic.tests; | ||
7 | |||
8 | import org.hamcrest.Description; | ||
9 | import org.hamcrest.TypeSafeMatcher; | ||
10 | import tools.refinery.logic.dnf.Dnf; | ||
11 | import tools.refinery.logic.equality.DeepDnfEqualityChecker; | ||
12 | |||
13 | public class StructurallyEqualTo extends TypeSafeMatcher<Dnf> { | ||
14 | private final Dnf expected; | ||
15 | |||
16 | public StructurallyEqualTo(Dnf expected) { | ||
17 | this.expected = expected; | ||
18 | } | ||
19 | |||
20 | @Override | ||
21 | protected boolean matchesSafely(Dnf item) { | ||
22 | var checker = new DeepDnfEqualityChecker(); | ||
23 | return checker.dnfEqual(expected, item); | ||
24 | } | ||
25 | |||
26 | @Override | ||
27 | protected void describeMismatchSafely(Dnf item, Description mismatchDescription) { | ||
28 | var describingChecker = new MismatchDescribingDnfEqualityChecker(mismatchDescription); | ||
29 | if (describingChecker.dnfEqual(expected, item)) { | ||
30 | throw new IllegalStateException("Mismatched Dnf was matching on repeated comparison"); | ||
31 | } | ||
32 | if (describingChecker.needsDescription()) { | ||
33 | super.describeMismatchSafely(item, mismatchDescription); | ||
34 | } | ||
35 | } | ||
36 | |||
37 | @Override | ||
38 | public void describeTo(Description description) { | ||
39 | description.appendText("structurally equal to ").appendText(expected.toDefinitionString()); | ||
40 | } | ||
41 | } | ||