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

Function TestIntervalTree_QueryPoint

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

Source from the content-addressed store, hash-verified

57}
58
59func TestIntervalTree_QueryPoint(t *testing.T) {
60 tree := NewIntervalTree()
61
62 // Insert intervals: [100, 200], [150, 250], [50, 75], [300, 400]
63 tree.Insert(makeTestInterval(100, 200))
64 tree.Insert(makeTestInterval(150, 250))
65 tree.Insert(makeTestInterval(50, 75))
66 tree.Insert(makeTestInterval(300, 400))
67
68 tests := []struct {
69 name string
70 timestamp int64
71 wantCount int
72 }{
73 {"before all", 25, 0},
74 {"in first interval only", 60, 1},
75 {"at start of interval", 100, 1},
76 {"in overlapping region", 175, 2},
77 {"at end of first interval (overlaps with second)", 200, 2},
78 {"between intervals", 275, 0},
79 {"in last interval", 350, 1},
80 {"after all", 500, 0},
81 }
82
83 for _, tt := range tests {
84 t.Run(tt.name, func(t *testing.T) {
85 count := 0
86 tree.QueryPoint(tt.timestamp, func(interval ast.Interval) error {
87 count++
88 return nil
89 })
90 if count != tt.wantCount {
91 t.Errorf("QueryPoint(%d) returned %d intervals, want %d", tt.timestamp, count, tt.wantCount)
92 }
93 })
94 }
95}
96
97func TestIntervalTree_QueryRange(t *testing.T) {
98 tree := NewIntervalTree()

Callers

nothing calls this directly

Calls 4

InsertMethod · 0.95
QueryPointMethod · 0.95
NewIntervalTreeFunction · 0.85
makeTestIntervalFunction · 0.85

Tested by

no test coverage detected