From ef867e5798fe6cb8d9dccc87b0222e104147228d Mon Sep 17 00:00:00 2001 From: richardreeve Date: Tue, 21 Nov 2023 19:43:05 +0000 Subject: [PATCH] Fix missing exports and add tests --- src/Phylo.jl | 11 +++++++---- test/test_Interface.jl | 26 +++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/Phylo.jl b/src/Phylo.jl index 503d1756..5b57b691 100644 --- a/src/Phylo.jl +++ b/src/Phylo.jl @@ -34,9 +34,12 @@ export OneTree, ManyTrees abstract type AbstractNode{RootType <: Rootedness, NodeLabel} end abstract type AbstractBranch{RootType <: Rootedness, NodeLabel} end +using Distances abstract type AbstractTree{TT <: TreeType, RT <: Rootedness, NL, N <: AbstractNode{RT, NL}, - B <: AbstractBranch{RT, NL}} end + B <: AbstractBranch{RT, NL}} <: Distances.UnionMetric +end + export AbstractTree @enum TraversalOrder anyorder preorder inorder postorder breadthfirst @@ -88,9 +91,9 @@ end include("Interface.jl") # AbstractTree methods -export ntrees, gettrees, nroots, getroots, getroot +export ntrees, gettrees, nroots, getroots, getroot, gettree export treenametype, gettreenames, gettreename #, getonetree #unimplemented -export roottype, nodetype, nodedatatype, nodenametype +export treetype, roottype, nodetype, nodedatatype, nodenametype export branchtype, branchdatatype, branchnametype export createbranch!, deletebranch! export createnode!, createnodes!, deletenode! @@ -114,7 +117,7 @@ export validate!, traversal, branchdims export isleaf, isroot, isinternal, isunattached export indegree, outdegree, hasinbound, getinbound, getoutbounds export hasoutboundspace, hasinboundspace -export getleafnames, getleaves, nleaves, nnodes, nbranches +export getleafnames, getleaves, nleaves, nnodes, ninternal, nbranches export getleafinfo, setleafinfo!, leafinfotype export getnodedata, setnodedata! export hasheight, getheight, setheight! diff --git a/test/test_Interface.jl b/test/test_Interface.jl index 2c33d4a5..e454460e 100644 --- a/test/test_Interface.jl +++ b/test/test_Interface.jl @@ -10,10 +10,12 @@ using Test BinaryTree{ManyRoots, DataFrame, Vector{Float64}}, RootedTree, ManyRootTree] + @test treetype(TreeType) == OneTree species = ["Dog", "Cat", "Human", "Potato", "Apple"] tree = TreeType(species) othernodes = ["Some 1", "Some 2"] nodes = createnodes!(tree, othernodes) + @test !((roottype(TreeType) ≡ ManyRoots) ⊻ validate!(tree)) @test [getnodename(tree, node) for node in nodes] == othernodes extra = [getnodename(tree, node) for node in createnodes!(tree, 1)] @test isa(extra[1], String) @@ -31,13 +33,19 @@ using Test allnodes = copy(innodes) pop!(innodes) @test_throws Exception getroot(tree) + matchbranch = true branches = map(innodes) do node itr = Iterators.filter(name -> hasoutboundspace(tree, name) && name != node && name ∉ getdescendants(tree, node) && name ∉ species, allnodes) - getbranch(tree, createbranch!(tree, first(itr), node)) - end + matchbranch = !matchbranch + if matchbranch + getbranch(tree, createbranch!(tree, getnode(tree, first(itr)), getnode(tree, node))) + else + getbranch(tree, createbranch!(tree, getnodename(tree, first(itr)), getnodename(tree, node))) + end + end @test_nowarn getroot(tree) branchnames = [getbranchname(tree, branch) for branch in branches] @test Set(branchnames) == Set(getbranchnames(tree)) @@ -84,6 +92,14 @@ using Test @test_nowarn createbranch!(tree, who, species[1]) @test hasnode(tree, species[1]) @test validate!(tree) + NT = typeof(node1) + @test NT ≡ String || nodenametype(NT) ≡ String + @test NT ≡ String || branchnametype(NT) ≡ Int + @test NT ≡ String || roottype(NT) ≡ roottype(TreeType) + BT = typeof(b) + @test nodenametype(BT) ≡ String + @test branchnametype(BT) ≡ Int + @test roottype(BT) ≡ roottype(TreeType) @test all(isleaf(tree, node) for node in species) @test all((!isroot(tree, node) & !isunattached(tree, node) & !isinternal(tree, node)) for node in species) @@ -92,7 +108,11 @@ using Test Set(getnodename(tree, dst(tree, branch)) for branch in getbranches(tree)) == Set(getnodenames(tree)) createnode!(tree) - @test (roottype(TreeType) == OneRoot) ⊻ validate!(tree) + @test treenametype(TreeType) ≡ Int ? gettreename(tree) == 1 : gettreename(tree) == "Tree" + @test (roottype(TreeType) ≡ OneRoot) ⊻ validate!(tree) + @test gettree(tree) ≡ tree + @test length(getnodes(tree)) == nnodes(tree) + @test ninternal(tree) == nnodes(tree) - nleaves(tree) end end