|
422 | 422 | @test !(3.5 in 1:5)
|
423 | 423 | @test (3 in 1:5)
|
424 | 424 | @test (3 in 5:-1:1)
|
425 |
| - #@test (3 in 3+0*(1:5)) |
426 |
| - #@test !(4 in 3+0*(1:5)) |
| 425 | + @test 0. in (0. .* (1:10)) |
| 426 | + @test !(0.1 in (0. .* (1:10))) |
427 | 427 |
|
428 | 428 | let r = 0.0:0.01:1.0
|
429 | 429 | @test (r[30] in r)
|
|
440 | 440 | x = (NaN16, Inf32, -Inf64, 1//0, -1//0)
|
441 | 441 | @test !(x in r)
|
442 | 442 | end
|
| 443 | + |
| 444 | + @test 1e40 ∉ 0:1.0 # Issue #45747 |
| 445 | + @test 1e20 ∉ 0:1e-20:1e-20 |
| 446 | + @test 1e20 ∉ 0:1e-20 |
| 447 | + @test 1.0 ∉ 0:1e-20:1e-20 |
| 448 | + @test 0.5 ∉ 0:1e-20:1e-20 |
| 449 | + @test 1 ∉ 0:1e-20:1e-20 |
| 450 | + |
| 451 | + @test_broken 17.0 ∈ 0:1e40 # Don't support really long ranges |
443 | 452 | end
|
444 |
| - @testset "in() works across types, including non-numeric types (#21728)" begin |
| 453 | + @testset "in() works across types, including non-numeric types (#21728 and #45646)" begin |
445 | 454 | @test 1//1 in 1:3
|
446 | 455 | @test 1//1 in 1.0:3.0
|
447 | 456 | @test !(5//1 in 1:3)
|
|
462 | 471 | @test !(Complex(1, 0) in Date(2017, 01, 01):Dates.Day(1):Date(2017, 01, 05))
|
463 | 472 | @test !(π in Date(2017, 01, 01):Dates.Day(1):Date(2017, 01, 05))
|
464 | 473 | @test !("a" in Date(2017, 01, 01):Dates.Day(1):Date(2017, 01, 05))
|
| 474 | + |
| 475 | + # We use Ducks because of their propensity to stand in a row and because we know |
| 476 | + # that no additional methods (e.g. isfinite) are defined specifically for Ducks. |
| 477 | + struct Duck |
| 478 | + location::Int |
| 479 | + end |
| 480 | + Base.:+(x::Duck, y::Int) = Duck(x.location + y) |
| 481 | + Base.:-(x::Duck, y::Int) = Duck(x.location - y) |
| 482 | + Base.:-(x::Duck, y::Duck) = x.location - y.location |
| 483 | + Base.isless(x::Duck, y::Duck) = isless(x.location, y.location) |
| 484 | + |
| 485 | + @test Duck(3) ∈ Duck(1):2:Duck(5) |
| 486 | + @test Duck(3) ∈ Duck(5):-2:Duck(2) |
| 487 | + @test Duck(4) ∉ Duck(5):-2:Duck(1) |
| 488 | + @test Duck(4) ∈ Duck(1):Duck(5) |
| 489 | + @test Duck(0) ∉ Duck(1):Duck(5) |
465 | 490 | end
|
466 | 491 | end
|
467 | 492 | @testset "indexing range with empty range (#4309)" begin
|
|
0 commit comments