macro_rules! assert_approx_eq_all {
(tolerance: $tolerance:expr, $first:expr, $($rest:expr),+ $(,)?) => { ... };
}
Expand description
Asserts the approximate equality of a series of expressions within tolerance
.
This macro should work with any numeric type that supports comparison and subtraction, including signed and unsigned integers and floating-point numbers.
The given $tolerance
must be a non-negative number.
§Panics
§Examples
The following examples compile:
assert_approx_eq_all![tolerance: 0.01, 1.0, 1.001, 0.999]; // up to 0.01 away from 1.0
assert_approx_eq_all![tolerance: 1_u32, 4, 3, 5]; // up to 1 away from 4
assert_approx_eq_all![tolerance: 0.01, -1.0, -1.001, -0.999];
assert_approx_eq_all![tolerance: 1_i32, -4, -3, -5];
assert_approx_eq_all![tolerance: 0_i32, 3, 3];
The following examples panic:
ⓘ
assert_approx_eq_all![tolerance: 0.01, 1.0, 1.001, 0.989]; // |0.989 - 1.0| > |0.01|
ⓘ
assert_approx_eq_all![tolerance: 1_u32, 4, 3, 5, 6]; // |6 - 4| > |1|
ⓘ
assert_approx_eq_all![tolerance: 1_u32, 3, 4, 5]; // |5 - 3| > |1|
ⓘ
assert_approx_eq_all![tolerance: -0.01, 1.0, 1.001, 0.999]; // tolerance: -0.01 < 0
ⓘ
assert_approx_eq_all![tolerance: -1_i32, 4, 3, 5]; // tolerance: -1 < 0