|
28 | 28 |
|
29 | 29 | import static org.hamcrest.Matchers.closeTo; |
30 | 30 | import static org.hamcrest.Matchers.lessThan; |
| 31 | +import static org.hamcrest.Matchers.notANumber; |
31 | 32 |
|
32 | 33 | public class QuantileAccuracyTests extends ESTestCase { |
33 | 34 |
|
34 | 35 | public static final double[] QUANTILES_TO_TEST = { 0, 0.01, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95, 0.99, 1.0 }; |
35 | 36 |
|
36 | | - public void testBasicSmall() { |
37 | | - DoubleStream values = IntStream.range(1,10).mapToDouble(Double::valueOf); |
38 | | - testQuantileAccuracy(values.toArray(), 100); |
39 | | - } |
40 | | - |
41 | 37 | public void testUniformDistribution() { |
42 | 38 | testDistributionQuantileAccuracy(new UniformRealDistribution(new Well19937c(42), 0, 100), 50000, 500); |
43 | 39 | } |
@@ -66,13 +62,69 @@ public void testWeibullDistribution() { |
66 | 62 | testDistributionQuantileAccuracy(new WeibullDistribution(new Well19937c(42), 2, 5), 50000, 500); |
67 | 63 | } |
68 | 64 |
|
| 65 | + public void testBasicSmall() { |
| 66 | + DoubleStream values = IntStream.range(1, 10).mapToDouble(Double::valueOf); |
| 67 | + double maxError = testQuantileAccuracy(values.toArray(), 100); |
| 68 | + assertThat(maxError, lessThan(0.000001)); |
| 69 | + } |
| 70 | + |
69 | 71 | public void testBigJump() { |
70 | | - double[] values = DoubleStream.concat( |
71 | | - IntStream.range(0,18).mapToDouble(Double::valueOf), |
72 | | - DoubleStream.of(1_000_000.0) |
73 | | - ).toArray(); |
| 72 | + double[] values = DoubleStream.concat(IntStream.range(0, 18).mapToDouble(Double::valueOf), DoubleStream.of(1_000_000.0)).toArray(); |
| 73 | + |
| 74 | + double maxError = testQuantileAccuracy(values, 500); |
| 75 | + assertThat(maxError, lessThan(0.000001)); |
| 76 | + } |
74 | 77 |
|
75 | | - testQuantileAccuracy(values, 500); |
| 78 | + public void testExplicitSkewedData() { |
| 79 | + double[] data = new double[] { |
| 80 | + 245, |
| 81 | + 246, |
| 82 | + 247.249, |
| 83 | + 240, |
| 84 | + 243, |
| 85 | + 248, |
| 86 | + 250, |
| 87 | + 241, |
| 88 | + 244, |
| 89 | + 245, |
| 90 | + 245, |
| 91 | + 247, |
| 92 | + 243, |
| 93 | + 242, |
| 94 | + 241, |
| 95 | + 50100, |
| 96 | + 51246, |
| 97 | + 52247, |
| 98 | + 52249, |
| 99 | + 51240, |
| 100 | + 53243, |
| 101 | + 59248, |
| 102 | + 59250, |
| 103 | + 57241, |
| 104 | + 56244, |
| 105 | + 55245, |
| 106 | + 56245, |
| 107 | + 575247, |
| 108 | + 58243, |
| 109 | + 51242, |
| 110 | + 54241 }; |
| 111 | + |
| 112 | + double maxError = testQuantileAccuracy(data, data.length / 2); |
| 113 | + assertThat(maxError, lessThan(0.007)); |
| 114 | + } |
| 115 | + |
| 116 | + public void testEmptyHistogram() { |
| 117 | + ExponentialHistogram histo = ExponentialHistogramGenerator.createFor(); |
| 118 | + for (double q : QUANTILES_TO_TEST) { |
| 119 | + assertThat(ExponentialHistogramQuantile.getQuantile(histo, q), notANumber()); |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + public void testSingleValueHistogram() { |
| 124 | + ExponentialHistogram histo = ExponentialHistogramGenerator.createFor(42); |
| 125 | + for (double q : QUANTILES_TO_TEST) { |
| 126 | + assertThat(ExponentialHistogramQuantile.getQuantile(histo, q), closeTo(42, 0.0000001)); |
| 127 | + } |
76 | 128 | } |
77 | 129 |
|
78 | 130 | public void testBucketCountImpact() { |
|
0 commit comments