blob: aaab2e7ed897f1dc7965fdb6e67b7b44c2f517ab (
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
|
package tools.refinery.store.query.tests;
import org.hamcrest.Description;
import tools.refinery.store.query.equality.DeepDnfEqualityChecker;
class MismatchDescribingDnfEqualityChecker extends DeepDnfEqualityChecker {
private final Description description;
private boolean described;
MismatchDescribingDnfEqualityChecker(Description description) {
this.description = description;
}
public boolean isDescribed() {
return described;
}
@Override
protected boolean doCheckEqual(Pair pair) {
boolean result = super.doCheckEqual(pair);
if (!result && !described) {
describeMismatch(pair);
// Only describe the first found (innermost) mismatch.
described = true;
}
return result;
}
private void describeMismatch(Pair pair) {
var inProgress = getInProgress();
int size = inProgress.size();
if (size <= 1) {
description.appendText("was ").appendValue(pair.left());
return;
}
var last = inProgress.get(size - 1);
description.appendText("expected ").appendValue(last.right());
for (int i = size - 2; i >= 0; i--) {
description.appendText(" called from ").appendText(inProgress.get(i).left().name());
}
description.appendText(" was not structurally equal to ").appendValue(last.right());
}
}
|