@@ -1036,40 +1036,30 @@ end
1036
1036
@test issorted (sort! (rand (100 ), Base. Sort. InitialOptimizations (DispatchLoopTestAlg ()), Base. Order. Forward))
1037
1037
end
1038
1038
1039
- @testset " partialsort tests added for BracketedSort #52006" begin
1040
- x = rand (Int, 1000 )
1041
- @test partialsort (x, 1 ) == minimum (x)
1042
- @test partialsort (x, 1000 ) == maximum (x)
1043
- sx = sort (x)
1044
- for i in [1 , 2 , 4 , 10 , 11 , 425 , 500 , 845 , 991 , 997 , 999 , 1000 ]
1045
- @test partialsort (x, i) == sx[i]
1046
- end
1047
- for i in [1 : 1 , 1 : 2 , 1 : 5 , 1 : 8 , 1 : 9 , 1 : 11 , 1 : 108 , 135 : 812 , 220 : 586 , 363 : 368 , 450 : 574 , 458 : 597 , 469 : 638 , 487 : 488 , 500 : 501 , 584 : 594 , 1000 : 1000 ]
1048
- @test partialsort (x, i) == sx[i]
1039
+ # Pathologize 0 is a noop, pathologize 3 is fully pathological
1040
+ function pathologize! (x, level)
1041
+ Base. require_one_based_indexing (x)
1042
+ k2 = Int (cbrt (length (x))^ 2 )
1043
+ seed = hash (length (x), Int === Int64 ? 0x85eb830e0216012d : 0xae6c4e15 )
1044
+ for a in 1 : level
1045
+ seed = hash (a, seed)
1046
+ x[mod .(hash .(1 : k2, seed), range .(1 : k2,lastindex (x)))] .= a
1049
1047
end
1048
+ x
1049
+ end
1050
1050
1051
- # Semi-pathological input
1052
- seed = hash (1000 , Int === Int64 ? 0x85eb830e0216012d : 0xae6c4e15 )
1053
- seed = hash (1 , seed)
1054
- for i in 1 : 100
1055
- j = mod (hash (i, seed), i: 1000 )
1056
- x[j] = typemax (Int)
1051
+ @testset " partialsort tests added for BracketedSort #52006" begin
1052
+ for x in [pathologize! .(Ref (rand (Int, 1000 )), 0 : 3 ); pathologize! .(Ref (rand (1000 )), 0 : 3 ); [pathologize! (rand (Int, 1_000_000 ), 3 )]]
1053
+ @test partialsort (x, 1 ) == minimum (x)
1054
+ @test partialsort (x, lastindex (x)) == maximum (x)
1055
+ sx = sort (x)
1056
+ for i in [1 , 2 , 4 , 10 , 11 , 425 , 500 , 845 , 991 , 997 , 999 , 1000 ]
1057
+ @test partialsort (x, i) == sx[i]
1058
+ end
1059
+ for i in [1 : 1 , 1 : 2 , 1 : 5 , 1 : 8 , 1 : 9 , 1 : 11 , 1 : 108 , 135 : 812 , 220 : 586 , 363 : 368 , 450 : 574 , 458 : 597 , 469 : 638 , 487 : 488 , 500 : 501 , 584 : 594 , 1000 : 1000 ]
1060
+ @test partialsort (x, i) == sx[i]
1061
+ end
1057
1062
end
1058
- @test partialsort (x, 500 ) == sort (x)[500 ]
1059
-
1060
- # Fully pathological input
1061
- # it would be too much trouble to actually construct a valid pathological input, so we
1062
- # construct an invalid pathological input.
1063
- # This test is kind of sketchy because it passes invalid inputs to the function
1064
- # Temporarily removed due to flakey test failures. See #52642 for details.
1065
- # for i in [1:6, 1:483, 1:957, 77:86, 118:478, 223:227, 231:970, 317:958, 500:501, 500:501, 500:501, 614:620, 632:635, 658:665, 933:940, 937:942, 997:1000, 999:1000]
1066
- # x = rand(1:5, 1000)
1067
- # @test partialsort(x, i, lt=(<=)) == sort(x)[i]
1068
- # end
1069
- # for i in [1, 7, 8, 490, 495, 852, 993, 996, 1000]
1070
- # x = rand(1:5, 1000)
1071
- # @test partialsort(x, i, lt=(<=)) == sort(x)[i]
1072
- # end
1073
1063
end
1074
1064
1075
1065
# This testset is at the end of the file because it is slow.
0 commit comments