Skip to content

Commit

Permalink
more tests for CellArrays (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
albert-de-montserrat authored Dec 18, 2023
1 parent 62dc38c commit 06061e6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/phases/CallArrays.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

@inline cellnum(A::CellArray) = prod(cellsize(A))
@inline cellaxes(A) = map(Base.oneto, cellnum(A))
@inline new_empty_cell(A::CellArray{T,N}) where {T,N} = zeros(T)
@inline new_empty_cell(::CellArray{T,N}) where {T,N} = zeros(T)

import Base.setindex!

Expand Down
15 changes: 10 additions & 5 deletions test/test_CellArrays2D.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ environment!(model)
ni = 5, 5
A = JustRelax.@fill(false, ni..., celldims=(2,), eltype=Bool)

@test cellaxes(A) === Base.OneTo(2)
@test cellnum(A) == 2
@test new_empty_cell(A) === SA[false, false]

@test @cell(A[1, 1, 1]) === false
@test (@allocated @cell A[1, 1, 1]) == 0
@test (@allocated @cell A[1, 1, 1]) === 0

@cell A[1, 1, 1] = true
@test @cell(A[1, 1, 1]) === true
@test (@allocated @cell A[1, 1, 1] = true) == 0

@test A[1, 1] == SA[true, false]
@test (@allocated @cell A[1, 1, 1] = true) === 0
@test A[1, 1] === SA[true, false]
allocs = check_allocs(getindex, (typeof(A), Int64, Int64))
@test isempty(allocs)
end
end

0 comments on commit 06061e6

Please sign in to comment.