Skip to content

Commit

Permalink
add test for issue #123
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth authored and rafaqz committed Oct 6, 2023
1 parent 21e2888 commit dbed952
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -670,3 +670,36 @@ struct TestArray{T,N} <: AbstractArray{T,N} end
DiskArrays.@implement_batchgetindex TestArray
DiskArrays.@implement_diskarray TestArray
end

# issue #123

mutable struct ResizableArray{T,N} <: AbstractArray{T,N}
A::AbstractArray{T,N}
end

Base.size(RA::ResizableArray) = size(RA.A)
Base.getindex(RA::ResizableArray,inds...) = getindex(RA.A,inds...)
Base.checkbounds(::Type{Bool},RA::ResizableArray,inds...) = all(minimum.(inds) .> 0)
function Base.setindex!(RA::ResizableArray{T,N}, value, inds::Vararg{Int, N}) where {T,N}
sz = max.(size(RA),inds)
if sz != size(RA)
# grow
oldA = RA.A
RA.A = Array{T,N}(undef,sz)
RA.A[axes(oldA)...] = oldA
end
RA.A[inds...] = value
end

b = ResizableArray(Vector{Int}(undef,0))
@test size(b) == (0,)
b[1:5] = 1:5
@test b == 1:5
@test size(b) == (5,)

a = ResizableArray(Vector{Int}(undef,0))
a1 = _DiskArray(a,chunksize=(5,))
@test size(a1) == (0,)
a1[1:5] .= 1:5
@test a1 == 1:5
@test size(a1) == (5,)

0 comments on commit dbed952

Please sign in to comment.