macro_rules! assert_eq_unordered_sort {
    ($left:expr, $right:expr $(,)?) => { ... };
    ($left:expr, $right:expr, $($arg:tt)+) => { ... };
}
Expand description

Assert that $left and $right are “unordered” equal. That is, they contain the same elements, but not necessarily in the same order. If this assertion is false, a panic is raised, and the elements that are different between $left and $right are shown (when possible).

Both $left and $right must be of the same type and implement PartialEq and Iterator or IntoIterator, but otherwise can be any type. The iterator Item type can be any type that implements Debug, Ord, and Eq. Optional $arg parameters may be given to customize the error message, if any (these are the same as the parameters passed to format!).

Efficiency

If $left and $right are equal, this assertion is quite efficient just doing a regular equality check and then returning. If they are not equal, $left and $right are sorted and compared again. If still not equal, the elements compared one by one for both $left and $right (meaning it is at least O(n^2) algorithmic complexity, if not equal by this point).

Example

use assert_unordered::assert_eq_unordered_sort;

#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]
struct MyType(i32);

let expected = vec![MyType(1), MyType(2), MyType(4), MyType(5)];
let actual = vec![MyType(2), MyType(0), MyType(4)];

assert_eq_unordered_sort!(expected, actual);

Output:

example_error