Use proptest to test reasonable bounds of mean
This commit is contained in:
parent
a4098571fd
commit
3f82a320f9
@ -43,3 +43,4 @@ rand = "0.6"
|
|||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
streaming-stats = "0.2"
|
streaming-stats = "0.2"
|
||||||
quantiles = "0.7"
|
quantiles = "0.7"
|
||||||
|
proptest = "0.9"
|
||||||
|
28
tests/proptest.rs
Normal file
28
tests/proptest.rs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#![cfg_attr(feature = "cargo-clippy", allow(float_cmp, map_clone))]
|
||||||
|
|
||||||
|
#[macro_use] extern crate average;
|
||||||
|
#[macro_use] extern crate proptest;
|
||||||
|
|
||||||
|
extern crate core;
|
||||||
|
|
||||||
|
use core::iter::Iterator;
|
||||||
|
|
||||||
|
use average::Mean;
|
||||||
|
use proptest::prelude::*;
|
||||||
|
use prop::num::f64;
|
||||||
|
|
||||||
|
proptest! {
|
||||||
|
#![proptest_config(ProptestConfig::with_cases(10000))]
|
||||||
|
#[test]
|
||||||
|
fn reasonable_bounds(s in prop::collection::vec(
|
||||||
|
f64::POSITIVE | f64::NEGATIVE | f64::SUBNORMAL | f64::ZERO, 1..100usize)) {
|
||||||
|
// See https://hypothesis.works/articles/calculating-the-mean/.
|
||||||
|
let max = s.iter().cloned().fold(0./0., f64::max);
|
||||||
|
let min = s.iter().cloned().fold(0./0., f64::min);
|
||||||
|
let a: Mean = s.iter().collect();
|
||||||
|
let mean = a.mean();
|
||||||
|
println!("min: {} mean: {} max: {}", min, mean, max);
|
||||||
|
assert!(min <= mean);
|
||||||
|
assert!(mean <= max);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user