Skip to content

Commit

Permalink
printchildren are not automatically sorted anymore, v2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmandlik committed Nov 16, 2021
1 parent 15fe88c commit 2bd6adf
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "HierarchicalUtils"
uuid = "f9ccea15-0695-44b9-8113-df7c26ae4fa9"
authors = ["Simon Mandlik <simon.mandlik@gmail.com>"]
version = "2.0.1"
version = "2.1.0"

[deps]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Expand Down
15 changes: 0 additions & 15 deletions src/traversal_encoding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,6 @@ function _walk(::LeafNode, n, c::AbstractString)
end
end

# function _walk(::SingletonNode, n, c::AbstractString)
# !isempty(c) || return n
# i, nc = decode(c, 1)
# 0 <= i <= 1 || error("Invalid index!")
# if i == 0
# if Set(nc) ⊆ ['0']
# return n
# else
# error("Invalid index!")
# end
# end
# _walk(_children_sorted(n), nc)
# end

# function _walk(::Union{SingletonNode, InnerNode}, n, c::AbstractString)
function _walk(::InnerNode, n, c::AbstractString)
!isempty(c) || return n
i, nc = decode(c, nprintchildren(n))
Expand Down
38 changes: 28 additions & 10 deletions test/printing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,39 @@ end
@test numlines(buf) == min(l, vtrunc + 1) + 1 # one line for ellipsis ⋮ and one for the header
end

@testset "printtree labelled children sorted" begin
t1 = Dict("a" => Leaf(1), "b" => Leaf(2), "c" => Leaf(3))
t2 = Dict("c" => Leaf(3), "a" => Leaf(1), "b" => Leaf(2))
t3 = Dict("b" => Leaf(2), "c" => Leaf(3), "a" => Leaf(1))
@test all([t1, t2, t3]) do t
buff = IOBuffer()
printtree(buff, t)
String(take!(buff)) ==
@testset "printtree labelled children not sorted" begin
t = NTVertex(0, (; a=Leaf(1), b=Leaf(2), c=Leaf(3)))
buff = IOBuffer()
printtree(buff, t)
@test String(take!(buff)) ==
"""
Dict of
NTVertex (0) comm
├── a: Leaf (1) comm
├── b: Leaf (2) comm
└── c: Leaf (3) comm
"""
end

t = NTVertex(0, (; c=Leaf(3), b=Leaf(2), a=Leaf(1)))
buff = IOBuffer()
printtree(buff, t)
@test String(take!(buff)) ==
"""
NTVertex (0) comm
├── c: Leaf (3) comm
├── b: Leaf (2) comm
└── a: Leaf (1) comm
"""

t = NTVertex(0, (; b=Leaf(2), c=Leaf(3), a=Leaf(1)))
buff = IOBuffer()
printtree(buff, t)
@test String(take!(buff)) ==
"""
NTVertex (0) comm
├── b: Leaf (2) comm
├── c: Leaf (3) comm
└── a: Leaf (1) comm
"""
end

@testset "printtree traversal encoding" begin
Expand Down
3 changes: 1 addition & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ import HierarchicalUtils: NodeType, nodeshow, nodecommshow, children
NodeType(::Type{Leaf}) = HierarchicalUtils.LeafNode()

NodeType(::Type{<:VectorVertex}) = HierarchicalUtils.InnerNode()
# we shuffle each time for the sake of testing
children(t::VectorVertex) = shuffle([k => ch for (k,ch) in enumerate(t.chs)])
children(t::VectorVertex) = [k => ch for (k,ch) in enumerate(t.chs)]

NodeType(::Type{<:NTVertex}) = HierarchicalUtils.InnerNode()
children(t::NTVertex) = t.chs
Expand Down

2 comments on commit 2bd6adf

@simonmandlik
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/48860

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.1.0 -m "<description of version>" 2bd6adf0c078395898588b5c8e44db026636ca2a
git push origin v2.1.0

Please sign in to comment.