Skip to content

Commit a75e3f1

Browse files
committed
Fixup vwhisto test (elastic#60936)
This test assumed some random bounds that turned out not to hold in some cases. Closes elastic#60673
1 parent cfa54c0 commit a75e3f1

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

server/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/VariableWidthHistogramAggregatorTests.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@
5454
import java.util.function.Consumer;
5555

5656
import static java.util.stream.Collectors.toList;
57+
import static org.hamcrest.Matchers.both;
5758
import static org.hamcrest.Matchers.containsString;
5859
import static org.hamcrest.Matchers.equalTo;
60+
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
61+
import static org.hamcrest.Matchers.lessThanOrEqualTo;
5962

6063
public class VariableWidthHistogramAggregatorTests extends AggregatorTestCase {
6164

@@ -428,14 +431,14 @@ public void testMultipleSegments() throws IOException{
428431

429432
assertEquals(2, buckets.size());
430433

431-
// The smaller cluster
432-
assertEquals(4 <= buckets.get(0).getDocCount() && buckets.get(0).getDocCount() <= 6, true);
433-
assertEquals(0 <= buckets.get(0).centroid() && buckets.get(0).centroid() <= 200d, true);
434+
// The lower cluster
435+
assertThat(buckets.get(0).getDocCount(), both(greaterThanOrEqualTo(4L)).and(lessThanOrEqualTo(7L)));
436+
assertThat(buckets.get(0).centroid(), both(greaterThanOrEqualTo(0.0)).and(lessThanOrEqualTo(300.0)));
434437
assertEquals(1, buckets.get(0).min(), deltaError);
435438

436-
// The bigger cluster
437-
assertEquals(4 <= buckets.get(1).getDocCount() && buckets.get(1).getDocCount() <= 6, true);
438-
assertEquals(800d <= buckets.get(1).centroid() && buckets.get(1).centroid() <= 1005d, true);
439+
// The higher cluster
440+
assertThat(buckets.get(1).getDocCount(), equalTo(dataset.size() - buckets.get(0).getDocCount()));
441+
assertThat(buckets.get(1).centroid(), both(greaterThanOrEqualTo(800.0)).and(lessThanOrEqualTo(1005.0)));
439442
assertEquals(1005, buckets.get(1).max(), deltaError);
440443
});
441444

0 commit comments

Comments
 (0)