feat: remove trait bound DefinedOrderProperty from iterator assertions - #97
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #97 +/- ##
=======================================
Coverage 87.84% 87.84%
=======================================
Files 42 42
Lines 7513 7513
Branches 7513 7513
=======================================
Hits 6600 6600
Misses 843 843
Partials 70 70 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Assertions on iterators such as
.contains_exactly(in order) or.first_element()only make sense on iterators that yield the elements in a well defined order. Therefore we defined theDefinedOrderPropertytrait to make all iterators that yield their elements in a well defined order and allow the users to write assertions that rely on a well defined order only for iterators that implement theDefinedOrderPropertytrait. In practice this turned out to be more painful than helpful.The problem with this design:
Currently when we want to write an assertion for a "composite" iterator where we know the elements are yielded in a well defined order, the compiler prevents us from doing so. The trait
DefinedOrderPropertyis not implemented forMaporSkiporTake.The following example won't compile, although we know the elements are yielded in the same order as defined in the array:
The solution:
We remove the trait bounds on
DefinedOrderPropertyfrom the assertion-methods for iterators.The drawback is, that we can now use
.contains_exactlyalso on hashsets and other types that yield the elements in an undefined order. The test might be flaky, because sometimes the order is as expected and sometimes it is not. So it is up to the user to carefully choose the right assertion method.With this pull request the trait bounds on
DefinedOderPropertyare removed from all assertion methods for iterators.