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::::new(128) == 128u8); // });