Skip to content

Commit ed9f14c

Browse files
committed
Add Base.length(ci::ComponentIndex)
1 parent db1023a commit ed9f14c

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/componentindex.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ const NullComponentIndex{Idx} = ComponentIndex{Idx, NullAxis}
1313

1414
Base.:(==)(ci1::ComponentIndex, ci2::ComponentIndex) = ci1.idx == ci2.idx && ci1.ax == ci2.ax
1515

16+
Base.length(ci::ComponentIndex) = length(ci.idx)
17+
1618

1719
"""
1820
KeepIndex(idx)

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,12 @@ end
366366
@test ax[(:a, :c)] == ax[[:a, :c]] == ComponentArrays.ComponentIndex([1, 3, 4], Axis(a = 1, c = r2v(2:3)))
367367
ax2 = getaxes(ca2)[1]
368368
@test ax2[(:a, :c)] == ax2[[:a, :c]] == ComponentArrays.ComponentIndex([1, 3:8...], Axis(a = 1, c = ViewAxis(2:7, ShapedAxis((2,3)))))
369+
370+
@test length(ComponentArrays.ComponentIndex(1, ComponentArrays.NullAxis())) == 1
371+
@test length(ComponentArrays.ComponentIndex(3:4, ShapedAxis(size(3:4)))) == 2
372+
@test length(ComponentArrays.ComponentIndex(5:8, Axis(a = r2v(1:3), b = 4))) == 4
373+
@test length(ComponentArrays.ComponentIndex([1, 3, 4], Axis(a = 1, c = r2v(2:3)))) == 3
374+
@test length(ComponentArrays.ComponentIndex([1, 3:8...], Axis(a = 1, c = ViewAxis(2:7, ShapedAxis((2,3)))))) == 7
369375
end
370376

371377
@testset "KeepIndex" begin

0 commit comments

Comments
 (0)