(t *testing.T)
| 29 | } |
| 30 | |
| 31 | func TestTemporalEvaluator_DiamondMinus(t *testing.T) { |
| 32 | store := factstore.NewTemporalStore() |
| 33 | |
| 34 | // Set up test data: employee was active from Jan 1 to Jan 15, 2024 |
| 35 | activeAtom := ast.NewAtom("active", name("/alice")) |
| 36 | store.Add(activeAtom, ast.DateInterval(2024, 1, 1, 2024, 1, 15)) |
| 37 | |
| 38 | // Evaluation time: Jan 20, 2024 |
| 39 | evalTime := ast.Date(2024, 1, 20) |
| 40 | te := NewTemporalEvaluator(store, evalTime) |
| 41 | |
| 42 | tests := []struct { |
| 43 | name string |
| 44 | operator ast.TemporalOperator |
| 45 | wantSolns int |
| 46 | description string |
| 47 | }{ |
| 48 | { |
| 49 | name: "within_range", |
| 50 | // <-[0d, 30d] active(/alice) - was active sometime in last 30 days |
| 51 | // The operator interval uses negative timestamps to represent durations |
| 52 | // Start: 0 days ago (now), End: 30 days ago |
| 53 | operator: ast.TemporalOperator{ |
| 54 | Type: ast.DiamondMinus, |
| 55 | Interval: ast.NewInterval( |
| 56 | ast.NewDurationBound(0), // 0 duration |
| 57 | ast.NewDurationBound(30*24*time.Hour), // 30 days |
| 58 | ), |
| 59 | }, |
| 60 | wantSolns: 1, |
| 61 | description: "Alice was active within the last 30 days", |
| 62 | }, |
| 63 | { |
| 64 | name: "outside_range", |
| 65 | // <-[0d, 3d] active(/alice) - was active sometime in last 3 days |
| 66 | operator: ast.TemporalOperator{ |
| 67 | Type: ast.DiamondMinus, |
| 68 | Interval: ast.NewInterval( |
| 69 | ast.NewDurationBound(0), // 0 days ago |
| 70 | ast.NewDurationBound(3*24*time.Hour), |
| 71 | ), |
| 72 | }, |
| 73 | wantSolns: 0, |
| 74 | description: "Alice was NOT active within the last 3 days (she left on Jan 15)", |
| 75 | }, |
| 76 | } |
| 77 | |
| 78 | for _, tt := range tests { |
| 79 | t.Run(tt.name, func(t *testing.T) { |
| 80 | tl := ast.TemporalLiteral{ |
| 81 | Literal: activeAtom, |
| 82 | Operator: &tt.operator, |
| 83 | } |
| 84 | |
| 85 | solutions, err := te.EvalTemporalLiteral(tl, unionfind.New()) |
| 86 | if err != nil { |
| 87 | t.Fatalf("EvalTemporalLiteral error: %v", err) |
| 88 | } |
nothing calls this directly
no test coverage detected