|
1 |
| -using Test: @inferred, @testset, @test |
2 | 1 | using DerivableInterfaces: @interface, DefaultArrayInterface, interface
|
| 2 | +using Test: @testset, @test |
| 3 | +using TestExtras: @constinferred |
3 | 4 |
|
4 | 5 | # function wrappers to test type-stability
|
5 | 6 | _getindex(A, i...) = @interface DefaultArrayInterface() A[i...]
|
|
11 | 12 |
|
12 | 13 | @testset "indexing" begin
|
13 | 14 | for (A, i) in ((zeros(2), 2), (zeros(2, 2), (2, 1)), (zeros(1, 2, 3), (1, 2, 3)))
|
14 |
| - a = @inferred _getindex(A, i...) |
| 15 | + a = @constinferred _getindex(A, i...) |
15 | 16 | @test a == A[i...]
|
16 | 17 | v = 1.1
|
17 |
| - A′ = @inferred _setindex!(A, v, i...) |
| 18 | + A′ = @constinferred _setindex!(A, v, i...) |
18 | 19 | @test A′ == (A[i...] = v)
|
19 | 20 | end
|
20 | 21 | end
|
21 | 22 |
|
22 | 23 | @testset "map!" begin
|
23 | 24 | A = zeros(3)
|
24 |
| - a = @inferred _map!(Returns(2), copy(A), A) |
| 25 | + a = @constinferred _map!(Returns(2), copy(A), A) |
25 | 26 | @test a == map!(Returns(2), copy(A), A)
|
26 | 27 | end
|
27 | 28 |
|
28 | 29 | @testset "mapreduce" begin
|
29 | 30 | A = zeros(3)
|
30 |
| - a = @inferred _mapreduce(Returns(2), +, A) |
| 31 | + a = @constinferred _mapreduce(Returns(2), +, A) |
31 | 32 | @test a == mapreduce(Returns(2), +, A)
|
32 | 33 | end
|
33 | 34 |
|
| 35 | +@testset "DefaultArrayInterface" begin |
| 36 | + @test interface(Array) === DefaultArrayInterface{Any}() |
| 37 | + @test interface(Array{Float32}) === DefaultArrayInterface{Any}() |
| 38 | + @test interface(Matrix) === DefaultArrayInterface{2}() |
| 39 | + @test interface(Matrix{Float32}) === DefaultArrayInterface{2}() |
| 40 | + @test DefaultArrayInterface() === DefaultArrayInterface{Any}() |
| 41 | + @test DefaultArrayInterface(Val(2)) === DefaultArrayInterface{2}() |
| 42 | + @test DefaultArrayInterface{Any}(Val(2)) === DefaultArrayInterface{2}() |
| 43 | + @test DefaultArrayInterface{3}(Val(2)) === DefaultArrayInterface{2}() |
| 44 | +end |
| 45 | + |
| 46 | +@testset "similar(::DefaultArrayInterface, ...)" begin |
| 47 | + a = @constinferred similar(DefaultArrayInterface(), Float32, (2, 2)) |
| 48 | + @test typeof(a) === Matrix{Float32} |
| 49 | + @test size(a) == (2, 2) |
| 50 | + |
| 51 | + a = @constinferred similar(DefaultArrayInterface{1}(), Float32, (2, 2)) |
| 52 | + @test typeof(a) === Matrix{Float32} |
| 53 | + @test size(a) == (2, 2) |
| 54 | +end |
| 55 | + |
34 | 56 | @testset "Broadcast.DefaultArrayStyle" begin
|
35 | 57 | @test interface(Broadcast.DefaultArrayStyle) == DefaultArrayInterface()
|
| 58 | + @test interface(Broadcast.DefaultArrayStyle{2}) == DefaultArrayInterface{2}() |
36 | 59 | @test interface(Broadcast.Broadcasted(nothing, +, (randn(2), randn(2)))) ==
|
37 |
| - DefaultArrayInterface() |
| 60 | + DefaultArrayInterface{1}() |
38 | 61 | end
|
0 commit comments