Add tests for concatenate

This commit is contained in:
Vinzent Steinberg 2017-06-21 19:35:41 +02:00
parent 9b055e4c0b
commit fb1b0879bd

52
tests/macros.rs Normal file
View File

@ -0,0 +1,52 @@
#[macro_use] extern crate average;
extern crate core;
#[test]
fn concatenate_simple() {
use average::{Min, Max};
concatenate!(MinMax, [Min, min], [Max, max]);
{
let mut s = MinMax::new();
for i in 1..6 {
s.add(i as f64);
}
assert_eq!(s.min(), 1.0);
assert_eq!(s.max(), 5.0);
}
{
let mut s = MinMax::default();
for i in 1..6 {
s.add(i as f64);
}
assert_eq!(s.min(), 1.0);
assert_eq!(s.max(), 5.0);
}
{
let s: MinMax = (1..6).map(Into::into).collect();
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]);
let e: Estimator = (1..6).map(Into::into).collect();
assert_eq!(e.mean(), 3.0);
assert_eq!(e.sample_variance(), 2.5);
assert_eq!(e.quantile(), 3.0);
}