#![warn(
missing_docs,
missing_debug_implementations,
rust_2018_idioms,
unreachable_pub
)]
pub mod data;
pub use assert_approx_eq::assert_approx_eq;
#[track_caller]
pub fn assert_all_close(actual: &[f64], expected: &[f64]) {
assert_eq!(
actual.len(),
expected.len(),
"slices have different lengths"
);
for (actual, expected) in actual.iter().zip(expected) {
if actual.is_nan() {
assert!(expected.is_nan());
} else {
assert_approx_eq!(actual, expected, 1e-1);
}
}
}
#[macro_export]
macro_rules! assert_within_pct {
($a:expr, $b:expr, $tol:expr) => {
if $a == 0.0 {
assert!(
($b as f64).abs() < $tol,
"{} is not within {}% of 0",
$b,
$tol * 100.0
);
} else {
assert!(
(($a - $b) / $a).abs() < $tol,
"{} is not within {}% of {}",
$a,
$tol * 100.0,
$b
);
}
};
}