Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

56
assert-unordered: A direct replacement for `assert_eq` for unordered collections
Post Body

Github | Crates.io | Docs.rs

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 are needed on the elements. The only downside is it is going to be O(n2), 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)

UPDATE 2: As of 0.3.2, output is now in color like that of pretty_assertions. I can't figure out how to put an image link in reddit markdown, so use the github or crates.io link to see what it looks like.

UPDATE 3: Since two different people mentioned it, I gave it more thought, and decided it made sense to add a sort variant again. It is available from 0.3.4 onward.

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)]"'

Author
Account Strength
90%
Account Age
13 years
Verified Email
Yes
Verified Flair
No
Total Karma
2,295
Link Karma
366
Comment Karma
1,909
Profile updated: 3 days ago
Posts updated: 1 year ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
2 years ago