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

Function TestTemporalStore_GetFactsAt

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

Source from the content-addressed store, hash-verified

147}
148
149func TestTemporalStore_GetFactsAt(t *testing.T) {
150 store := NewTemporalStore()
151
152 // Alice employed from 2020-2023
153 aliceEmployed := ast.NewAtom("employed", name("/alice"))
154 store.Add(aliceEmployed, ast.TimeInterval(
155 ast.Date(2020, 1, 1),
156 ast.Date(2023, 12, 31),
157 ))
158
159 // Bob employed from 2022 onwards
160 bobEmployed := ast.NewAtom("employed", name("/bob"))
161 store.Add(bobEmployed, ast.TimeInterval(
162 ast.Date(2022, 1, 1),
163 ast.Date(2099, 12, 31),
164 ))
165
166 tests := []struct {
167 name string
168 queryTime time.Time
169 wantCount int
170 }{
171 {
172 name: "before both",
173 queryTime: ast.Date(2019, 6, 15),
174 wantCount: 0,
175 },
176 {
177 name: "alice only",
178 queryTime: ast.Date(2021, 6, 15),
179 wantCount: 1,
180 },
181 {
182 name: "both employed",
183 queryTime: ast.Date(2022, 6, 15),
184 wantCount: 2,
185 },
186 {
187 name: "bob only (after alice left)",
188 queryTime: ast.Date(2024, 6, 15),
189 wantCount: 1,
190 },
191 }
192
193 query := ast.NewQuery(ast.PredicateSym{Symbol: "employed", Arity: 1})
194
195 for _, tt := range tests {
196 t.Run(tt.name, func(t *testing.T) {
197 count := 0
198 err := store.GetFactsAt(query, tt.queryTime, func(tf TemporalFact) error {
199 count++
200 return nil
201 })
202 if err != nil {
203 t.Fatalf("GetFactsAt error: %v", err)
204 }
205 if count != tt.wantCount {
206 t.Errorf("GetFactsAt count = %d, want %d", count, tt.wantCount)

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected