Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lkdvos committed Jan 10, 2025
1 parent 4917bb0 commit ebd40cb
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/basics/test_defaultarrayinterface.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Test: @testset, @test, @inferred
using DerivableInterfaces: @interface, DefaultArrayInterface

# function wrappers to test type-stability
_getindex(A, i...) = @interface DefaultArrayInterface() A[i...]
_setindex!(A, v, i...) = @interface DefaultArrayInterface() A[i...] = v
_map!(args...) = @interface DefaultArrayInterface() map!(args...)
function _mapreduce(args...; kwargs...)
@interface DefaultArrayInterface() mapreduce(args...; kwargs...)
end

@testset "indexing" begin
for (A, i) in ((zeros(2), 2), (zeros(2, 2), (2, 1)), (zeros(1, 2, 3), (1, 2, 3)))
a = @inferred _getindex(A, i...)
@test a == A[i...]
v = 1.1
A′ = @inferred _setindex!(A, v, i...)
@test_broken A′ == (A[i...] = v) # FIXME: `setindex` and `A[i] = v` have a slight semantic difference
end
end

@testset "map!" begin
A = zeros(3)
a = @inferred _map!(Returns(2), copy(A), A)
@test a == map!(Returns(2), copy(A), A)
end

@testset "mapreduce" begin
A = zeros(3)
a = @inferred _mapreduce(Returns(2), +, A)
@test a == mapreduce(Returns(2), +, A)
end

0 comments on commit ebd40cb

Please sign in to comment.