Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaselineCalculator should process duplicates as well, since 3rd party linters can not guarantee their absence #5

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static class Options {
* if old result is absent and wasChecked == false -> oldResult.baselineState = UNCHANGED
* if old result is present then current result `wasChecked` is not used.
* <p>
* Typicaly wasChecked is true if result is in the scope of current check.
* Typically, wasChecked is true if result is in the scope of current check.
*/
private static final Function<Result, Boolean> ALL_CHECKED = (result) -> true;
private final Function<Result, Boolean> wasChecked;
Expand Down Expand Up @@ -153,8 +153,8 @@ public boolean isFillBaselineState() {
}

private class RunResultGroup {
private final Map<String, Result> baselineHashes = new HashMap<>();
private final Map<String, Result> reportHashes = new HashMap<>();
private final Map<String, List<Result>> baselineHashes = new HashMap<>();
private final Map<String, List<Result>> reportHashes = new HashMap<>();
private final Map<ResultKey, List<Result>> diffBaseline = new HashMap<>();
private final Map<ResultKey, List<Result>> diffReport = new HashMap<>();
private final Run report;
Expand All @@ -170,13 +170,16 @@ private void removeProblemsWithState(Run report, Result.BaselineState state) {
report.getResults().removeIf(result -> result.getBaselineState() == state);
}

private void buildMap(Run run, Map<String, Result> map, Map<ResultKey, List<Result>> diffSet) {
private void buildMap(Run run, Map<String, List<Result>> map, Map<ResultKey, List<Result>> diffSet) {
for (Result result : run.getResults()) {
if (result.getBaselineState() == ABSENT) continue;
VersionedMap<String> fingerprints = result.getPartialFingerprints();
String equalIndicator = fingerprints != null ? fingerprints.getLastValue(EQUAL_INDICATOR) : null;
if (equalIndicator != null) {
map.put(equalIndicator, result);
List<Result> resultBucket = map.compute(
equalIndicator,
(key, value) -> value != null ? value : new ArrayList<>());
resultBucket.add(result);
} else {
addToDiff(result, diffSet);
}
Expand All @@ -192,23 +195,25 @@ public void addToDiff(Result result, Map<ResultKey, List<Result>> diffSet) {
}

public void build() {
reportHashes.forEach((hash, result) -> {
reportHashes.forEach((hash, results) -> {
if (baselineHashes.containsKey(hash)) {
setBaselineState(result, UNCHANGED);
unchangedResults++;
results.forEach((it) -> setBaselineState(it, UNCHANGED));
unchangedResults += results.size();
} else {
addToDiff(result, diffReport);
results.forEach((it) -> addToDiff(it, diffReport));
}
});

baselineHashes.forEach((hash, result) -> {
baselineHashes.forEach((hash, results) -> {
if (!reportHashes.containsKey(hash)) {
if (options.wasChecked.apply(result)) {
addToDiff(result, diffBaseline);
} else {
result.setBaselineState(UNCHANGED);
report.getResults().add(result);
unchangedResults += 1;
for (Result result : results) {
if (options.wasChecked.apply(result)) {
addToDiff(result, diffBaseline);
} else {
result.setBaselineState(UNCHANGED);
report.getResults().add(result);
unchangedResults += 1;
}
}
}
});
Expand Down
Loading