blob: 6a3301b306858102a82b32b952d2d298abf1f188 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
/*
* SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/>
*
* SPDX-License-Identifier: EPL-2.0
*/
package tools.refinery.store.query.tests;
import org.hamcrest.Description;
import tools.refinery.store.query.dnf.Dnf;
import tools.refinery.store.query.dnf.SymbolicParameter;
import tools.refinery.store.query.equality.DeepDnfEqualityChecker;
import tools.refinery.store.query.literal.Literal;
import java.util.List;
class MismatchDescribingDnfEqualityChecker extends DeepDnfEqualityChecker {
private final Description description;
private boolean raw;
private boolean needsDescription = true;
MismatchDescribingDnfEqualityChecker(Description description) {
this.description = description;
}
public boolean needsDescription() {
return needsDescription;
}
@Override
public boolean dnfEqualRaw(List<SymbolicParameter> symbolicParameters, List<? extends List<? extends Literal>> clauses, Dnf other) {
try {
raw = true;
boolean result = super.dnfEqualRaw(symbolicParameters, clauses, other);
if (!result && needsDescription) {
description.appendText("was ").appendText(other.toDefinitionString());
}
return false;
} finally {
raw = false;
}
}
@Override
protected boolean doCheckEqual(Pair pair) {
boolean result = super.doCheckEqual(pair);
if (!result && needsDescription) {
describeMismatch(pair);
// Only describe the first found (innermost) mismatch.
needsDescription = false;
}
return result;
}
private void describeMismatch(Pair pair) {
var inProgress = getInProgress();
int size = inProgress.size();
if (size <= 1 && !raw) {
description.appendText("was ").appendText(pair.right().toDefinitionString());
return;
}
var last = inProgress.get(size - 1);
description.appendText("expected ").appendText(last.left().toDefinitionString());
for (int i = size - 2; i >= 0; i--) {
description.appendText(" called from ").appendText(inProgress.get(i).left().toString());
}
description.appendText(" was not structurally equal to ").appendText(last.right().toDefinitionString());
}
}
|