-
Notifications
You must be signed in to change notification settings - Fork 11
/
macros.rs
86 lines (67 loc) · 1.79 KB
/
macros.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#![cfg_attr(feature = "cargo-clippy", allow(clippy::float_cmp))]
use average::{concatenate, Estimate, Max, Min};
concatenate!(MinMax, [Min, min], [Max, max]);
#[test]
fn concatenate_simple() {
{
let mut s = MinMax::new();
for i in 1..6 {
s.add(f64::from(i));
}
assert_eq!(s.min(), 1.0);
assert_eq!(s.max(), 5.0);
}
{
let mut s = MinMax::default();
for i in 1..6 {
s.add(f64::from(i));
}
assert_eq!(s.min(), 1.0);
assert_eq!(s.max(), 5.0);
}
{
let s: MinMax = (1..6).map(f64::from).collect();
assert_eq!(s.min(), 1.0);
assert_eq!(s.max(), 5.0);
}
}
#[test]
fn concatenate_moments_max() {
use average::{Max, Variance};
concatenate!(
Estimator,
[Variance, variance, mean, sample_variance],
[Max, max, max]
);
let e: Estimator = (1..6).map(f64::from).collect();
assert_eq!(e.mean(), 3.0);
assert_eq!(e.sample_variance(), 2.5);
assert_eq!(e.max(), 5.0);
}
#[cfg(any(feature = "std", feature = "libm"))]
#[test]
fn concatenate_moments_quantile() {
use average::{Quantile, Variance};
concatenate!(
Estimator,
[Variance, variance, mean, sample_variance],
[Quantile, quantile, quantile]
);
let e: Estimator = (1..6).map(f64::from).collect();
assert_eq!(e.mean(), 3.0);
assert_eq!(e.sample_variance(), 2.5);
assert_eq!(e.quantile(), 3.0);
}
#[test]
fn concatenate_pub() {
mod submodule {
use average::{concatenate, Min, Max, Estimate};
concatenate!(pub MinMax, [Min, min], [Max, max]);
}
let mut s = submodule::MinMax::new();
for i in 1..6 {
s.add(f64::from(i));
}
assert_eq!(s.min(), 1.0);
assert_eq!(s.max(), 5.0);
}