assert-unordered: A direct replacement for `assert_eq` for unordered collections
I went looking for this crate or something like it, but could not find anything (perhaps I missed it and it does exist?). I was surprised because it is very useful in some situations to not have to worry about collection order when comparing in tests. What I didn't realize was a crate like this is even more useful because it is specialized on collections and can therefore directly show ONLY the differences between left and right (vs. making the user visually scan for differences). I had planned to only use this in the rare circumstance when I needed unordered comparison for collections, but now plan to use it anytime ordering simply doesn't matter. Hopefully others find it useful as well.
UPDATE: 0.3.0 has been published which I think greatly simplifies the crate. Gone are the 3 macros reduced to just one. There are no limitations on inequalities not found and only Debug and PartiaEq is needed on the elements. The only downside is it is going to be O(n^2), but typically in tests we don't have huge datasets (and if you do, sorry, I weighed the simplification/easy of use and decided this made the most sense - can always use 0.2)
Example:
use assert_unordered::assert_eq_unordered;
#[derive(Debug, PartialEq)]
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!(expected, actual);
Output:
thread 'tests::test' panicked at 'The left did not contain the same items as the right:
In both: "[MyType(2), MyType(4)]"
In left: "[MyType(1), MyType(5)]"
In right: "[MyType(0)]"'