Fix median calculation in MedianAbsoluteDeviationAggregatorTests (#38979)
Fixes an error in median calculation in MedianAbsoluteDeviationAggregatorTests for odd number of sample points, which causes some rare test failures. Fixes #38937
This commit is contained in:
parent
90b1b36f50
commit
3d93011e32
|
@ -260,9 +260,15 @@ public class MedianAbsoluteDeviationAggregatorTests extends AggregatorTestCase {
|
|||
private static double calculateMedian(double[] sample) {
|
||||
final double[] sorted = Arrays.copyOf(sample, sample.length);
|
||||
Arrays.sort(sorted);
|
||||
|
||||
final int halfway = (int) Math.ceil(sorted.length / 2d);
|
||||
final double median = (sorted[halfway - 1] + sorted[halfway]) / 2d;
|
||||
final int halfway = (int) Math.ceil(sorted.length / 2d);
|
||||
final double median;
|
||||
if (sorted.length % 2 == 0) {
|
||||
// even
|
||||
median = (sorted[halfway - 1] + sorted[halfway]) / 2d;
|
||||
} else {
|
||||
// odd
|
||||
median = (sorted[halfway - 1]);
|
||||
}
|
||||
return median;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue