Assert that a large enumerable contains only the very same item n times?
See original GitHub issueI have a collection of 100K sample numbers. In one test case I want to assert that all of them are of the same value. I tried:
values.Should().AllBeEquivalentTo(5);
This takes quite some time (around five seconds). Which is WAY to long. Is this a bug in the implementation? Why is it taking so long? I think it’s the wrong function, but I couldn’t find a .AllBe(5)
for which I was looking for originally.
My workaround now is values.Distinct().Should().BeEquivalentTo(new[]{5});
but I don’t like it because it doesn’t express my intent.
Ideas on how to do that properly?
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (6 by maintainers)
Top Results From Across the Web
How can I efficiently determine if an IEnumerable has more ...
I prefer the first one since a common way to check whether Count() > ... decided if IEnumerable has at least n elements...
Read more >C#: IEnumerable, yield return, and lazy evaluation
Every time we iterate over numbers , it will start over at the beginning of the iterator method and yield all the same...
Read more >Enumerable.Contains Method (System.Linq)
Determines whether a sequence contains a specified element by using the default equality comparer.
Read more >Enumerable.Take Method (System.Linq)
Returns a specified number of contiguous elements from the start of a sequence.
Read more >module Enumerable - RDoc Documentation
An array (“chunk”) containing the element for which that value was returned, and all following elements for which the block returned the same...
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
@drauch Forget my last comment, I was looking at the wrong test after all. I confirm that execution time gets excessively long for larger collections.
Yes, we’re fixing up the last things to get 5.5.0 ready. https://github.com/fluentassertions/fluentassertions/milestone/12
So stay tuned, we’re also eager to get out a new release.