MCPcopy
hub / github.com/google/mangle / TestIntervalTree_Balance

Function TestIntervalTree_Balance

factstore/interval_tree_test.go:135–155  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

133}
134
135func TestIntervalTree_Balance(t *testing.T) {
136 tree := NewIntervalTree()
137
138 // Insert many intervals in sorted order (worst case for naive BST)
139 for i := int64(0); i < 100; i++ {
140 tree.Insert(makeTestInterval(i*10, i*10+5))
141 }
142
143 if tree.Size() != 100 {
144 t.Errorf("Expected size 100, got %d", tree.Size())
145 }
146
147 // Tree should be balanced, so root height should be O(log n)
148 // For 100 elements, height should be around 7-8 (log2(100) ≈ 6.6)
149 if tree.root == nil {
150 t.Fatal("Root should not be nil")
151 }
152 if tree.root.height > 10 {
153 t.Errorf("Tree appears unbalanced: height %d for 100 elements", tree.root.height)
154 }
155}
156
157func TestIntervalTree_All(t *testing.T) {
158 tree := NewIntervalTree()

Callers

nothing calls this directly

Calls 4

InsertMethod · 0.95
SizeMethod · 0.95
NewIntervalTreeFunction · 0.85
makeTestIntervalFunction · 0.85

Tested by

no test coverage detected