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§

source

fn with_rel_tol(self, rel_tol: S) -> Subject<'a, S, FloatTolerance<S>, R>

Set the relative tolerance.

source

fn with_abs_tol(self, abs_tol: S) -> Subject<'a, S, FloatTolerance<S>, R>

Set the absolute tolerance.

source

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

Implementors§

source§

impl<'a, S, R> FloatAssertion<'a, S, R> for Subject<'a, S, FloatTolerance<S>, R>where S: Float + Debug, AssertionResult: AssertionStrategy<R>,

source§

impl<'a, S, R: 'a> FloatAssertion<'a, S, R> for Subject<'a, S, (), R>where S: Float + Debug, AssertionResult: AssertionStrategy<R>,