Skip to content

Commit

Permalink
Fix missing exports and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
richardreeve committed Nov 21, 2023
1 parent 771f096 commit ef867e5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/Phylo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!
Expand All @@ -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!
Expand Down
26 changes: 23 additions & 3 deletions test/test_Interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down

0 comments on commit ef867e5

Please sign in to comment.