Proposal: IsEquivalentTo matcher for IEnumerables ignoring order
See original GitHub issueHey, I would like to propose a matcher similar to IsSameSequenceAs, but one that ignores ordering. Similar to CollectionAssert.AreEquivalent()
.
My initial idea was to implement a new IsEquivalentTo
method that would have a required OrderByKey
parameter which would be used to order both enumerables and then call IsSameSequenceAs
internally for the matching.
Would like to know your opinions on it and if I should work on it.
Thanks in advance.
Issue Analytics
- State:
- Created 7 months ago
- Comments:11 (8 by maintainers)
Top Results From Across the Web
c# - Compare two List<T> objects for equality, ignoring order
I need to check that they both have the same elements, regardless of their position within the list. Each MyType object may appear...
Read more >HashSets are wrongly compared as IEnumerables where ...
cs where we try to match the individual elements, and this matching is done using CollectionTally.ItemsEqual(object expected, object actual) .
Read more >C# | Jon Skeet's coding blog | Page 11
It allows you to order any sequence implementing IEnumerable<T> – rather than Array.Sort being separate from List<T>.Sort, for example.
Read more >High Performance PowerShell with LINQ - Simple Talk
Casts the elements of an IEnumerable to the specified type, effectively converting IEnumerable to IEnumerable<T> , which then makes the sequence ...
Read more >4. Advanced C# - C# 10 in a Nutshell [Book]
Our Transform method is a higher-order function because it’s a function that takes a function as an argument. (A method that returns a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, I guess in typical unit tests you don’t work on very large lists… And what I said about using
EqualityComparer<T>.Default
doesn’t apply, unfortunately, because we won’t have aT
(well, we will, but it will be the type of the collection, not the type of the items). So we’ll just have to useEqualityComparer<object>.Default
instead.👍
I don’t think the efficiency is a big deal. Or at least we could be inefficient at first and see if it becomes one. I’m not against a more efficient solution, but if we don’t become convinced there’s a working and efficient solution, working inefficient is a reasonable tradeoff, IMO.