Improve TestingSequence assertions - #901
Closed
viceroypenguin wants to merge 4 commits into
Closed
Conversation
TestingSequence assertions
Codecov Report
@@ Coverage Diff @@
## master #901 +/- ##
=======================================
Coverage 92.41% 92.41%
=======================================
Files 112 112
Lines 3439 3439
Branches 1021 1021
=======================================
Hits 3178 3178
Misses 199 199
Partials 62 62 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Contributor
Author
|
A future PR will make additional improvements, similar to viceroypenguin/SuperLinq#143.
|
atifaziz
requested changes
Jan 19, 2023
atifaziz
left a comment
Member
There was a problem hiding this comment.
I like the extra checks. However, even though the specification allows the following:
- 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. As such, we should not be afraid to take advantage of such behavior when it makes code easier.- Per the specification, it is not a failure to call
.MoveNext()after receiving afalseresponse. The enumerator is simply expected to continue to returnfalsefor each following call. As such, we should not be afraid to take advantage of such behavior when it makes code easier (see SimplifyZipLongestimplementation #905 for examples).
I would make it an option rather than a default of TestingSequence for 3 reasons:
- We've almost never needed to rely on this so far.
- It should be very obvious in tests if someone is relying on such allowed behaviour and it should be challenged because doing extra work should be avoided if it can be helped.
- A hard-written implementation could be buggy on edges because not everyone reads the documentation/specifications and so if one can avoid inducing such bugs then it saves everyone time and trouble.
Member
|
This has been superseded by PR #936. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR updates the assertions made in
TestingSequence:.Dispose()multiple times. The.Dispose()method is expected to be idempotent, such that it is callable multiple times without throwing an exception. As such, we should not be afraid to take advantage of such behavior when it makes code easier..MoveNext()after receiving afalseresponse. The enumerator is simply expected to continue to returnfalsefor each following call. As such, we should not be afraid to take advantage of such behavior when it makes code easier (see SimplifyZipLongestimplementation #905 for examples).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.IEnumerators return a default or the last value when calling.Currentafter.MoveNext()returnsfalse, the spec does not make any promises on the usefulness of.Currentin this situation. More importantly, we should be relying on.MoveNext()return value and not attempting to reference.Currentin these cases. As such, we should fail directly.IEnumerators do not complain when calling.Currentafter disposal, it does indicate an error in our code to expect that.Currentis a valid behavior after we have disposed the iterator. As such, we should fail directly.