-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
add missing constructor for ReverseOrdering() and tidy sort tests #33736
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,45 +2,62 @@ | |
|
||
module SortingTests | ||
|
||
using Base.Order: Forward | ||
using Base.Order | ||
using Random | ||
using Test | ||
|
||
@test sort([2,3,1]) == [1,2,3] | ||
@test sort([2,3,1], rev=true) == [3,2,1] | ||
@test sort(['z':-1:'a';]) == ['a':'z';] | ||
@test sort(['a':'z';], rev=true) == ['z':-1:'a';] | ||
@test sortperm([2,3,1]) == [3,1,2] | ||
@test sortperm!([1,2,3], [2,3,1]) == [3,1,2] | ||
let s = view([1,2,3,4], 1:3), | ||
r = sortperm!(s, [2,3,1]) | ||
@test r == [3,1,2] | ||
@test r === s | ||
@testset "Order" begin | ||
@test Forward == ForwardOrdering() | ||
@test ReverseOrdering(Forward) == ReverseOrdering() == Reverse | ||
end | ||
@test_throws ArgumentError sortperm!(view([1,2,3,4], 1:4), [2,3,1]) | ||
@test !issorted([2,3,1]) | ||
@test issorted([1,2,3]) | ||
@test reverse([2,3,1]) == [1,3,2] | ||
@test partialsort([3,6,30,1,9],3) == 6 | ||
@test partialsort([3,6,30,1,9],3:4) == [6,9] | ||
@test partialsortperm([3,6,30,1,9], 3:4) == [2,5] | ||
@test partialsortperm!(Vector(1:5), [3,6,30,1,9], 3:4) == [2,5] | ||
let a=[1:10;] | ||
for r in Any[2:4, 1:2, 10:10, 4:2, 2:1, 4:-1:2, 2:-1:1, 10:-1:10, 4:1:3, 1:2:8, 10:-3:1, UInt(2):UInt(5)] | ||
@test partialsort(a, r) == [r;] | ||
@test partialsortperm(a, r) == [r;] | ||
@test partialsort(a, r, rev=true) == (11 .- [r;]) | ||
@test partialsortperm(a, r, rev=true) == (11 .- [r;]) | ||
|
||
|
||
@testset "sort" begin | ||
@test sort([2,3,1]) == [1,2,3] == sort([2,3,1]; order=Forward) | ||
@test sort([2,3,1], rev=true) == [3,2,1] == sort([2,3,1], order=Reverse) | ||
@test sort(['z':-1:'a';]) == ['a':'z';] | ||
@test sort(['a':'z';], rev=true) == ['z':-1:'a';] | ||
end | ||
|
||
@testset "sortperm" begin | ||
@test sortperm([2,3,1]) == [3,1,2] | ||
@test sortperm!([1,2,3], [2,3,1]) == [3,1,2] | ||
let s = view([1,2,3,4], 1:3), | ||
r = sortperm!(s, [2,3,1]) | ||
@test r == [3,1,2] | ||
@test r === s | ||
end | ||
for i in (2, UInt(2), Int128(1), big(10)) | ||
@test partialsort(a, i) == i | ||
@test partialsortperm(a, i) == i | ||
@test partialsort(a, i, rev=true) == (11 - i) | ||
@test partialsortperm(a, i, rev=true) == (11 - i) | ||
@test_throws ArgumentError sortperm!(view([1,2,3,4], 1:4), [2,3,1]) | ||
end | ||
|
||
@testset "misc sorting" begin | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not extatic about this testsets name. |
||
@test !issorted([2,3,1]) | ||
@test issorted([1,2,3]) | ||
@test reverse([2,3,1]) == [1,3,2] | ||
@test sum(randperm(6)) == 21 | ||
end | ||
|
||
@testset "partialsort" begin | ||
@test partialsort([3,6,30,1,9],3) == 6 | ||
@test partialsort([3,6,30,1,9],3:4) == [6,9] | ||
@test partialsortperm([3,6,30,1,9], 3:4) == [2,5] | ||
@test partialsortperm!(Vector(1:5), [3,6,30,1,9], 3:4) == [2,5] | ||
let a=[1:10;] | ||
for r in Any[2:4, 1:2, 10:10, 4:2, 2:1, 4:-1:2, 2:-1:1, 10:-1:10, 4:1:3, 1:2:8, 10:-3:1, UInt(2):UInt(5)] | ||
@test partialsort(a, r) == [r;] | ||
@test partialsortperm(a, r) == [r;] | ||
@test partialsort(a, r, rev=true) == (11 .- [r;]) | ||
@test partialsortperm(a, r, rev=true) == (11 .- [r;]) | ||
end | ||
for i in (2, UInt(2), Int128(1), big(10)) | ||
@test partialsort(a, i) == i | ||
@test partialsortperm(a, i) == i | ||
@test partialsort(a, i, rev=true) == (11 - i) | ||
@test partialsortperm(a, i, rev=true) == (11 - i) | ||
end | ||
end | ||
@test_throws ArgumentError partialsortperm!([1,2], [2,3,1], 1:2) | ||
end | ||
@test_throws ArgumentError partialsortperm!([1,2], [2,3,1], 1:2) | ||
@test sum(randperm(6)) == 21 | ||
|
||
@testset "searchsorted" begin | ||
numTypes = [ Int8, Int16, Int32, Int64, Int128, | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the focus of this PR