mirror of
https://github.com/sharkdp/hyperfine.git
synced 2024-09-11 14:07:02 +03:00
Add MAD=0 unit tests for outlier detection, see #329
This commit is contained in:
parent
25f8129212
commit
1477c68658
@ -29,6 +29,9 @@ pub fn modified_zscores(xs: &[f64]) -> Vec<f64> {
|
||||
// Compute median absolute deviation:
|
||||
let mad = median(&deviations);
|
||||
|
||||
// Handle MAD == 0 case
|
||||
let mad = if mad > 0.0 { mad } else { f64::EPSILON };
|
||||
|
||||
// Compute modified Z-scores (x_i - x_median) / MAD
|
||||
xs.iter().map(|&x| (x - x_median) / mad).collect()
|
||||
}
|
||||
@ -99,3 +102,13 @@ fn test_detect_outliers() {
|
||||
];
|
||||
assert_eq!(2, num_outliers(&xs));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_detect_outliers_if_mad_becomes_0() {
|
||||
// See https://stats.stackexchange.com/q/339932
|
||||
let xs = [10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 100.0];
|
||||
assert_eq!(1, num_outliers(&xs));
|
||||
|
||||
let xs = [10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 100.0, 100.0];
|
||||
assert_eq!(2, num_outliers(&xs));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user