1#![warn(
7 missing_docs,
8 missing_debug_implementations,
9 rust_2018_idioms,
10 unreachable_pub
11)]
12
13pub mod data;
14
15pub use assert_approx_eq::assert_approx_eq;
16
17#[track_caller]
19pub fn assert_all_close(actual: &[f64], expected: &[f64]) {
20 assert_eq!(
21 actual.len(),
22 expected.len(),
23 "slices have different lengths"
24 );
25 for (actual, expected) in actual.iter().zip(expected) {
26 if actual.is_nan() {
27 assert!(expected.is_nan());
28 } else {
29 assert_approx_eq!(actual, expected, 1e-1);
30 }
31 }
32}
33
34#[macro_export]
36macro_rules! assert_within_pct {
37 ($a:expr, $b:expr, $tol:expr) => {
38 if $a == 0.0 {
39 assert!(
40 ($b as f64).abs() < $tol,
41 "{} is not within {}% of 0",
42 $b,
43 $tol * 100.0
44 );
45 } else {
46 assert!(
47 (($a - $b) / $a).abs() < $tol,
48 "{} is not within {}% of {}",
49 $a,
50 $tol * 100.0,
51 $b
52 );
53 }
54 };
55}