Function galvanic_assert::matchers::collection::sorted_by [] [src]

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

Matches if the elements in the asserted collection are sorted weakly 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,2,3,3,4,5,6], sorted_by(|a: &i32, b: &i32| a.cmp(b), Ordering::Less));