Skip to content

Improve and Validate TestingSequence assertions - #936

Merged
atifaziz merged 15 commits into
morelinq:masterfrom
viceroypenguin:testsequence-multi
Jan 28, 2023
Merged

Improve and Validate TestingSequence assertions#936
atifaziz merged 15 commits into
morelinq:masterfrom
viceroypenguin:testsequence-multi

Conversation

@viceroypenguin

@viceroypenguin viceroypenguin commented Jan 20, 2023

Copy link
Copy Markdown
Contributor

This PR updates the assertions made in TestingSequence:

  • Per the specification, it is not a failure to call .Dispose() multiple times. The .Dispose() method is expected to be idempotent, such that it is callable multiple times without throwing an exception. Updated to allow relying on this specification via Options.AllowRepeatedDispoals.
  • Per the specification, it is not a failure to call .MoveNext() after receiving a false response. The enumerator is simply expected to continue to return false for each following call. As such, we should not be afraid to take advantage of such behavior when it makes code easier (see Simplify ZipLongest implementation #905 for examples). Updated to allow relying on this specification via Options.AllowRepeatedMoveNexts.
  • While most IEnumerators do not complain when calling .MoveNext() after disposal, it does indicate an error in our code to expect that .MoveNext() is a valid behavior after we have disposed the iterator. As such, we should fail directly.
  • While most IEnumerators return a default or the last value when calling .Current after .MoveNext() returns false, the spec does not make any promises on the usefulness of .Current in this situation. More importantly, we should be relying on .MoveNext() return value and not attempting to reference .Current in these cases. As such, we should fail directly.
  • While most IEnumerators do not complain when calling .Current after disposal, it does indicate an error in our code to expect that .Current is a valid behavior after we have disposed the iterator. As such, we should fail directly.
  • Changing AllowMultipleEnumerations to an exact expectation of how many times the sequence should be enumerated.
  • Disallowing multiple simultaneous enumerations.
  • Adding unit tests to prove TestingSequence validates what it claims it validates; giving us better confidence that invalid MoreLinq and MoreLinq.Test code is written correctly.

@codecov

codecov Bot commented Jan 20, 2023

Copy link
Copy Markdown

Codecov Report

Merging #936 (1291504) into master (5b49471) will increase coverage by 0.04%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master     #936      +/-   ##
==========================================
+ Coverage   92.39%   92.44%   +0.04%     
==========================================
  Files         112      113       +1     
  Lines        3434     3453      +19     
  Branches     1021     1025       +4     
==========================================
+ Hits         3173     3192      +19     
+ Misses        199      196       -3     
- Partials       62       65       +3     
Impacted Files Coverage Δ
MoreLinq/ListLike.cs 86.95% <0.00%> (-5.91%) ⬇️
MoreLinq/AssertCount.cs 96.29% <0.00%> (-0.14%) ⬇️
MoreLinq/SkipLast.cs 100.00% <0.00%> (ø)
MoreLinq/TakeLast.cs 100.00% <0.00%> (ø)
MoreLinq/CollectionLike.cs 80.00% <0.00%> (ø)
MoreLinq/PadStart.cs 97.91% <0.00%> (+0.13%) ⬆️
MoreLinq/CountDown.cs 90.32% <0.00%> (+0.32%) ⬆️
MoreLinq/FallbackIfEmpty.cs 96.22% <0.00%> (+7.54%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@atifaziz

Copy link
Copy Markdown
Member

Depends on #901.

Sorry, but I'm confused. Doesn't this superseded #901 instead of depending on it?

@viceroypenguin

viceroypenguin commented Jan 20, 2023

Copy link
Copy Markdown
Contributor Author

Up to you - feels like separate PRs to me, given the nature of the work, but if you feel they're the same, then this one could be pulled directly without #901. PR description here updated as if single PR.

@viceroypenguin viceroypenguin changed the title Testsequence multi Improve and Validate TestingSequence assertions Jan 20, 2023

@atifaziz atifaziz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really a great set of improvements and having gone the extra distance to test the TestingSequence<T> implementation is just absolute bonus! Thanks!

I have made several suggestions to simplify things. Have a look and then I think we're good to merge soon.

Comment thread MoreLinq.Test/TestingSequence.cs Outdated
Comment thread MoreLinq.Test/TestingSequence.cs Outdated
Comment thread MoreLinq.Test/TestingSequence.cs
Comment thread MoreLinq.Test/TestingSequence.cs Outdated
Comment thread MoreLinq.Test/TestingSequence.cs Outdated
Comment thread MoreLinq.Test/TestingSequence.cs Outdated
Comment thread MoreLinq.Test/TestingSequence.cs Outdated
Comment thread MoreLinq.Test/TestingSequence.cs Outdated
Comment thread MoreLinq.Test/TestingSequence.cs Outdated
Comment thread MoreLinq.Test/TestingSequence.cs Outdated

@viceroypenguin viceroypenguin left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll address the code changes when I get a chance.

Comment thread MoreLinq.Test/TestingSequence.cs Outdated
Co-authored-by: Atif Aziz <code@raboof.com>
Comment thread MoreLinq.Test/TestingSequence.cs Outdated
Comment thread MoreLinq.Test/TestingSequence.cs Outdated

@atifaziz atifaziz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the improvements, follow-up and tests added with this PR! Good to merge! 🚀

@viceroypenguin

Copy link
Copy Markdown
Contributor Author

Woot! 🎉

@atifaziz
atifaziz merged commit d6953fc into morelinq:master Jan 28, 2023
@viceroypenguin
viceroypenguin deleted the testsequence-multi branch January 28, 2023 13:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants