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
0 commit comments