Skip to main content

CollectionAbsDiffAssertions

Trait CollectionAbsDiffAssertions 

Source
pub trait CollectionAbsDiffAssertions<C>{
    // Required methods
    fn contains_items_close_to<E, O>(self, expected: E, offset: O) -> Self
       where E: Borrow<C::Item>,
             O: Borrow<<C::Item as AbsDiff>::ReturnType>;
    fn contains_only_items_close_to<E, O>(self, expected: E, offset: O) -> Self
       where E: Borrow<C::Item>,
             O: Borrow<<C::Item as AbsDiff>::ReturnType>;
    fn does_not_contain_items_close_to<E, O>(
        self,
        expected: E,
        offset: O,
    ) -> Self
       where E: Borrow<C::Item>,
             O: Borrow<<C::Item as AbsDiff>::ReturnType>;
    fn contains_exactly_in_any_order_close_to<E, I, O>(
        self,
        items: I,
        offset: O,
    ) -> Self
       where E: Borrow<C::Item>,
             I: IntoIterator<Item = E>,
             O: Borrow<<C::Item as AbsDiff>::ReturnType> + Debug;
}
Expand description

An extension trait to be used on the output of assert_that with an argument that implements the Collection trait and whose Collection::Item type implements AbsDiff with a AbsDiff::ReturnType that implements PartialOrd. It can be seen as an approximate version of CollectionPartialEqAssertions.

Examples:

use kernal::prelude::*;

assert_that!([1.0, 1.5, 2.0])
    .contains_items_close_to(0.9, 0.2)
    .does_not_contain_items_close_to(5.0, 0.2);

Required Methods§

Source

fn contains_items_close_to<E, O>(self, expected: E, offset: O) -> Self
where E: Borrow<C::Item>, O: Borrow<<C::Item as AbsDiff>::ReturnType>,

Asserts that the tested collection contains at least one item that is within offset of expected according to AbsDiff and PartialOrd. More formally, for some item e it holds that e.abs_diff(expected) <= offset.

Source

fn contains_only_items_close_to<E, O>(self, expected: E, offset: O) -> Self
where E: Borrow<C::Item>, O: Borrow<<C::Item as AbsDiff>::ReturnType>,

Asserts that all items of the tested collection are within offset of expected according to AbsDiff and PartialOrd. More formally, for all items e it holds that e.abs_diff(expected) <= offset.

Source

fn does_not_contain_items_close_to<E, O>(self, expected: E, offset: O) -> Self
where E: Borrow<C::Item>, O: Borrow<<C::Item as AbsDiff>::ReturnType>,

Asserts that the tested collection does not contain items that are within offset of expected according to AbsDiff and PartialOrd. More formally, for all items e it holds that e.abs_diff(expected) > offset.

Source

fn contains_exactly_in_any_order_close_to<E, I, O>( self, items: I, offset: O, ) -> Self
where E: Borrow<C::Item>, I: IntoIterator<Item = E>, O: Borrow<<C::Item as AbsDiff>::ReturnType> + Debug,

Asserts there is a 1:1 matching of items in the tested collection and the given expected items such that each matched pair is within offset of each other according to AbsDiff and PartialOrd. This can be seen as a version of CollectionPartialEqAssertions::contains_exactly_in_any_order where equality is only approximate, controlled by offset.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§