Skip to content

Commit 4c2cfb2

Browse files
committed
Improve test coverage for Issue #78 fix
- Remove unused dense_original.jl reference file - Add tests for type stability helper functions - Add tests for broadcast type stability - Coverage now includes _stabilize_mesh_type, _create_mesharray_typed, _infer_mesh_type, and _copyto_typed!
1 parent cb236af commit 4c2cfb2

File tree

2 files changed

+51
-270
lines changed

2 files changed

+51
-270
lines changed

src/mesharrays/dense_original.jl

Lines changed: 0 additions & 270 deletions
This file was deleted.

test/test_MeshArrays.jl

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,54 @@ end
9494
g = MeshArray(mesh1, mesh1, mesh1, mesh1, mesh1, mesh1)
9595
@test isconcretetype(typeof(g.mesh))
9696
end
97+
98+
@testset "MeshArray Type Stability Helpers (Issue #78)" begin
99+
N1, N2 = 8, 6
100+
mesh1 = SimpleGrid.Uniform{Float64}([0.0, 1.0], N1)
101+
mesh2 = SimpleGrid.Uniform{Float64}([0.0, 1.0], N2)
102+
103+
mesh_tuple = (mesh1, mesh2)
104+
stabilized = MeshArrays._stabilize_mesh_type(mesh_tuple)
105+
@test isconcretetype(typeof(stabilized))
106+
@test stabilized === mesh_tuple
107+
108+
non_concrete_mesh = Any[mesh1, mesh2]
109+
stabilized_from_vec = MeshArrays._stabilize_mesh_type(non_concrete_mesh)
110+
@test isconcretetype(typeof(stabilized_from_vec))
111+
112+
data = rand(N1, N2)
113+
result = MeshArrays._create_mesharray_typed(data, mesh_tuple, Float64, 2)
114+
@test result isa MeshArray{Float64, 2}
115+
@test result.data === data
116+
117+
data_int = ones(Int, N1, N2)
118+
result_converted = MeshArrays._create_mesharray_typed(data_int, mesh_tuple, Float64, 2)
119+
@test result_converted isa MeshArray{Float64, 2}
120+
@test eltype(result_converted.data) == Float64
121+
122+
MT = typeof(mesh_tuple)
123+
@test MeshArrays._infer_mesh_type(mesh_tuple) == MT
124+
end
125+
126+
@testset "MeshArray Broadcast Type Stability" begin
127+
N1, N2 = 10, 12
128+
mesh1 = SimpleGrid.Uniform{Float64}([0.0, 1.0], N1)
129+
mesh2 = SimpleGrid.Uniform{Float64}([0.0, 1.0], N2)
130+
131+
g1 = MeshArray(mesh1, mesh2; data=rand(N1, N2))
132+
g2 = MeshArray(mesh1, mesh2; data=rand(N1, N2))
133+
134+
g3 = similar(g1)
135+
g3 .= g1 .+ g2
136+
@test g3.data g1.data .+ g2.data
137+
138+
g4 = similar(g1)
139+
Base.copyto!(g4, Base.Broadcast.broadcasted(+, g1, g2))
140+
@test g4.data g1.data .+ g2.data
141+
142+
indices = CartesianIndices(g1.data)
143+
bcf = Base.Broadcast.flatten(Base.Broadcast.broadcasted(*, g1, 2.0))
144+
g5 = similar(g1)
145+
MeshArrays._copyto_typed!(g5, bcf, indices)
146+
@test g5.data g1.data .* 2.0
147+
end

0 commit comments

Comments
 (0)