assert.IsIncreasing et al: support sort.Interface - #1124
Open
brackendawson wants to merge 4 commits into
Open
Conversation
If you passed a non-collection to IsIncreasing or any of its compatriots then the assertion would return false without failing the test.
The auto-generated functions are already correct
brackendawson
force-pushed
the
sort-interface
branch
from
October 29, 2021 18:45
6cad687 to
ad092bc
Compare
The test was failing in github actions. This change moves a possible allocation in NewTimer() out of the window between the asyncCall starting and the timer elapsing. As the allocation would be before the timer is started this does not risk making the timer effectively 0ms.
dittrichlucas
approved these changes
Oct 31, 2021
Collaborator
|
This will have to be rebased once #1430 is merged. |
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.
Summary
Support collections which implement
sort.Interfaceas objects toIsIncreasing,IsNonDecreasing,IsDecreasing&IsNonIncreasing.Changes
IsIncreasing,IsNonDecreasing,IsDecreasing&IsNonIncreasing, if a non-collection is passed as object then the assertion returns false without failing the test. 😱IsIncreasing,IsNonDecreasing,IsDecreasing&IsNonIncreasinginto helper functions, they already should be and their generated siblings already are.IsIncreasing,IsNonDecreasing,IsDecreasingorIsNonIncreasingimplementssort.Interface, check its ordering using that interface. This is done first as a performance concern because the algorithm does not use reflection.Motivation
If you have a collection which implements
sort.Interface, you can now assert the four ordering primitives against it. ForIsIncreasingthis could have been expressed asassert.True(t, sort.IsSorted(object)), but forIsNonDecreasing,IsDecreasingorIsNonIncreasingyou would have to write the algorithm in the test.Related issues
closes #1122