question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Assert that a large enumerable contains only the very same item n times?

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
krajekcommented, Sep 19, 2018

@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.

0reactions
jnyrupcommented, Oct 21, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found