From 3934e14bc01736e92c0b6c3e76c55a510408e85c Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Thu, 3 Sep 2020 12:37:17 -0400 Subject: [PATCH] Fixup vwhisto test (#60936) (#61928) This test assumed some random bounds that turned out not to hold in some cases. Closes #60673 --- .../VariableWidthHistogramAggregatorTests.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/VariableWidthHistogramAggregatorTests.java b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/VariableWidthHistogramAggregatorTests.java index 1b399203a8d..11f374c977f 100644 --- a/server/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/VariableWidthHistogramAggregatorTests.java +++ b/server/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/VariableWidthHistogramAggregatorTests.java @@ -54,8 +54,11 @@ import java.util.Map; import java.util.function.Consumer; import static java.util.stream.Collectors.toList; +import static org.hamcrest.Matchers.both; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; +import static org.hamcrest.Matchers.lessThanOrEqualTo; public class VariableWidthHistogramAggregatorTests extends AggregatorTestCase { @@ -428,14 +431,14 @@ public class VariableWidthHistogramAggregatorTests extends AggregatorTestCase { assertEquals(2, buckets.size()); - // The smaller cluster - assertEquals(4 <= buckets.get(0).getDocCount() && buckets.get(0).getDocCount() <= 6, true); - assertEquals(0 <= buckets.get(0).centroid() && buckets.get(0).centroid() <= 200d, true); + // The lower cluster + assertThat(buckets.get(0).getDocCount(), both(greaterThanOrEqualTo(4L)).and(lessThanOrEqualTo(7L))); + assertThat(buckets.get(0).centroid(), both(greaterThanOrEqualTo(0.0)).and(lessThanOrEqualTo(300.0))); assertEquals(1, buckets.get(0).min(), deltaError); - // The bigger cluster - assertEquals(4 <= buckets.get(1).getDocCount() && buckets.get(1).getDocCount() <= 6, true); - assertEquals(800d <= buckets.get(1).centroid() && buckets.get(1).centroid() <= 1005d, true); + // The higher cluster + assertThat(buckets.get(1).getDocCount(), equalTo(dataset.size() - buckets.get(0).getDocCount())); + assertThat(buckets.get(1).centroid(), both(greaterThanOrEqualTo(800.0)).and(lessThanOrEqualTo(1005.0))); assertEquals(1005, buckets.get(1).max(), deltaError); });