|
| 1 | + |
| 2 | +@testset "Range Interface" begin |
| 3 | + @testset "Range Constructors" begin |
| 4 | + @test @inferred(StaticInt(1):StaticInt(10)) == 1:10 |
| 5 | + @test @inferred(StaticInt(1):StaticInt(2):StaticInt(10)) == 1:2:10 |
| 6 | + @test @inferred(1:StaticInt(2):StaticInt(10)) == 1:2:10 |
| 7 | + @test @inferred(StaticInt(1):StaticInt(2):10) == 1:2:10 |
| 8 | + @test @inferred(StaticInt(1):2:StaticInt(10)) == 1:2:10 |
| 9 | + @test @inferred(1:2:StaticInt(10)) == 1:2:10 |
| 10 | + @test @inferred(1:StaticInt(2):10) == 1:2:10 |
| 11 | + @test @inferred(StaticInt(1):2:10) == 1:2:10 |
| 12 | + @test @inferred(StaticInt(1):UInt(10)) === StaticInt(1):10 |
| 13 | + @test @inferred(UInt(1):StaticInt(1):StaticInt(10)) === 1:StaticInt(10) |
| 14 | + @test @inferred(ArrayInterface.OptionallyStaticUnitRange{Int,Int}(1:10)) == 1:10 |
| 15 | + @test @inferred(ArrayInterface.OptionallyStaticUnitRange(1:10)) == 1:10 |
| 16 | + |
| 17 | + @inferred(ArrayInterface.OptionallyStaticUnitRange(1:10)) |
| 18 | + |
| 19 | + @test @inferred(ArrayInterface.OptionallyStaticStepRange(StaticInt(1), static(1), static(1))) == 1:1:1 |
| 20 | + @test @inferred(ArrayInterface.OptionallyStaticStepRange(StaticInt(1), 1, UInt(10))) == StaticInt(1):1:10 |
| 21 | + @test @inferred(ArrayInterface.OptionallyStaticStepRange(UInt(1), 1, StaticInt(10))) == StaticInt(1):1:10 |
| 22 | + @test @inferred(ArrayInterface.OptionallyStaticStepRange(1:10)) == 1:1:10 |
| 23 | + |
| 24 | + @test_throws ArgumentError ArrayInterface.OptionallyStaticUnitRange(1:2:10) |
| 25 | + @test_throws ArgumentError ArrayInterface.OptionallyStaticUnitRange{Int,Int}(1:2:10) |
| 26 | + @test_throws ArgumentError ArrayInterface.OptionallyStaticStepRange(1, 0, 10) |
| 27 | + |
| 28 | + @test @inferred(StaticInt(1):StaticInt(1):StaticInt(10)) === ArrayInterface.OptionallyStaticUnitRange(StaticInt(1), StaticInt(10)) |
| 29 | + @test @inferred(StaticInt(1):StaticInt(1):10) === ArrayInterface.OptionallyStaticUnitRange(StaticInt(1), 10) |
| 30 | + @test @inferred(1:StaticInt(1):10) === ArrayInterface.OptionallyStaticUnitRange(1, 10) |
| 31 | + @test length(StaticInt{-1}():StaticInt{-1}():StaticInt{-10}()) == 10 |
| 32 | + |
| 33 | + @test UnitRange(ArrayInterface.OptionallyStaticUnitRange(StaticInt(1), StaticInt(10))) === UnitRange(1, 10) |
| 34 | + @test UnitRange{Int}(ArrayInterface.OptionallyStaticUnitRange(StaticInt(1), StaticInt(10))) === UnitRange(1, 10) |
| 35 | + |
| 36 | + @test AbstractUnitRange{Int}(ArrayInterface.OptionallyStaticUnitRange(StaticInt(1), StaticInt(10))) isa ArrayInterface.OptionallyStaticUnitRange |
| 37 | + @test AbstractUnitRange{UInt}(ArrayInterface.OptionallyStaticUnitRange(StaticInt(1), StaticInt(10))) isa Base.OneTo |
| 38 | + @test AbstractUnitRange{UInt}(ArrayInterface.OptionallyStaticUnitRange(StaticInt(2), StaticInt(10))) isa UnitRange |
| 39 | + |
| 40 | + @test @inferred((StaticInt(1):StaticInt(10))[StaticInt(2):StaticInt(3)]) === StaticInt(2):StaticInt(3) |
| 41 | + @test @inferred((StaticInt(1):StaticInt(10))[StaticInt(2):3]) === StaticInt(2):3 |
| 42 | + @test @inferred((StaticInt(1):StaticInt(10))[2:3]) === 2:3 |
| 43 | + @test @inferred((1:StaticInt(10))[StaticInt(2):StaticInt(3)]) === 2:3 |
| 44 | + |
| 45 | + @test -(StaticInt{1}():StaticInt{10}()) === StaticInt{-1}():StaticInt{-1}():StaticInt{-10}() |
| 46 | + |
| 47 | + @test reverse(StaticInt{1}():StaticInt{10}()) === StaticInt{10}():StaticInt{-1}():StaticInt{1}() |
| 48 | + @test reverse(StaticInt{1}():StaticInt{2}():StaticInt{9}()) === StaticInt{9}():StaticInt{-2}():StaticInt{1}() |
| 49 | + end |
| 50 | + |
| 51 | + @test isnothing(@inferred(ArrayInterface.known_first(typeof(1:4)))) |
| 52 | + @test isone(@inferred(ArrayInterface.known_first(Base.OneTo(4)))) |
| 53 | + @test isone(@inferred(ArrayInterface.known_first(typeof(Base.OneTo(4))))) |
| 54 | + @test isone(@inferred(ArrayInterface.known_first(typeof(StaticInt(1):2:10)))) |
| 55 | + |
| 56 | + @test isnothing(@inferred(ArrayInterface.known_last(1:4))) |
| 57 | + @test isnothing(@inferred(ArrayInterface.known_last(typeof(1:4)))) |
| 58 | + @test isone(@inferred(ArrayInterface.known_last(typeof(StaticInt(-1):StaticInt(2):StaticInt(1))))) |
| 59 | + |
| 60 | + @test isnothing(@inferred(ArrayInterface.known_step(typeof(1:0.2:4)))) |
| 61 | + @test isone(@inferred(ArrayInterface.known_step(1:4))) |
| 62 | + @test isone(@inferred(ArrayInterface.known_step(typeof(1:4)))) |
| 63 | + @test isone(@inferred(ArrayInterface.known_step(typeof(Base.Slice(1:4))))) |
| 64 | + @test isone(@inferred(ArrayInterface.known_step(typeof(view(1:4, 1:2))))) |
| 65 | + |
| 66 | + @testset "length" begin |
| 67 | + @test @inferred(length(ArrayInterface.OptionallyStaticUnitRange(1, 0))) == 0 |
| 68 | + @test @inferred(length(ArrayInterface.OptionallyStaticUnitRange(1, 10))) == 10 |
| 69 | + @test @inferred(length(ArrayInterface.OptionallyStaticUnitRange(StaticInt(1), 10))) == 10 |
| 70 | + @test @inferred(length(ArrayInterface.OptionallyStaticUnitRange(StaticInt(0), 10))) == 11 |
| 71 | + @test @inferred(length(ArrayInterface.OptionallyStaticUnitRange(StaticInt(1), StaticInt(10)))) == 10 |
| 72 | + @test @inferred(length(ArrayInterface.OptionallyStaticUnitRange(StaticInt(0), StaticInt(10)))) == 11 |
| 73 | + |
| 74 | + @test @inferred(length(StaticInt(1):StaticInt(2):StaticInt(0))) == 0 |
| 75 | + @test @inferred(length(StaticInt(0):StaticInt(-2):StaticInt(1))) == 0 |
| 76 | + |
| 77 | + @test @inferred(ArrayInterface.known_length(typeof(ArrayInterface.OptionallyStaticStepRange(StaticInt(1), 2, 10)))) === nothing |
| 78 | + @test @inferred(ArrayInterface.known_length(typeof(ArrayInterface.OptionallyStaticStepRange(StaticInt(1), StaticInt(1), StaticInt(10))))) === 10 |
| 79 | + @test @inferred(ArrayInterface.known_length(typeof(ArrayInterface.OptionallyStaticStepRange(StaticInt(2), StaticInt(1), StaticInt(10))))) === 9 |
| 80 | + @test @inferred(ArrayInterface.known_length(typeof(ArrayInterface.OptionallyStaticStepRange(StaticInt(2), StaticInt(2), StaticInt(10))))) === 5 |
| 81 | + @test @inferred(ArrayInterface.known_length(Int)) === 1 |
| 82 | + |
| 83 | + @test @inferred(length(ArrayInterface.OptionallyStaticStepRange(StaticInt(1), 2, 10))) == 5 |
| 84 | + @test @inferred(length(ArrayInterface.OptionallyStaticStepRange(StaticInt(1), StaticInt(1), StaticInt(10)))) == 10 |
| 85 | + @test @inferred(length(ArrayInterface.OptionallyStaticStepRange(StaticInt(2), StaticInt(1), StaticInt(10)))) == 9 |
| 86 | + @test @inferred(length(ArrayInterface.OptionallyStaticStepRange(StaticInt(2), StaticInt(2), StaticInt(10)))) == 5 |
| 87 | + end |
| 88 | + |
| 89 | + @test @inferred(getindex(ArrayInterface.OptionallyStaticUnitRange(StaticInt(1), 10), 1)) == 1 |
| 90 | + @test @inferred(getindex(ArrayInterface.OptionallyStaticUnitRange(StaticInt(0), 10), 1)) == 0 |
| 91 | + @test_throws BoundsError getindex(ArrayInterface.OptionallyStaticUnitRange(StaticInt(1), 10), 0) |
| 92 | + @test_throws BoundsError getindex(ArrayInterface.OptionallyStaticStepRange(StaticInt(1), 2, 10), 0) |
| 93 | + @test_throws BoundsError getindex(ArrayInterface.OptionallyStaticUnitRange(StaticInt(1), 10), 11) |
| 94 | + @test_throws BoundsError getindex(ArrayInterface.OptionallyStaticStepRange(StaticInt(1), 2, 10), 11) |
| 95 | +end |
| 96 | + |
0 commit comments