Skip to content

Commit c8ad26e

Browse files
authored
Tests: Extend InternalStatsTests (#24212)
Currently we don't test for count = 0 which will make a difference when adding tests for parsing for the high level rest client. Also min/max/sum should also be tested with negative values and on a larger range.
1 parent 81b64ed commit c8ad26e

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

core/src/test/java/org/elasticsearch/search/aggregations/metrics/InternalStatsTests.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,12 @@ public class InternalStatsTests extends InternalAggregationTestCase<InternalStat
3232
@Override
3333
protected InternalStats createTestInstance(String name, List<PipelineAggregator> pipelineAggregators,
3434
Map<String, Object> metaData) {
35-
long count = randomIntBetween(1, 50);
36-
double[] minMax = new double[2];
37-
minMax[0] = randomDouble();
38-
minMax[0] = randomDouble();
39-
double sum = randomDoubleBetween(0, 100, true);
40-
return new InternalStats(name, count, sum, minMax[0], minMax[1], DocValueFormat.RAW,
41-
pipelineAggregators, Collections.emptyMap());
35+
long count = frequently() ? randomIntBetween(1, Integer.MAX_VALUE) : 0;
36+
double min = randomDoubleBetween(-1000000, 1000000, true);
37+
double max = randomDoubleBetween(-1000000, 1000000, true);
38+
double sum = randomDoubleBetween(-1000000, 1000000, true);
39+
DocValueFormat format = randomNumericDocValueFormat();
40+
return new InternalStats(name, count, sum, min, max, format, pipelineAggregators, Collections.emptyMap());
4241
}
4342

4443
@Override
@@ -58,7 +57,7 @@ protected void assertReduced(InternalStats reduced, List<InternalStats> inputs)
5857
expectedSum += stats.getSum();
5958
}
6059
assertEquals(expectedCount, reduced.getCount());
61-
assertEquals(expectedSum, reduced.getSum(), 1e-10);
60+
assertEquals(expectedSum, reduced.getSum(), 1e-7);
6261
assertEquals(expectedMin, reduced.getMin(), 0d);
6362
assertEquals(expectedMax, reduced.getMax(), 0d);
6463
}

0 commit comments

Comments
 (0)