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

Function TestTemporalFactStoreAdapter

factstore/temporal_test.go:439–482  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

437}
438
439func TestTemporalFactStoreAdapter(t *testing.T) {
440 temporal := NewTemporalStore()
441
442 // Add some temporal facts
443 alice := ast.NewAtom("employed", name("/alice"))
444 bob := ast.NewAtom("employed", name("/bob"))
445
446 temporal.Add(alice, ast.TimeInterval(
447 ast.Date(2020, 1, 1),
448 ast.Date(2023, 12, 31),
449 ))
450 temporal.Add(bob, ast.TimeInterval(
451 ast.Date(2022, 1, 1),
452 ast.Date(2099, 12, 31),
453 ))
454
455 // Test adapter without time constraint
456 adapter := NewTemporalFactStoreAdapter(temporal)
457
458 query := ast.NewQuery(ast.PredicateSym{Symbol: "employed", Arity: 1})
459 count := 0
460 adapter.GetFacts(query, func(a ast.Atom) error {
461 count++
462 return nil
463 })
464
465 if count != 2 {
466 t.Errorf("Adapter without time: count = %d, want 2", count)
467 }
468
469 // Test adapter with time constraint
470 queryTime := ast.Date(2021, 6, 15)
471 adapterAt := NewTemporalFactStoreAdapterAt(temporal, queryTime)
472
473 count = 0
474 adapterAt.GetFacts(query, func(a ast.Atom) error {
475 count++
476 return nil
477 })
478
479 if count != 1 {
480 t.Errorf("Adapter at 2021-06-15: count = %d, want 1 (only alice)", count)
481 }
482}
483
484func TestTemporalFactStoreAdapter_Add(t *testing.T) {
485 temporal := NewTemporalStore()

Callers

nothing calls this directly

Calls 11

AddMethod · 0.95
GetFactsMethod · 0.95
NewAtomFunction · 0.92
TimeIntervalFunction · 0.92
DateFunction · 0.92
NewQueryFunction · 0.92
NewTemporalStoreFunction · 0.85
nameFunction · 0.70
GetFactsMethod · 0.65

Tested by

no test coverage detected