Expand description
Assert for approximations.
These macros compare numbers, such as two floating point numbers, where one number may be very close to another number but not quite equal.
-
assert_approx_eq!(a, b)≈ a is approximately equal to b -
assert_approx_ne!(a, b)≈ a is approximately not equal to b -
assert_approx_eq_with_absolute_error!(a, b, Δ)≈ a is approximately equal to b by using absolute error a.k.a. delta. -
assert_approx_ne_with_absolute_error!(a, b, Δ)≈ a is approximately not equal to b by using absolute error a.k.a. delta. -
assert_approx_eq_with_relative_error!(a, b, ε)≈ a is approximately equal to b by using relative error a.k.a. epsilon. -
assert_approx_ne_with_relative_error!(a, b, ε)≈ a is approximately not equal to b by using relative error a.k.a. epsilon.
§Example
use assertables::*;
let a: f32 = 1.0000001;
let b: f32 = 1.0000011;
assert_approx_eq!(a, b);Modules§
- assert_
approx_ eq - Assert a number is approximately equal to another.
- assert_
approx_ eq_ with_ absolute_ error - Assert a number is approximately equal to another by using absolute error a.k.a. delta.
- assert_
approx_ eq_ with_ relative_ error - Assert a number is approximately equal to another by using relative error a.k.a. epsilon.
- assert_
approx_ ne - Assert a number is approximately not equal to another.
- assert_
approx_ ne_ with_ absolute_ error - Assert a number is approximately not equal to another by using absolute error a.k.a. delta.
- assert_
approx_ ne_ with_ relative_ error - Assert a number is approximately not equal to another by using relative error a.k.a. epsilon.