(t *testing.T)
| 342 | } |
| 343 | |
| 344 | func TestIntegration_BoxMinusQuery(t *testing.T) { |
| 345 | // Create a temporal store |
| 346 | store := factstore.NewTemporalStore() |
| 347 | |
| 348 | // Add a fact: employee was employed from Jan 1, 2023 to Dec 31, 2024 |
| 349 | employed := ast.NewAtom("employed", name("/alice")) |
| 350 | store.Add(employed, ast.TimeInterval( |
| 351 | ast.Date(2023, 1, 1), |
| 352 | ast.Date(2024, 12, 31), |
| 353 | )) |
| 354 | |
| 355 | tests := []struct { |
| 356 | name string |
| 357 | evalTime time.Time |
| 358 | lookbackDays int |
| 359 | wantMatch bool |
| 360 | }{ |
| 361 | { |
| 362 | name: "Mid-2024: employed continuously for last 365 days", |
| 363 | evalTime: ast.Date(2024, 6, 15), |
| 364 | lookbackDays: 365, |
| 365 | wantMatch: true, |
| 366 | }, |
| 367 | { |
| 368 | name: "Early 2023: employed continuously for last 30 days", |
| 369 | evalTime: ast.Date(2023, 2, 15), |
| 370 | lookbackDays: 30, |
| 371 | wantMatch: true, |
| 372 | }, |
| 373 | { |
| 374 | name: "Early 2023: NOT employed continuously for last 365 days", |
| 375 | evalTime: ast.Date(2023, 2, 15), |
| 376 | lookbackDays: 365, |
| 377 | wantMatch: false, // Alice wasn't employed before Jan 1, 2023 |
| 378 | }, |
| 379 | } |
| 380 | |
| 381 | for _, test := range tests { |
| 382 | t.Run(test.name, func(t *testing.T) { |
| 383 | te := NewTemporalEvaluator(store, test.evalTime) |
| 384 | |
| 385 | query := ast.NewAtom("employed", name("/alice")) |
| 386 | operator := ast.TemporalOperator{ |
| 387 | Type: ast.BoxMinus, |
| 388 | Interval: ast.NewInterval( |
| 389 | ast.NewDurationBound(0), // ~now |
| 390 | ast.NewDurationBound(time.Duration(test.lookbackDays)*24*time.Hour), |
| 391 | ), |
| 392 | } |
| 393 | |
| 394 | tl := ast.TemporalLiteral{ |
| 395 | Literal: query, |
| 396 | Operator: &operator, |
| 397 | } |
| 398 | |
| 399 | solutions, err := te.EvalTemporalLiteral(tl, unionfind.New()) |
| 400 | if err != nil { |
| 401 | t.Fatalf("EvalTemporalLiteral failed: %v", err) |
nothing calls this directly
no test coverage detected