diff options
Diffstat (limited to 'subprojects/store-query/src/testFixtures/java/tools/refinery/store/query/tests/MismatchDescribingDnfEqualityChecker.java')
-rw-r--r-- | subprojects/store-query/src/testFixtures/java/tools/refinery/store/query/tests/MismatchDescribingDnfEqualityChecker.java | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/subprojects/store-query/src/testFixtures/java/tools/refinery/store/query/tests/MismatchDescribingDnfEqualityChecker.java b/subprojects/store-query/src/testFixtures/java/tools/refinery/store/query/tests/MismatchDescribingDnfEqualityChecker.java new file mode 100644 index 00000000..aaab2e7e --- /dev/null +++ b/subprojects/store-query/src/testFixtures/java/tools/refinery/store/query/tests/MismatchDescribingDnfEqualityChecker.java | |||
@@ -0,0 +1,43 @@ | |||
1 | package tools.refinery.store.query.tests; | ||
2 | |||
3 | import org.hamcrest.Description; | ||
4 | import tools.refinery.store.query.equality.DeepDnfEqualityChecker; | ||
5 | |||
6 | class MismatchDescribingDnfEqualityChecker extends DeepDnfEqualityChecker { | ||
7 | private final Description description; | ||
8 | private boolean described; | ||
9 | |||
10 | MismatchDescribingDnfEqualityChecker(Description description) { | ||
11 | this.description = description; | ||
12 | } | ||
13 | |||
14 | public boolean isDescribed() { | ||
15 | return described; | ||
16 | } | ||
17 | |||
18 | @Override | ||
19 | protected boolean doCheckEqual(Pair pair) { | ||
20 | boolean result = super.doCheckEqual(pair); | ||
21 | if (!result && !described) { | ||
22 | describeMismatch(pair); | ||
23 | // Only describe the first found (innermost) mismatch. | ||
24 | described = true; | ||
25 | } | ||
26 | return result; | ||
27 | } | ||
28 | |||
29 | private void describeMismatch(Pair pair) { | ||
30 | var inProgress = getInProgress(); | ||
31 | int size = inProgress.size(); | ||
32 | if (size <= 1) { | ||
33 | description.appendText("was ").appendValue(pair.left()); | ||
34 | return; | ||
35 | } | ||
36 | var last = inProgress.get(size - 1); | ||
37 | description.appendText("expected ").appendValue(last.right()); | ||
38 | for (int i = size - 2; i >= 0; i--) { | ||
39 | description.appendText(" called from ").appendText(inProgress.get(i).left().name()); | ||
40 | } | ||
41 | description.appendText(" was not structurally equal to ").appendValue(last.right()); | ||
42 | } | ||
43 | } | ||