macro_rules! assert_pos_relative_eq {
($left:expr, $right:expr, $epsilon:expr) => { ... };
}Expand description
Asserts that two Positive values are relatively equal within a given epsilon.
This macro compares two Positive values and checks if their relative difference
is within the specified epsilon. It handles cases where one or both values
are zero, ensuring that the non-zero value is less than or equal to epsilon.
§Examples
use positive::Positive;
use positive::{assert_pos_relative_eq, pos_or_panic};
let a = pos_or_panic!(1.0);
let b = pos_or_panic!(1.0001);
let epsilon = pos_or_panic!(0.001);
assert_pos_relative_eq!(a, b, epsilon); // Passes
let c = pos_or_panic!(1.0);
let d = pos_or_panic!(2.0);
let epsilon = pos_or_panic!(0.001);
#[test]
#[should_panic]
assert_pos_relative_eq!(c, d, epsilon); // Panics
let e = pos_or_panic!(0.0);
let f = pos_or_panic!(0.0001);
let epsilon = pos_or_panic!(0.001);
assert_pos_relative_eq!(e, f, epsilon); // Passes
let g = pos_or_panic!(0.0);
let h = pos_or_panic!(0.0011);
let epsilon = pos_or_panic!(0.001);
#[test]
#[should_panic]
assert_pos_relative_eq!(g, h, epsilon); // Panics§Panics
This macro panics if the relative difference between the two values is greater than
the specified epsilon, or if one value is zero and the other is greater than epsilon.
The panic message includes the values being compared, the expected relative difference,
and the actual relative difference.