Skip to content

Commit 92bc57f

Browse files
committed
Add tests for AbstractTrees interface
1 parent 459e54d commit 92bc57f

File tree

4 files changed

+72
-1
lines changed

4 files changed

+72
-1
lines changed

src/abstracttrees.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ AbstractTrees.children(node::STRNode) = node.children
99
AbstractTrees.nodevalue(node::STRNode) = Extents.extent(node)
1010

1111
# Implement the interface for STRLeafNodes
12-
AbstractTrees.children(node::STRLeafNode) = STRLeafNode[]
12+
AbstractTrees.children(node::STRLeafNode) = STRLeafNode[] # no children for a leaf node
1313
AbstractTrees.nodevalue(node::STRLeafNode) = Extents.extent(node)
1414

1515

test/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[deps]
2+
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
23
ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3"
34
Extents = "411431e0-e8b7-467b-b5e0-f676ba4f2910"
45
GeoInterface = "cf35fbd7-0cd7-5166-be24-54bfbe79505f"

test/abstracttrees.jl

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
2+
using Test
3+
using AbstractTrees
4+
using SortTileRecursiveTree
5+
using SortTileRecursiveTree: STRtree, STRNode, STRLeafNode
6+
using Extents
7+
using AbstractTrees: GI
8+
9+
@testset "AbstractTrees interface" begin
10+
# Create a simple test tree structure
11+
# Level 1: root with extent (0,0) -> (10,10)
12+
# Level 2: two children with extents (0,0)->(5,5) and (5,5)->(10,10)
13+
# Level 3: leaf nodes
14+
15+
geom1 = GI.MultiPoint([GI.Point((0.0, 0.0)), GI.Point((2.5, 2.5))])
16+
geom2 = GI.MultiPoint([GI.Point((2.5, 2.5)), GI.Point((5.0, 5.0))])
17+
geom3 = GI.MultiPoint([GI.Point((5.0, 5.0)), GI.Point((7.5, 7.5))])
18+
geom4 = GI.MultiPoint([GI.Point((7.5, 7.5)), GI.Point((10.0, 10.0))])
19+
20+
tree = STRtree([geom1, geom1, geom2, geom2, geom3, geom3, geom4, geom4]; nodecapacity=2)
21+
22+
@testset "Basic Tree Structure" begin
23+
# Test children access
24+
@test length(children(tree)) == 2
25+
@test length(children(first(children(tree)))) == 2
26+
@test length(children(last(children(tree)))) == 2
27+
@test all(x -> isa(x, STRLeafNode), children(first(children(tree))))
28+
@test all(x -> isa(x, STRLeafNode), children(last(children(tree))))
29+
end
30+
31+
@testset "Node Values" begin
32+
# Test that nodevalue returns proper extents
33+
@test nodevalue(tree) isa Extent
34+
@test nodevalue(first(children(tree))) isa Extent
35+
@test nodevalue(first(children(last(children(tree))))) isa Extent
36+
end
37+
38+
@testset "Tree Traits" begin
39+
# Test ParentLinks trait
40+
@test ParentLinks(STRtree) == ImplicitParents()
41+
@test ParentLinks(STRNode) == ImplicitParents()
42+
@test ParentLinks(STRLeafNode) == ImplicitParents()
43+
44+
# Test SiblingLinks trait
45+
@test SiblingLinks(STRtree) == ImplicitSiblings()
46+
@test SiblingLinks(STRNode) == ImplicitSiblings()
47+
@test SiblingLinks(STRLeafNode) == ImplicitSiblings()
48+
49+
# Test ChildIndexing trait
50+
@test ChildIndexing(STRtree) == IndexedChildren()
51+
@test ChildIndexing(STRNode) == IndexedChildren()
52+
end
53+
54+
@testset "Tree Traversal Iterators" begin
55+
# Test that we can traverse the tree
56+
nodes = collect(PreOrderDFS(tree))
57+
@test length(nodes) == 7 # 1 root + 2 internal nodes + 4 leaves
58+
59+
leaves = collect(Leaves(tree))
60+
@test length(leaves) == 4
61+
@test all(x -> x isa STRLeafNode, leaves)
62+
end
63+
64+
@testset "Node Type Stability" begin
65+
@test NodeType(STRtree) == NodeTypeUnknown()
66+
@test NodeType(STRNode) == NodeTypeUnknown()
67+
@test NodeType(STRLeafNode) == NodeTypeUnknown()
68+
end
69+
end

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ import GeoInterface as GI
3434
@test points[query_result] == points[:,1]
3535
@test query(tree, Extent(X=(0, 0.5), Y=(0, 0.5))) == []
3636
end
37+
@testset "AbstractTrees interface" begin; include("abstracttrees.jl"); end
3738
end

0 commit comments

Comments
 (0)