From 2bd6adf0c078395898588b5c8e44db026636ca2a Mon Sep 17 00:00:00 2001 From: Simon Mandlik Date: Tue, 16 Nov 2021 10:09:09 +0100 Subject: [PATCH] printchildren are not automatically sorted anymore, v2.1.0 --- Project.toml | 2 +- src/traversal_encoding.jl | 15 --------------- test/printing.jl | 38 ++++++++++++++++++++++++++++---------- test/runtests.jl | 3 +-- 4 files changed, 30 insertions(+), 28 deletions(-) diff --git a/Project.toml b/Project.toml index 7d3c1ef..1c317e4 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "HierarchicalUtils" uuid = "f9ccea15-0695-44b9-8113-df7c26ae4fa9" authors = ["Simon Mandlik "] -version = "2.0.1" +version = "2.1.0" [deps] DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" diff --git a/src/traversal_encoding.jl b/src/traversal_encoding.jl index e0af4e9..035d8be 100644 --- a/src/traversal_encoding.jl +++ b/src/traversal_encoding.jl @@ -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)) diff --git a/test/printing.jl b/test/printing.jl index 8224ab3..628d9e2 100644 --- a/test/printing.jl +++ b/test/printing.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index d6999db..9e3c1cd 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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