(t *testing.T)
| 367 | } |
| 368 | |
| 369 | func TestTemporalEvaluator_BoxPlus(t *testing.T) { |
| 370 | store := factstore.NewTemporalStore() |
| 371 | |
| 372 | // Set up test data: contract valid from Jan 1, 2024 to Dec 31, 2024 |
| 373 | contractAtom := ast.NewAtom("contract", name("/customer")) |
| 374 | store.Add(contractAtom, ast.TimeInterval( |
| 375 | ast.Date(2024, 1, 1), |
| 376 | ast.Date(2024, 12, 31), |
| 377 | )) |
| 378 | |
| 379 | // Evaluation time: Jan 15, 2024 |
| 380 | evalTime := ast.Date(2024, 1, 15) |
| 381 | te := NewTemporalEvaluator(store, evalTime) |
| 382 | |
| 383 | tests := []struct { |
| 384 | name string |
| 385 | operator ast.TemporalOperator |
| 386 | wantSolns int |
| 387 | description string |
| 388 | }{ |
| 389 | { |
| 390 | name: "continuously_true_future", |
| 391 | // [+[0d, 30d] contract(/customer) - will contract be valid for all of next 30 days? |
| 392 | operator: ast.TemporalOperator{ |
| 393 | Type: ast.BoxPlus, |
| 394 | Interval: ast.NewInterval( |
| 395 | ast.NewDurationBound(0), |
| 396 | ast.NewDurationBound(30*24*time.Hour), |
| 397 | ), |
| 398 | }, |
| 399 | wantSolns: 1, |
| 400 | description: "Contract is valid for the entire next 30 days", |
| 401 | }, |
| 402 | { |
| 403 | name: "not_continuously_true_future", |
| 404 | // [+[0d, 365d] contract(/customer) - will contract be valid for all of next 365 days? |
| 405 | operator: ast.TemporalOperator{ |
| 406 | Type: ast.BoxPlus, |
| 407 | Interval: ast.NewInterval( |
| 408 | ast.NewDurationBound(0), |
| 409 | ast.NewDurationBound(365*24*time.Hour), |
| 410 | ), |
| 411 | }, |
| 412 | wantSolns: 0, |
| 413 | description: "Contract expires before 365 days (ends Dec 31)", |
| 414 | }, |
| 415 | } |
| 416 | |
| 417 | for _, tt := range tests { |
| 418 | t.Run(tt.name, func(t *testing.T) { |
| 419 | tl := ast.TemporalLiteral{ |
| 420 | Literal: contractAtom, |
| 421 | Operator: &tt.operator, |
| 422 | } |
| 423 | |
| 424 | solutions, err := te.EvalTemporalLiteral(tl, unionfind.New()) |
| 425 | if err != nil { |
| 426 | t.Fatalf("EvalTemporalLiteral error: %v", err) |
nothing calls this directly
no test coverage detected