How to assert that two collections are equivalent
Closed this issue · 5 comments
disklosr commented
Is there a way to check that 2 collections are equivalent (have the same items but not necessarily in the same order)?
Thanks
dupdob commented
Thank you for taking the time to create that issue!
Well, I realize there is no fully satisfying way to achieve that. I will open an issue to have a new check (IsEquivalent).
If you are sure the the enumeration does not contain any duplicate entries, you can use IsOnlyMadeOf
var integers = new[] { 1, 2, 3 };
Check.That(integers).IsOnlyMadeOf(3, 2, 1);
disklosr commented
Thanks. I ended up chaining IsOnlyMAdeOf with has Size to achieve the desired check.
Another thing I needed but didn't find is a check that a collection only contains unique elements.
dupdob commented
The current beta offers ContainsNoDuplicateItem to achieve that result.