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

Function TestTemporalStore_WithIntervalTree

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

Source from the content-addressed store, hash-verified

258}
259
260func TestTemporalStore_WithIntervalTree(t *testing.T) {
261 store := NewTemporalStore()
262
263 atom := ast.Atom{
264 Predicate: ast.PredicateSym{Symbol: "test", Arity: 1},
265 Args: []ast.BaseTerm{ast.String("alice")},
266 }
267
268 interval := makeTestInterval(100, 200)
269
270 // Add fact
271 added, err := store.Add(atom, interval)
272 if err != nil {
273 t.Fatalf("Add failed: %v", err)
274 }
275 if !added {
276 t.Error("Expected Add to return true")
277 }
278
279 // Check count
280 if store.EstimateFactCount() != 1 {
281 t.Errorf("Expected count 1, got %d", store.EstimateFactCount())
282 }
283
284 // Query at valid time
285 query := ast.NewQuery(atom.Predicate)
286 foundAt := false
287 store.GetFactsAt(query, time.Unix(0, 150), func(tf TemporalFact) error {
288 foundAt = true
289 return nil
290 })
291 if !foundAt {
292 t.Error("Expected to find fact at valid time")
293 }
294
295 // Query at invalid time
296 foundAt = false
297 store.GetFactsAt(query, time.Unix(0, 50), func(tf TemporalFact) error {
298 foundAt = true
299 return nil
300 })
301 if foundAt {
302 t.Error("Did not expect to find fact at invalid time")
303 }
304}
305
306func TestTemporalStore_IntervalTreeLimit(t *testing.T) {
307 store := NewTemporalStore(WithMaxIntervalsPerAtom(3))

Callers

nothing calls this directly

Calls 8

AddMethod · 0.95
EstimateFactCountMethod · 0.95
GetFactsAtMethod · 0.95
StringFunction · 0.92
NewQueryFunction · 0.92
NewTemporalStoreFunction · 0.85
makeTestIntervalFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected