|
162 | 162 | end
|
163 | 163 |
|
164 | 164 | @testset "zero_tangent" begin
|
165 |
| - @test zero_tangent(1) === 0 |
166 |
| - @test zero_tangent(1.0) === 0.0 |
167 |
| - mutable struct MutDemo |
168 |
| - x::Float64 |
169 |
| - end |
170 |
| - struct Demo |
171 |
| - x::Float64 |
172 |
| - end |
173 |
| - @test zero_tangent(MutDemo(1.5)) isa MutableTangent{MutDemo} |
174 |
| - @test iszero(zero_tangent(MutDemo(1.5))) |
| 165 | + @testset "basics" begin |
| 166 | + @test zero_tangent(1) === 0 |
| 167 | + @test zero_tangent(1.0) === 0.0 |
| 168 | + mutable struct MutDemo |
| 169 | + x::Float64 |
| 170 | + end |
| 171 | + struct Demo |
| 172 | + x::Float64 |
| 173 | + end |
| 174 | + @test zero_tangent(MutDemo(1.5)) isa MutableTangent{MutDemo} |
| 175 | + @test iszero(zero_tangent(MutDemo(1.5))) |
175 | 176 |
|
176 |
| - @test zero_tangent((; a=1)) isa Tangent{typeof((; a = 1))} |
177 |
| - @test zero_tangent(Demo(1.2)) isa Tangent{Demo} |
178 |
| - @test zero_tangent(Demo(1.2)).x === 0.0 |
| 177 | + @test zero_tangent((; a=1)) isa Tangent{typeof((; a = 1))} |
| 178 | + @test zero_tangent(Demo(1.2)) isa Tangent{Demo} |
| 179 | + @test zero_tangent(Demo(1.2)).x === 0.0 |
179 | 180 |
|
180 |
| - @test zero_tangent([1.0, 2.0]) == [0.0, 0.0] |
181 |
| - @test zero_tangent([[1.0, 2.0], [3.0]]) == [[0.0, 0.0], [0.0]] |
| 181 | + @test zero_tangent([1.0, 2.0]) == [0.0, 0.0] |
| 182 | + @test zero_tangent([[1.0, 2.0], [3.0]]) == [[0.0, 0.0], [0.0]] |
| 183 | + |
| 184 | + @test zero_tangent((1.0, 2.0)) == Tangent{Tuple{Float64,Float64}}(0.0, 0.0) |
| 185 | + end |
| 186 | + |
| 187 | + @testset "Weird types" begin |
| 188 | + @test iszero(zero_tangent(typeof(Int))) # primative type |
| 189 | + @test iszero(zero_tangent(typeof(Base.RefValue))) # struct |
| 190 | + @test iszero(zero_tangent(Vector)) # UnionAll |
| 191 | + @test iszero(zero_tangent(Union{Int, Float64})) # Union |
| 192 | + @test iszero(zero_tangent(:abc)) |
| 193 | + @test iszero(zero_tangent("abc")) |
| 194 | + @test iszero(zero_tangent(sin)) |
| 195 | + end |
182 | 196 |
|
183 |
| - @test zero_tangent((1.0, 2.0)) == Tangent{Tuple{Float64,Float64}}(0.0, 0.0) |
184 | 197 | @testset "undef elements Vector" begin
|
185 | 198 | x = Vector{Vector{Float64}}(undef, 3)
|
186 | 199 | x[2] = [1.0, 2.0]
|
|
0 commit comments