-
-
Notifications
You must be signed in to change notification settings - Fork 554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assert that a large enumerable contains only the very same item n times? #914
Comments
It's a performance bug. The current implementation is using a very naive approach. |
@dennisdoomen Are you going to fix it or can I jump in? |
By all means, jump in |
@drauch I have just tried to reproduce the problem with following test. [Fact] public void When_some_subject_items_are_not_equivalent_to_expectation_for_huge_table_execution_time_should_still_be_short()
{
//-----------------------------------------------------------------------------------------------------------
// Arrange
//-----------------------------------------------------------------------------------------------------------
const int N = 1000000;
var subject = new List<int>(N) {1};
for (int i = 1; i < N; i++)
{
subject.Add(2);
}
//-----------------------------------------------------------------------------------------------------------
// Act
//-----------------------------------------------------------------------------------------------------------
Action action = () =>
{
try { subject.Should().AllBeEquivalentTo(1); }
catch (Exception)
{
// ignored, we only care about execution time
}
};
////-----------------------------------------------------------------------------------------------------------
//// Assert
////-----------------------------------------------------------------------------------------------------------
action.ExecutionTime().Should().BeLessThan(150.Milliseconds());
} On my machine it always passes, even for more elements than 100K. Could you provide minimal, complete and verifiable example? |
@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. |
Thanks! |
Are you going to release this soon? :) |
Yes, we're fixing up the last things to get 5.5.0 ready. So stay tuned, we're also eager to get out a new release. |
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:
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?
The text was updated successfully, but these errors were encountered: