|
72 | 72 | end
|
73 | 73 | @test Tangent{Foo}(; x=2.5).x == 2.5
|
74 | 74 |
|
75 |
| - @test keys(Tangent{Tuple{Float64}}(2.0)) == Base.OneTo(1) |
| 75 | + tang1 = Tangent{Tuple{Float64}}(2.0) |
| 76 | + @test keys(tang1) == Base.OneTo(1) |
76 | 77 | @test propertynames(Tangent{Tuple{Float64}}(2.0)) == (1,)
|
77 | 78 | @test getindex(Tangent{Tuple{Float64}}(2.0), 1) == 2.0
|
78 | 79 | @test getindex(Tangent{Tuple{Float64}}(@thunk 2.0^2), 1) == 4.0
|
79 | 80 | @test getproperty(Tangent{Tuple{Float64}}(2.0), 1) == 2.0
|
80 | 81 | @test getproperty(Tangent{Tuple{Float64}}(@thunk 2.0^2), 1) == 4.0
|
| 82 | + @test NoTangent() === @inferred Base.tail(tang1) |
| 83 | + @test NoTangent() === @inferred Base.tail(Tangent{Tuple{}}()) |
| 84 | + |
| 85 | + tang3 = Tangent{Tuple{Float64, String, Vector{Float64}}}(1.0, NoTangent(), @thunk [3.0] .+ 4) |
| 86 | + @test @inferred(first(tang3)) === tang3[1] === 1.0 |
| 87 | + @test @inferred(last(tang3)) isa Thunk |
| 88 | + @test unthunk(last(tang3)) == [7.0] |
| 89 | + @test Tuple(@inferred Base.tail(tang3))[1] === NoTangent() |
| 90 | + @test Tuple(Base.tail(tang3))[end] isa Thunk |
81 | 91 |
|
82 | 92 | NT = NamedTuple{(:a, :b),Tuple{Float64,Float64}}
|
83 | 93 | @test getindex(Tangent{NT}(; a=(@thunk 2.0^2)), :a) == 4.0
|
|
89 | 99 | @test getproperty(Tangent{NT}(; a=(@thunk 2.0^2)), :b) == ZeroTangent()
|
90 | 100 | @test getproperty(Tangent{NT}(; b=(@thunk 2.0^2)), 1) == ZeroTangent()
|
91 | 101 | @test getproperty(Tangent{NT}(; b=(@thunk 2.0^2)), 2) == 4.0
|
| 102 | + |
| 103 | + @test first(Tangent{NT}(; a=(@thunk 2.0^2))) isa Thunk |
| 104 | + @test unthunk(first(Tangent{NT}(; a=(@thunk 2.0^2)))) == 4.0 |
| 105 | + @test last(Tangent{NT}(; a=(@thunk 2.0^2))) isa ZeroTangent |
| 106 | + |
| 107 | + ntang1 = @inferred Base.tail(Tangent{NT}(; b=(@thunk 2.0^2))) |
| 108 | + @test ntang1 isa Tangent{<:NamedTuple{(:b,)}} |
| 109 | + @test NoTangent() === @inferred Base.tail(ntang1) |
92 | 110 |
|
93 | 111 | # TODO: uncomment this once https://github.com/JuliaLang/julia/issues/35516
|
94 | 112 | if VERSION >= v"1.8-"
|
|
0 commit comments