Skip to content

Commit 974337d

Browse files
authored
Improve test coverage for BlockLogicalIndex (#480)
I noticed #475 had some missing test coverage, this should fix that.
1 parent d55d96e commit 974337d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/views.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ collect(I::BlockedLogicalIndex) = collect(I.blocks)
111111
checkbounds(::Type{Bool}, A::AbstractArray, i::BlockedLogicalIndex) = checkbounds(Bool, A, i.blocks.mask)
112112
# `checkbounds_indices` has been handled via `I::AbstractArray` fallback
113113
checkindex(::Type{Bool}, inds::AbstractUnitRange, i::BlockedLogicalIndex) = checkindex(Bool, inds, i.blocks.mask)
114-
checkindex(::Type{Bool}, inds::Tuple, i::BlockedLogicalIndex) = checkindex(Bool, inds, i.blocks.mask)
115114

116115
# Instantiate the BlockedLogicalIndex when constructing a SubArray, similar to
117116
# `ensure_indexable(I::Tuple{LogicalIndex,Vararg{Any}})`:

test/test_blockviews.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ bview(a, b) = Base.invoke(view, Tuple{AbstractArray,Any}, a, b)
360360
a = randn(6, 6)
361361
for mask in ([true, true, false, false, true, false], BitVector([true, true, false, false, true, false]))
362362
I = BlockedVector(mask, [3, 3])
363+
@test Base.to_index(I) == BlockedLogicalIndex(I)
364+
@test Base.to_index(I) == [1, 2, 5]
365+
@test Base.to_index(I) isa BlockedLogicalIndex
363366
@test to_indices(a, (I, I)) == to_indices(a, (mask, mask))
364367
@test to_indices(a, (I, I)) == (BlockedVector(LogicalIndex(mask), [2, 1]), BlockedVector(LogicalIndex(mask), [2, 1]))
365368
@test to_indices(a, (I, I)) isa Tuple{BlockedLogicalIndex{Int},BlockedLogicalIndex{Int}}
@@ -372,7 +375,15 @@ bview(a, b) = Base.invoke(view, Tuple{AbstractArray,Any}, a, b)
372375
@test parentindices(view(a, I, I)) == (BlockedVector([1, 2, 5], [2, 1]), BlockedVector([1, 2, 5], [2, 1]))
373376
@test parentindices(view(a, I, I)) isa Tuple{BlockedVector{Int,Vector{Int}},BlockedVector{Int,Vector{Int}}}
374377
@test blocklengths.(Base.axes1.(parentindices(view(a, I, I)))) == ([2, 1], [2, 1])
378+
@test sprint(show, BlockedLogicalIndex(I)) == "[1, 2, 5]"
375379
end
380+
bl = BlockedLogicalIndex(BlockedVector([true, true, false, false, true, false], [3, 3]))
381+
@test sprint(show, "text/plain", bl) ==
382+
"2-blocked 3-element BlockedVector{Int64, Base.LogicalIndex{Int64, BlockedVector{Bool, Vector{Bool}, Tuple{BlockedOneTo{Int64, Vector{Int64}}}}}, Tuple{BlockedOneTo{Int64, Vector{Int64}}}}:\n 1\n 2\n\n 5"
383+
@test checkbounds(Bool, randn(6), bl)
384+
@test !checkbounds(Bool, randn(5), bl)
385+
@test checkindex(Bool, 1:6, bl)
386+
@test !checkindex(Bool, 1:5, bl)
376387
end
377388
end
378389

0 commit comments

Comments
 (0)