From 2dfac1dbd115f521f6b123d2ce1673d006e6aa88 Mon Sep 17 00:00:00 2001 From: Jishnu Bhattacharya Date: Tue, 5 Dec 2023 21:15:35 +0530 Subject: [PATCH] Add tests for custom structs --- test/runtests.jl | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index d7a6aca1..f6d7f85c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1894,6 +1894,33 @@ end @test FillArrays.getindex_value(transpose(a)) == FillArrays.unique_value(transpose(a)) == 2.0 + im @test convert(Fill, transpose(a)) ≡ Fill(2.0+im,1,5) end + + @testst "custom AbstractFill types" begin + # implicit axes + struct StaticZerosVec{L,T} <: FillArrays.AbstractZeros{T,1,Tuple{SOneTo{L}}} end + Base.size(::StaticZerosVec{L}) where {L} = (L,) + Base.axes(::StaticZerosVec{L}) where {L} = (SOneTo(L),) + S = StaticZerosVec{3,Int}() + @test real.(S) == S + @test imag.(S) == S + + struct StaticOnesVec{L,T} <: FillArrays.AbstractOnes{T,1,Tuple{SOneTo{L}}} end + Base.size(::StaticOnesVec{L}) where {L} = (L,) + Base.axes(::StaticOnesVec{L}) where {L} = (SOneTo(L),) + S = StaticOnesVec{3,Int}() + @test real.(S) == S + @test imag.(S) == zero(S) + + struct StaticFill{S1,S2,T} <: FillArrays.AbstractFill{T,2,Tuple{SOneTo{S1},SOneTo{S2}}} + x :: T + end + StaticFill{S1,S2}(x::T) where {S1,S2,T} = StaticFill{S1,S2,T}(x) + Base.size(::StaticFill{S1,S2}) where {S1,S2} = (S1,S2) + Base.axes(::StaticFill{S1,S2}) where {S1,S2} = (SOneTo(S1), SOneTo(S2)) + FillArrays.getindex_value(S::StaticFill) = S.x + S = StaticFill{2,3}(2) + @test permutedims(S) == Fill(2, reverse(size(S))) + end end @testset "Statistics" begin