2019-07-08 17:32:18 +02:00
|
|
|
#![cfg_attr(feature = "cargo-clippy", allow(clippy::float_cmp))]
|
2018-01-10 16:02:55 +01:00
|
|
|
|
2019-07-08 16:17:04 +02:00
|
|
|
use average::{Estimate, Min, Max, concatenate};
|
2019-04-25 13:51:33 +02:00
|
|
|
|
|
|
|
concatenate!(MinMax, [Min, min], [Max, max]);
|
2017-06-25 14:39:23 +02:00
|
|
|
|
2017-06-21 19:35:41 +02:00
|
|
|
#[test]
|
|
|
|
fn concatenate_simple() {
|
|
|
|
{
|
|
|
|
let mut s = MinMax::new();
|
|
|
|
for i in 1..6 {
|
2018-01-10 16:02:55 +01:00
|
|
|
s.add(f64::from(i));
|
2017-06-21 19:35:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
assert_eq!(s.min(), 1.0);
|
|
|
|
assert_eq!(s.max(), 5.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
let mut s = MinMax::default();
|
|
|
|
for i in 1..6 {
|
2018-01-10 16:02:55 +01:00
|
|
|
s.add(f64::from(i));
|
2017-06-21 19:35:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
assert_eq!(s.min(), 1.0);
|
|
|
|
assert_eq!(s.max(), 5.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-02-27 01:38:45 +01:00
|
|
|
let s: MinMax = (1..6).map(f64::from).collect();
|
2017-06-21 19:35:41 +02:00
|
|
|
|
|
|
|
assert_eq!(s.min(), 1.0);
|
|
|
|
assert_eq!(s.max(), 5.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn concatenate_moments() {
|
|
|
|
use average::{Variance, Quantile};
|
|
|
|
|
|
|
|
concatenate!(Estimator,
|
|
|
|
[Variance, variance, mean, sample_variance],
|
|
|
|
[Quantile, quantile, quantile]);
|
|
|
|
|
2018-02-27 01:38:45 +01:00
|
|
|
let e: Estimator = (1..6).map(f64::from).collect();
|
2017-06-21 19:35:41 +02:00
|
|
|
|
|
|
|
assert_eq!(e.mean(), 3.0);
|
|
|
|
assert_eq!(e.sample_variance(), 2.5);
|
|
|
|
assert_eq!(e.quantile(), 3.0);
|
|
|
|
}
|