|
518 | 518 | @test !(3.5 in 1:5)
|
519 | 519 | @test (3 in 1:5)
|
520 | 520 | @test (3 in 5:-1:1)
|
521 |
| - #@test (3 in 3+0*(1:5)) |
522 |
| - #@test !(4 in 3+0*(1:5)) |
| 521 | + @test (3 in 3 .+ 0*(1:5)) |
| 522 | + @test !(4 in 3 .+ 0*(1:5)) |
| 523 | + @test 0. in (0. .* (1:10)) |
| 524 | + @test !(0.1 in (0. .* (1:10))) |
523 | 525 |
|
524 | 526 | let r = 0.0:0.01:1.0
|
525 | 527 | @test (r[30] in r)
|
|
536 | 538 | x = (NaN16, Inf32, -Inf64, 1//0, -1//0)
|
537 | 539 | @test !(x in r)
|
538 | 540 | end
|
| 541 | + |
| 542 | + @test 1e40 ∉ 0:1.0 # Issue #45747 |
| 543 | + @test 1e20 ∉ 0:1e-20:1e-20 |
| 544 | + @test 1e20 ∉ 0:1e-20 |
| 545 | + @test 1.0 ∉ 0:1e-20:1e-20 |
| 546 | + @test 0.5 ∉ 0:1e-20:1e-20 |
| 547 | + @test 1 ∉ 0:1e-20:1e-20 |
| 548 | + |
| 549 | + @test_broken 17.0 ∈ 0:1e40 # Don't support really long ranges |
539 | 550 | end
|
540 |
| - @testset "in() works across types, including non-numeric types (#21728)" begin |
| 551 | + @testset "in() works across types, including non-numeric types (#21728 and #45646)" begin |
541 | 552 | @test 1//1 in 1:3
|
542 | 553 | @test 1//1 in 1.0:3.0
|
543 | 554 | @test !(5//1 in 1:3)
|
|
558 | 569 | @test !(Complex(1, 0) in Date(2017, 01, 01):Dates.Day(1):Date(2017, 01, 05))
|
559 | 570 | @test !(π in Date(2017, 01, 01):Dates.Day(1):Date(2017, 01, 05))
|
560 | 571 | @test !("a" in Date(2017, 01, 01):Dates.Day(1):Date(2017, 01, 05))
|
| 572 | + |
| 573 | + # We use Ducks because of their propensity to stand in a row and because we know |
| 574 | + # that no additional methods (e.g. isfinite) are defined specifically for Ducks. |
| 575 | + struct Duck |
| 576 | + location::Int |
| 577 | + end |
| 578 | + Base.:+(x::Duck, y::Int) = Duck(x.location + y) |
| 579 | + Base.:-(x::Duck, y::Int) = Duck(x.location - y) |
| 580 | + Base.:-(x::Duck, y::Duck) = x.location - y.location |
| 581 | + Base.isless(x::Duck, y::Duck) = isless(x.location, y.location) |
| 582 | + |
| 583 | + @test Duck(3) ∈ Duck(1):2:Duck(5) |
| 584 | + @test Duck(3) ∈ Duck(5):-2:Duck(2) |
| 585 | + @test Duck(4) ∉ Duck(5):-2:Duck(1) |
| 586 | + @test Duck(4) ∈ Duck(1):Duck(5) |
| 587 | + @test Duck(0) ∉ Duck(1):Duck(5) |
561 | 588 | end
|
562 | 589 | end
|
563 | 590 | @testset "indexing range with empty range (#4309)" begin
|
|
0 commit comments