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
|
use crate::*;
macro_rules! test_fn {
($test_name:tt => $test_body:tt) => {
mini_paste::item! {
#[test]
fn $test_name() {
$test_body
}
}
};
}
macro_rules! test_edges_for {
($vtype:ty, P[$ptype:ty]) => {
test_edges_for!($vtype, P[$ptype], <$vtype>::MIN, <$vtype>::MAX);
};
($vtype:ty, P[$ptype:ty], $vmin:expr, $vmax:expr) => {
test_fn!([< test_ $vtype _min_by_ $ptype _min >] => {
assert!($vmin * Proportion::<$ptype>::MIN == $vmin);
});
test_fn!([< test_ $vtype _min_by_ $ptype _max >] => {
assert!($vmin * Proportion::<$ptype>::MAX == $vmin);
});
test_fn!([< test_ $vtype _max_by_ $ptype _min >] => {
assert!($vmax * Proportion::<$ptype>::MIN == $vmin);
});
test_fn!([< test_ $vtype _max_by_ $ptype _max >] => {
assert!($vmax * Proportion::<$ptype>::MAX == $vmax);
});
};
}
macro_rules! test_edges_for_ptype {
(P[$ptype:ty]) => {
test_edges_for!(u8, P[$ptype]);
test_edges_for!(u16, P[$ptype]);
test_edges_for!(u32, P[$ptype]);
test_edges_for!(f32, P[$ptype], 0.0, 1.0);
test_edges_for!(f64, P[$ptype], 0.0, 1.0);
};
}
test_edges_for_ptype!(P[u8]);
test_edges_for_ptype!(P[f32]);
test_edges_for_ptype!(P[f64]);
macro_rules! test_invert_for {
($ptype:ty) => {
test_fn!([< test_ $ptype _min_invert >] => {
assert!(Proportion::<$ptype>::MIN.invert().value == Proportion::<$ptype>::MAX.value);
});
test_fn!([< test_ $ptype _max_invert >] => {
assert!(Proportion::<$ptype>::MAX.invert().value == Proportion::<$ptype>::MIN.value);
});
}
}
test_invert_for!(u8);
test_invert_for!(f32);
test_invert_for!(f64);
// TODO: Test MAX*MID, MIN*MID, MID*MID=QUARTER
// test_fn!(test_u8_max_by_u8_mid => {
// assert!(u8::MAX * Proportion::<u8>::new(128) == 128u8);
// });
|