blob: 526832c4ef1f92bebba3152797efcb626965cf5c (
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
|
/*
* 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.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 ").appendText(pair.left().toDefinitionString());
return;
}
var last = inProgress.get(size - 1);
description.appendText("expected ").appendText(last.right().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());
}
}
|