Trait assertor::FloatAssertion
source · pub trait FloatAssertion<'a, S, R> {
// Required methods
fn with_rel_tol(self, rel_tol: S) -> Subject<'a, S, FloatTolerance<S>, R>;
fn with_abs_tol(self, abs_tol: S) -> Subject<'a, S, FloatTolerance<S>, R>;
fn is_approx_equal_to<B: Borrow<S>>(&self, expected: B) -> R
where FloatTolerance<S>: Default;
}
Expand description
Trait for float assertion.
Example
use assertor::*;
assert_that!(0.1_f32).is_approx_equal_to(0.1);
assert_that!(0.1_f32)
.with_abs_tol(0.5)
.is_approx_equal_to(0.5);
assert_that!(0.1_f64)
.with_rel_tol(0.2)
.is_approx_equal_to(0.12); // 0.1 ± 0.12 * 0.2
Required Methods§
sourcefn with_rel_tol(self, rel_tol: S) -> Subject<'a, S, FloatTolerance<S>, R>
fn with_rel_tol(self, rel_tol: S) -> Subject<'a, S, FloatTolerance<S>, R>
Set the relative tolerance.
sourcefn with_abs_tol(self, abs_tol: S) -> Subject<'a, S, FloatTolerance<S>, R>
fn with_abs_tol(self, abs_tol: S) -> Subject<'a, S, FloatTolerance<S>, R>
Set the absolute tolerance.
sourcefn is_approx_equal_to<B: Borrow<S>>(&self, expected: B) -> Rwhere
FloatTolerance<S>: Default,
fn is_approx_equal_to<B: Borrow<S>>(&self, expected: B) -> Rwhere FloatTolerance<S>: Default,
Checks the subject is equal to expected
with tolerance.
The equality with tolerance is defined as following:
abs(actual - expected) <= (asb_tol + rel_tol * abs(expected))
See also: numpy.isclose