galvanic_assert::matchers::collection

Function sorted_strictly_by

Source
pub fn sorted_strictly_by<'a, T, I, P>(
    predicate: P,
    expected_ordering: Ordering,
) -> Box<dyn Fn(&'a I) -> MatchResult>
where &'a I: IntoIterator<Item = &'a T> + 'a, T: Ord + Debug + 'a, P: Fn(&'a T, &'a T) -> Ordering + 'static,
Expand description

Matches if the elements in the asserted collection are sorted strictly monotone according to the given predicate in the expected order`.

The predicate is applied to all consecutive pairs of elements and returns the Ordering of the pair. The ordering is allowed to be weakly monotone, i.e., equal elements are allowed to follow each other. An empty collection is assumed to be always sorted.

#Examples

use galvanic_assert::matchers::collection::*;
use std::cmp::Ordering;
assert_that!(&vec![1,2,3,4,5,6], sorted_strictly_by(|a: &i32, b: &i32| a.cmp(b), Ordering::Less));