(t *testing.T)
| 95 | } |
| 96 | |
| 97 | func TestIntervalTree_QueryRange(t *testing.T) { |
| 98 | tree := NewIntervalTree() |
| 99 | |
| 100 | // Insert intervals: [100, 200], [150, 250], [50, 75], [300, 400] |
| 101 | tree.Insert(makeTestInterval(100, 200)) |
| 102 | tree.Insert(makeTestInterval(150, 250)) |
| 103 | tree.Insert(makeTestInterval(50, 75)) |
| 104 | tree.Insert(makeTestInterval(300, 400)) |
| 105 | |
| 106 | tests := []struct { |
| 107 | name string |
| 108 | start int64 |
| 109 | end int64 |
| 110 | wantCount int |
| 111 | }{ |
| 112 | {"before all", 0, 40, 0}, |
| 113 | {"overlap first", 60, 70, 1}, |
| 114 | {"overlap two", 175, 180, 2}, |
| 115 | {"overlap all middle", 100, 250, 2}, |
| 116 | {"gap between", 275, 290, 0}, |
| 117 | {"overlap last", 350, 375, 1}, |
| 118 | {"overlap all", 0, 500, 4}, |
| 119 | } |
| 120 | |
| 121 | for _, tt := range tests { |
| 122 | t.Run(tt.name, func(t *testing.T) { |
| 123 | count := 0 |
| 124 | tree.QueryRange(tt.start, tt.end, func(interval ast.Interval) error { |
| 125 | count++ |
| 126 | return nil |
| 127 | }) |
| 128 | if count != tt.wantCount { |
| 129 | t.Errorf("QueryRange(%d, %d) returned %d intervals, want %d", tt.start, tt.end, count, tt.wantCount) |
| 130 | } |
| 131 | }) |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | func TestIntervalTree_Balance(t *testing.T) { |
| 136 | tree := NewIntervalTree() |
nothing calls this directly
no test coverage detected