Skip to content

Commit 6c8f4f9

Browse files
authored
implement empty and isempty (#48)
1 parent 412f814 commit 6c8f4f9

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/RootedTrees.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ iscanonical(t::RootedTree) = t.iscanonical
8383
#TODO: Validate rooted tree in constructor?
8484

8585
Base.copy(t::RootedTree) = RootedTree(copy(t.level_sequence), t.iscanonical)
86+
Base.isempty(t::RootedTree) = isempty(t.level_sequence)
87+
Base.empty(t::RootedTree) = RootedTree(empty(t.level_sequence), iscanonical(t))
8688

8789

8890
# #function RootedTree(sequence::Vector{T}, valid::Bool)

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,18 @@ Plots.unicodeplots()
6767
# more tests of the canonical representation
6868
t = rootedtree([1, 2, 3, 2, 3, 3, 2])
6969
@test t.level_sequence == [1, 2, 3, 3, 2, 3, 2]
70+
@test !isempty(t)
7071

7172
t = rootedtree([1, 2, 3, 2, 3, 4, 2, 3])
7273
@test t.level_sequence == [1, 2, 3, 4, 2, 3, 2, 3]
74+
@test !isempty(t)
7375

7476
t = rootedtree([1, 2, 3, 2, 3, 3, 2, 3])
7577
@test t.level_sequence == [1, 2, 3, 3, 2, 3, 2, 3]
78+
@test !isempty(t)
79+
80+
@test isempty(rootedtree(Int[]))
81+
@test isempty(empty(t))
7682

7783
level_sequence = zeros(Int, RootedTrees.BUFFER_LENGTH + 1)
7884
level_sequence[1] -= 1

0 commit comments

Comments
 (0)