|
42 | 42 | import static org.elasticsearch.exponentialhistogram.ExponentialScaleUtils.computeIndex; |
43 | 43 | import static org.hamcrest.Matchers.closeTo; |
44 | 44 | import static org.hamcrest.Matchers.equalTo; |
| 45 | +import static org.hamcrest.Matchers.greaterThanOrEqualTo; |
45 | 46 | import static org.hamcrest.Matchers.lessThan; |
46 | 47 | import static org.hamcrest.Matchers.lessThanOrEqualTo; |
47 | 48 | import static org.hamcrest.Matchers.notANumber; |
@@ -275,22 +276,26 @@ private double testQuantileAccuracy(double[] values, int bucketCount) { |
275 | 276 | double maxError = 0; |
276 | 277 | double allowedError = getMaximumRelativeError(values, bucketCount); |
277 | 278 |
|
| 279 | + double lastQuantile = Double.NEGATIVE_INFINITY; |
278 | 280 | // Compare histogram quantiles with exact quantiles |
279 | 281 | for (double q : QUANTILES_TO_TEST) { |
280 | 282 | double percentileRank = q * (values.length - 1); |
281 | 283 | int lowerRank = (int) Math.floor(percentileRank); |
282 | 284 | int upperRank = (int) Math.ceil(percentileRank); |
283 | 285 | double upperFactor = percentileRank - lowerRank; |
284 | 286 |
|
| 287 | + double histoValue = ExponentialHistogramQuantile.getQuantile(histogram, q); |
| 288 | + // values should be monotonically increasing |
| 289 | + assertThat(histoValue, greaterThanOrEqualTo(lastQuantile)); |
| 290 | + lastQuantile = histoValue; |
| 291 | + |
285 | 292 | if (values[lowerRank] < 0 && values[upperRank] > 0) { |
286 | 293 | // the percentile lies directly between a sign change and we interpolate linearly in-between |
287 | 294 | // in this case the relative error bound does not hold |
288 | 295 | continue; |
289 | 296 | } |
290 | 297 | double exactValue = values[lowerRank] * (1 - upperFactor) + values[upperRank] * upperFactor; |
291 | 298 |
|
292 | | - double histoValue = ExponentialHistogramQuantile.getQuantile(histogram, q); |
293 | | - |
294 | 299 | // Skip comparison if exact value is close to zero to avoid false-positives due to numerical imprecision |
295 | 300 | if (Math.abs(exactValue) < 1e-100) { |
296 | 301 | continue; |
|
0 commit comments