Skip to content

Commit 41b1336

Browse files
authored
[Containers] improve coverage of DenseAxisArray (#3058)
1 parent 1a938c0 commit 41b1336

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

src/Containers/DenseAxisArray.jl

+1-3
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,6 @@ if isdefined(Base, :print_array) # 0.7 and later
484484
end
485485
end
486486

487-
# n-dimensional arrays
488487
function Base.show_nd(
489488
io::IO,
490489
a::DenseAxisArray,
@@ -514,7 +513,6 @@ function Base.show_nd(
514513
@goto skip
515514
end
516515
end
517-
#println(io, idxs)
518516
print(io, "...\n\n")
519517
@goto skip
520518
end
@@ -534,7 +532,7 @@ function Base.show_nd(
534532
println(io, "] =")
535533
end
536534
slice = view(a.data, axes(a.data, 1), axes(a.data, 2), idxs...)
537-
Base.print_matrix(io, slice)
535+
print_matrix(io, slice)
538536
print(io, idxs == map(last, tailinds) ? "" : "\n\n")
539537
@label skip
540538
end

test/Containers/DenseAxisArray.jl

+50
Original file line numberDiff line numberDiff line change
@@ -392,4 +392,54 @@ And data, a 0-dimensional $(Array{Int,0}):
392392
x = DenseAxisArray(1:6, S)
393393
@test size(x) == (6,)
394394
end
395+
396+
@testset "DenseAxisArray_show_nd" begin
397+
S = zeros(Int, 2, 2, 3, 3, 3)
398+
for i in 1:length(S)
399+
S[i] = i
400+
end
401+
x = DenseAxisArray(S, 1:2, 1:2, 1:3, 1:3, 1:3)
402+
str = sprint((io, x) -> Base.show_nd(io, x, Base.print_matrix, true), x)
403+
@test occursin("[:, :, 1, 2, 3] =\n 85 87\n 86 88\n", str)
404+
str_limit = sprint(x) do io, x
405+
return Base.show_nd(
406+
IOContext(io, :limit => true),
407+
x,
408+
Base.print_matrix,
409+
true,
410+
)
411+
end
412+
@test occursin("[:, :, 1, 2, 3] =\n 85 87\n 86 88\n", str_limit)
413+
end
414+
415+
@testset "DenseAxisArray_show_nd_limit" begin
416+
S = zeros(Int, 2, 2, 3, 3, 20)
417+
for i in 1:length(S)
418+
S[i] = i
419+
end
420+
x = DenseAxisArray(S, 1:2, 1:2, 1:3, 1:3, 1:20)
421+
str = sprint((io, x) -> Base.show_nd(io, x, Base.print_matrix, true), x)
422+
@test occursin("[:, :, 1, 1, 3]", str)
423+
@test occursin("[:, :, 1, 1, 4]", str)
424+
@test occursin("[:, :, 1, 1, 17]", str)
425+
@test occursin("[:, :, 1, 1, 18]", str)
426+
str_limit = sprint(x) do io, x
427+
return Base.show_nd(
428+
IOContext(io, :limit => true),
429+
x,
430+
Base.print_matrix,
431+
true,
432+
)
433+
end
434+
@test occursin("[:, :, 1, 1, 3]", str_limit)
435+
@test !occursin("[:, :, 1, 1, 4]", str_limit)
436+
@test !occursin("[:, :, 1, 1, 17]", str_limit)
437+
@test occursin("[:, :, 1, 1, 18]", str_limit)
438+
end
439+
440+
@testset "DenseAxisArray_show_nd_empty" begin
441+
x = DenseAxisArray(Int[], 1:0)
442+
str = sprint((io, x) -> Base.show_nd(io, x, Base.print_matrix, true), x)
443+
@test isempty(str)
444+
end
395445
end

0 commit comments

Comments
 (0)