Skip to content

Commit 1983b27

Browse files
committed
tidy test cases added by #47066
1 parent d0b15c2 commit 1983b27

File tree

4 files changed

+51
-64
lines changed

4 files changed

+51
-64
lines changed

test/choosetests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ function choosetests(choices = [])
142142
filtertests!(tests, "subarray")
143143
filtertests!(tests, "compiler", [
144144
"compiler/datastructures", "compiler/inference", "compiler/effects",
145-
"compiler/validation", "compiler/sort", "compiler/ssair", "compiler/irpasses",
145+
"compiler/validation", "compiler/ssair", "compiler/irpasses",
146146
"compiler/codegen", "compiler/inline", "compiler/contextual",
147147
"compiler/AbstractInterpreter", "compiler/EscapeAnalysis/local",
148148
"compiler/EscapeAnalysis/interprocedural"])

test/compiler/datastructures.jl

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,47 @@ end
5454
end
5555
end
5656

57-
# Make sure that the compiler can sort things.
58-
# https://github.com/JuliaLang/julia/issues/47065
59-
@testset "Compiler Sorting" begin
60-
for len in (0, 1, 10, 100, 10000)
61-
v = Core.Compiler.sort!(rand(Int8,len))
62-
@test length(v) == len
63-
@test issorted(v)
64-
Core.Compiler.sort!(v, by=abs)
65-
@test issorted(v, by=abs)
57+
@testset "searchsorted" begin
58+
@test Core.Compiler.searchsorted([1, 1, 2, 2, 3, 3], 0) === Core.Compiler.UnitRange(1, 0)
59+
@test Core.Compiler.searchsorted([1, 1, 2, 2, 3, 3], 1) === Core.Compiler.UnitRange(1, 2)
60+
@test Core.Compiler.searchsorted([1, 1, 2, 2, 3, 3], 2) === Core.Compiler.UnitRange(3, 4)
61+
@test Core.Compiler.searchsorted([1, 1, 2, 2, 3, 3], 4) === Core.Compiler.UnitRange(7, 6)
62+
@test Core.Compiler.searchsorted([1, 1, 2, 2, 3, 3], 2.5; lt=<) === Core.Compiler.UnitRange(5, 4)
63+
64+
@test Core.Compiler.searchsorted(Core.Compiler.UnitRange(1, 3), 0) === Core.Compiler.UnitRange(1, 0)
65+
@test Core.Compiler.searchsorted(Core.Compiler.UnitRange(1, 3), 1) === Core.Compiler.UnitRange(1, 1)
66+
@test Core.Compiler.searchsorted(Core.Compiler.UnitRange(1, 3), 2) === Core.Compiler.UnitRange(2, 2)
67+
@test Core.Compiler.searchsorted(Core.Compiler.UnitRange(1, 3), 4) === Core.Compiler.UnitRange(4, 3)
68+
69+
@test Core.Compiler.searchsorted([1:10;], 1, by=(x -> x >= 5)) === Core.Compiler.UnitRange(1, 4)
70+
@test Core.Compiler.searchsorted([1:10;], 10, by=(x -> x >= 5)) === Core.Compiler.UnitRange(5, 10)
71+
@test Core.Compiler.searchsorted([1:5; 1:5; 1:5], 1, 6, 10, Core.Compiler.Forward) === Core.Compiler.UnitRange(6, 6)
72+
@test Core.Compiler.searchsorted(fill(1, 15), 1, 6, 10, Core.Compiler.Forward) === Core.Compiler.UnitRange(6, 10)
73+
74+
for (rg,I) in Any[(Core.Compiler.UnitRange(49, 57), 47:59),
75+
(Core.Compiler.StepRange(1, 2, 17), -1:19)]
76+
rg_r = Core.Compiler.reverse(rg)
77+
rgv, rgv_r = Core.Compiler.collect(rg), Core.Compiler.collect(rg_r)
78+
for i = I
79+
@test Core.Compiler.searchsorted(rg,i) === Core.Compiler.searchsorted(rgv,i)
80+
@test Core.Compiler.searchsorted(rg_r,i,rev=true) === Core.Compiler.searchsorted(rgv_r,i,rev=true)
81+
end
82+
end
83+
end
84+
85+
@testset "basic sort" begin
86+
v = [3,1,2]
87+
@test v == [3,1,2]
88+
@test Core.Compiler.sort!(v) === v == [1,2,3]
89+
@test Core.Compiler.sort!(v, by = x -> -x) === v == [3,2,1]
90+
@test Core.Compiler.sort!(v, by = x -> -x, < = >) === v == [1,2,3]
91+
end
92+
93+
@testset "randomized sorting tests" begin
94+
for n in [0, 1, 3, 10, 30, 100, 300], k in [0, 30, 2n]
95+
v = rand(-1:k, n)
96+
for by in [identity, x -> -x, x -> x^2 + .1x], lt in [<, >]
97+
@test sort(v; by, lt) == Core.Compiler.sort!(copy(v); by, < = lt)
98+
end
6699
end
67100
end

test/compiler/interpreter_exec.jl

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,16 @@ let m = Meta.@lower 1 + 1
107107
@test :b === @eval $m
108108
end
109109

110-
@testset "many basic blocks" begin
111-
n = 1000
110+
# https://github.com/JuliaLang/julia/issues/47065
111+
# `Core.Compiler.sort!` should be able to handle a big list
112+
let n = 1000
112113
ex = :(return 1)
113114
for _ in 1:n
114-
ex = :(if rand()<.1
115-
$(ex) end)
115+
ex = :(rand() < .1 && $(ex))
116116
end
117-
@eval begin
118-
function f_1000()
119-
$ex
120-
return 0
121-
end
117+
@eval global function f_1000_blocks()
118+
$ex
119+
return 0
122120
end
123-
@test f_1000()===0
124121
end
122+
@test f_1000_blocks() == 0

test/compiler/sort.jl

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)