Skip to content

Commit 56b12ca

Browse files
authored
Increase test coverage
1 parent 3fa5a58 commit 56b12ca

File tree

2 files changed

+106
-8
lines changed

2 files changed

+106
-8
lines changed

test/array_of_similar_arrays.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,11 +278,24 @@ using StatsBase: cov2cor
278278
@testset "examples" begin
279279
A_flat = rand(2,3,4,5,6)
280280
A_nested = nestedview(A_flat, 2)
281+
281282
@test A_nested isa AbstractArray{<:AbstractArray{T,2},3} where T
282283
@test flatview(A_nested) === A_flat
283284

285+
A_flat = rand(4,4)
286+
A_nested = @inferred(nestedview(A_flat))
287+
288+
@test A_nested.data == A_flat
289+
@test @inferred(size(A_nested))[1] == @inferred(size(A_flat))[1]
290+
@test @inferred(innersize(A_nested,1)) == @inferred(size(A_flat))[1]
291+
284292
# -------------------------------------------------------------------
285293

294+
A_flat = rand(2,3,4,5)
295+
ASA = @inferred(ArrayOfSimilarArrays{Float64,2,2}(A_flat))
296+
@test ASA.data == A_flat
297+
298+
# -------------------------------------------------------------------
286299
A_nested = nestedview(ElasticArray{Float64}(undef, 2, 3, 0), 2)
287300
A_nested_copy = deepcopy(A_nested)
288301

test/vector_of_arrays.jl

Lines changed: 93 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# This file is a part of ArraysOfArrays.jl, licensed under the MIT License (MIT).
22

33
using ArraysOfArrays
4-
using Test
54
using StatsBase
65
using Statistics
6+
using Test
77

88
using UnsafeArrays
99

@@ -103,7 +103,6 @@ using ArraysOfArrays: full_consistency_checks, append_elemptr!, element_ptr
103103
B1_copy = @inferred(copy(B1)); B3_copy = @inferred(copy(B3))
104104
append!(B1_copy, B3_copy)
105105
@test B1_copy.data == vcat(B1.data, B3.data)
106-
107106
end
108107

109108

@@ -112,14 +111,29 @@ using ArraysOfArrays: full_consistency_checks, append_elemptr!, element_ptr
112111
V2 = @inferred(VectorOfArrays(ref_AoA3(Float32, 3)))
113112
V12 = vcat(V1, V2)
114113
ind_style = @inferred(IndexStyle(V12))
114+
115115
@test ind_style == IndexLinear()
116+
116117
for i in 1:length(V12)
117118
@test getindex(V12, i) == V12[i]
118119
end
120+
119121
@test getindex(V12, 1:length(V12)) == V12
120-
122+
121123
@test @inferred(element_ptr(V12)) == V12.elem_ptr
122124

125+
getindex_of_UR = @inferred(Base._getindex(ind_style, V12, 1:length(V12)))
126+
getindex_of_vector = @inferred(Base._getindex(ind_style, V12, collect(1:length(V12))))
127+
@test getindex_of_UR == V12
128+
@test getindex_of_vector == getindex_of_UR
129+
130+
VV = @inferred(VectorOfVectors{Float64}())
131+
data = @inferred(rand(5))
132+
@inferred(push!(VV, data))
133+
@test @inferred(getindex(VV, 1)) == data
134+
@test @inferred(size(getindex(VV, 1))) == (5,)
135+
136+
123137
## _view_reshape_spec not yet implemented ##
124138
# V1_copy = copy(V1)
125139
# V2_copy = copy(V2)
@@ -140,6 +154,54 @@ using ArraysOfArrays: full_consistency_checks, append_elemptr!, element_ptr
140154

141155
end
142156

157+
@testset "indexing" begin
158+
V1 = @inferred(VectorOfArrays(ref_AoA3(Float32, 3)))
159+
V2 = @inferred(VectorOfArrays(ref_AoA3(Float32, 3)))
160+
V12 = vcat(V1, V2)
161+
ind_style = @inferred(IndexStyle(V12))
162+
@test ind_style == IndexLinear()
163+
for i in 1:length(V12)
164+
@test getindex(V12, i) == V12[i]
165+
end
166+
@test getindex(V12, 1:length(V12)) == V12
167+
168+
@test @inferred(element_ptr(V12)) == V12.elem_ptr
169+
170+
## _view_reshape_spec not yet implemented ##
171+
# V1_copy = copy(V1)
172+
# V2_copy = copy(V2)
173+
# @test setindex!(V1_copy, V1, 1) == V1
174+
# setindex!(V2_copy, V2, 1)
175+
# @test V2_copy[1] == V2_copy[2]
176+
177+
## function mul(s) not yet implemented ##
178+
# sizehint!(v12_copy, 2, (2,2,3))
179+
180+
# -------------------------------------------------------------------
181+
182+
zeroed_out = deepmap(x -> 0.0, V12)
183+
for i in zeroed_out
184+
@test @inferred(zeros(size(i))) == i
185+
end
186+
187+
# Not a good test of variable depth?
188+
@test innermap(x -> 2*x, V12) == deepmap(x -> 2*x, V12)
189+
190+
f = x -> 0
191+
A = @inferred(AbstractArray{AbstractArray{Float64, 3},1}([rand(3,3,3), rand(3,3,3), rand(3,3,3), rand(3,3,3)]))
192+
A_inner = innermap(f,A)
193+
A_deep = deepmap(f, A)
194+
195+
@test A_inner == A_deep
196+
197+
@test @inferred(size(A_inner)) == @inferred(size(A_deep))
198+
@test innersize(A,1) == innersize(A,2)
199+
@test innersize(A,1) == innersize(A,3)
200+
for i in 1:length(A_deep)
201+
@test A_deep[i] == zeros(3,3,3)
202+
end
203+
end
204+
143205

144206
@testset "copy" begin
145207
A = ref_AoA3(Float32, 3);
@@ -161,13 +223,28 @@ using ArraysOfArrays: full_consistency_checks, append_elemptr!, element_ptr
161223

162224

163225
@testset "examples" begin
164-
VA = VectorOfArrays{Float64, 2}()
226+
VA = @inferred(VectorOfArrays{Float64, 2}())
227+
228+
@inferred(push!(VA, rand(2, 3)))
229+
@inferred(push!(VA, rand(4, 2)))
230+
231+
@test @inferred(size(VA[1]) == (2,3))
232+
@test @inferred(size(VA[2]) == (4,2))
165233

166-
push!(VA, rand(2, 3))
167-
push!(VA, rand(4, 2))
234+
# -------------------------------------------------------------------
235+
236+
VV = @inferred(VectorOfVectors{Float64}())
237+
d1 = @inferred(rand(5))
238+
d2 = @inferred(rand(4))
239+
240+
@inferred(push!(VV, d1))
241+
@inferred(push!(VV, d2))
242+
243+
@test VV[1] == d1
244+
@test VV[2] == d2
168245

169-
@test size(VA[1]) == (2,3)
170-
@test size(VA[2]) == (4,2)
246+
@test @inferred(size(VV[1])) == (5,)
247+
@test @inferred(size(VV[2])) == (4,)
171248

172249
# -------------------------------------------------------------------
173250

@@ -176,6 +253,7 @@ using ArraysOfArrays: full_consistency_checks, append_elemptr!, element_ptr
176253

177254
@test @inferred(uview(VA)) == VA
178255
@test @inferred(Base.unsafe_view(VA, 1:size(VA)[1])) == VA
256+
179257
# -------------------------------------------------------------------
180258

181259

@@ -233,5 +311,12 @@ using ArraysOfArrays: full_consistency_checks, append_elemptr!, element_ptr
233311
@test flatview(result.a) === data.a
234312
@test flatview(result.b) === data.b
235313
@test flatview(result.c) === data.c
314+
315+
nestedV = @inferred(AbstractVector{AbstractArray{Float64, 4}}([rand(4,2,3,1), rand(5,3,1,3), rand(6,4,3,1), rand(9,2,1,2)]))
316+
VoA1 = @inferred(convert(VectorOfArrays, nestedV))
317+
@test @inferred(flatview(VoA1)) == VoA1.data
318+
VoA2 = @inferred(convert(VectorOfArrays{Float32, 4}, nestedV))
319+
@test @inferred(map(Float32, VoA1.data)) == VoA2.data
320+
236321
end
237322
end

0 commit comments

Comments
 (0)