rust-average/tests/proptest.rs

24 lines
790 B
Rust
Raw Normal View History

2019-07-08 17:32:18 +02:00
#![cfg_attr(feature = "cargo-clippy", allow(clippy::float_cmp, map_clone))]
use core::iter::Iterator;
use average::Mean;
use proptest::prelude::*;
2019-07-08 16:04:19 +02:00
use crate::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);
}
}