From 3ab0334f941bd05bf7fd91e56652195c166fd6ab Mon Sep 17 00:00:00 2001 From: Ido Berkovich Date: Tue, 26 Nov 2024 10:45:55 +0200 Subject: [PATCH] OPIK-395 pr comments --- .../v1/priv/ProjectMetricsResourceTest.java | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/ProjectMetricsResourceTest.java b/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/ProjectMetricsResourceTest.java index 1a6682454d..3331865c58 100644 --- a/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/ProjectMetricsResourceTest.java +++ b/apps/opik-backend/src/test/java/com/comet/opik/api/resources/v1/priv/ProjectMetricsResourceTest.java @@ -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> createExpectedFeedbackScores( @@ -449,18 +443,20 @@ private List> 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 createFeedbackScores(