Skip to content

Commit

Permalink
OPIK-395 pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
idoberko2 committed Nov 26, 2024
1 parent 10d8887 commit 3ab0334
Showing 1 changed file with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -414,17 +414,11 @@ void happyPath(TimeInterval interval) {
assertThat(response.results()).hasSize(names.size());

assertThat(response.results()).hasSize(expected.size());

for (var expectedRes : expected) {
var actual = response.results().stream()
.filter(actualRes -> actualRes.name().equals(expectedRes.name())).findFirst();
assertThat(actual).isPresent();

for (int i = 0; i < expectedRes.data().size(); i++) {
assertThat(actual.get().data().get(i).time()).isEqualTo(expectedRes.data().get(i).time());
assertEqualBigDecimal(expectedRes.data().get(i).value(), actual.get().data().get(i).value());
}
}
assertThat(response.results())
.usingRecursiveComparison()
.withComparatorForType(this::bigDecimalInDelta, BigDecimal.class)
.ignoringCollectionOrder()
.isEqualTo(expected);
}

private List<ProjectMetricResponse.Results<BigDecimal>> createExpectedFeedbackScores(
Expand All @@ -449,18 +443,20 @@ private List<ProjectMetricResponse.Results<BigDecimal>> createExpectedFeedbackSc
}).toList();
}

private void assertEqualBigDecimal(BigDecimal expected, BigDecimal actual) {
if (expected == null) {
assertThat(actual).isNull();
return;
private int bigDecimalInDelta(BigDecimal number, BigDecimal number2) {
if (number == null) {
return number2 == null ? 0 : 1;
}
if (number2 == null) {
return -1;
}
assertThat(actual).isNotNull();

var delta = new BigDecimal(".000001");
assertThat(actual)
.withFailMessage("Expected %s to be almost equal to %s within delta %s", actual,
expected, delta)
.satisfies(a -> assertThat(actual.subtract(expected).abs()).isLessThanOrEqualTo(delta));
if (number.subtract(number2).abs().compareTo(delta) < 0) {
return 0;
}

return number.compareTo(number2);
}

private Map<String, BigDecimal> createFeedbackScores(
Expand Down

0 comments on commit 3ab0334

Please sign in to comment.