|
138 | 138 | @test searchsortedlast(500:1.0:600, -1.0e20) == 0
|
139 | 139 | @test searchsortedlast(500:1.0:600, 1.0e20) == 101
|
140 | 140 | end
|
| 141 | + @testset "issue #34157" begin |
| 142 | + @test searchsorted(1:2.0, -Inf) === 1:0 |
| 143 | + @test searchsorted([1,2], -Inf) === 1:0 |
| 144 | + @test searchsorted(1:2, -Inf) === 1:0 |
| 145 | + |
| 146 | + @test searchsorted(1:2.0, Inf) === 3:2 |
| 147 | + @test searchsorted([1,2], Inf) === 3:2 |
| 148 | + @test searchsorted(1:2, Inf) === 3:2 |
| 149 | + |
| 150 | + for coll in [ |
| 151 | + Base.OneTo(10), |
| 152 | + 1:2, |
| 153 | + -4:6, |
| 154 | + 5:2:10, |
| 155 | + [1,2], |
| 156 | + 1.0:4, |
| 157 | + [10.0,20.0], |
| 158 | + ] |
| 159 | + for huge in [Inf, 1e300] |
| 160 | + @test searchsortedfirst(coll, huge) === lastindex(coll) + 1 |
| 161 | + @test searchsortedfirst(coll, -huge)=== firstindex(coll) |
| 162 | + @test searchsortedlast(coll, huge) === lastindex(coll) |
| 163 | + @test searchsortedlast(coll, -huge) === firstindex(coll) - 1 |
| 164 | + @test searchsorted(coll, huge) === lastindex(coll)+1 : lastindex(coll) |
| 165 | + @test searchsorted(coll, -huge) === firstindex(coll) : firstindex(coll) - 1 |
| 166 | + |
| 167 | + @test searchsortedfirst(reverse(coll), huge, rev=true) === firstindex(coll) |
| 168 | + @test searchsortedfirst(reverse(coll), -huge, rev=true) === lastindex(coll) + 1 |
| 169 | + @test searchsortedlast(reverse(coll), huge, rev=true) === firstindex(coll) - 1 |
| 170 | + @test searchsortedlast(reverse(coll), -huge, rev=true) === lastindex(coll) |
| 171 | + @test searchsorted(reverse(coll), huge, rev=true) === firstindex(coll):firstindex(coll) - 1 |
| 172 | + @test searchsorted(reverse(coll), -huge, rev=true) === lastindex(coll)+1:lastindex(coll) |
| 173 | + |
| 174 | + end |
| 175 | + end |
| 176 | + end |
141 | 177 | end
|
142 | 178 | # exercise the codepath in searchsorted* methods for ranges that check for zero step range
|
143 | 179 | struct ConstantRange{T} <: AbstractRange{T}
|
|
0 commit comments