(t *testing.T)
| 2265 | } |
| 2266 | |
| 2267 | func TestCostTrackingConsistentAcrossEvals(t *testing.T) { |
| 2268 | env := testEnv(t, |
| 2269 | Variable("val1", IntType), |
| 2270 | Variable("val2", IntType), |
| 2271 | ) |
| 2272 | ast, iss := env.Compile(`val1 + val2`) |
| 2273 | if iss.Err() != nil { |
| 2274 | t.Fatalf("env.Compile() failed: %v", iss.Err()) |
| 2275 | } |
| 2276 | checkedAst, iss := env.Check(ast) |
| 2277 | if iss.Err() != nil { |
| 2278 | t.Fatalf("env.Check() failed: %v", iss.Err()) |
| 2279 | } |
| 2280 | program, err := env.Program(checkedAst, CostTracking(nil)) |
| 2281 | if err != nil { |
| 2282 | t.Fatalf("env.Program() failed: %v", err) |
| 2283 | } |
| 2284 | input := map[string]any{"val1": 1, "val2": 2} |
| 2285 | |
| 2286 | _, det1, err := program.Eval(input) |
| 2287 | if err != nil { |
| 2288 | t.Fatalf("first Eval() failed: %v", err) |
| 2289 | } |
| 2290 | cost1 := det1.ActualCost() |
| 2291 | if cost1 == nil { |
| 2292 | t.Fatal("first Eval() returned nil ActualCost") |
| 2293 | } |
| 2294 | |
| 2295 | _, det2, err := program.Eval(input) |
| 2296 | if err != nil { |
| 2297 | t.Fatalf("second Eval() failed: %v", err) |
| 2298 | } |
| 2299 | cost2 := det2.ActualCost() |
| 2300 | if cost2 == nil { |
| 2301 | t.Fatal("second Eval() returned nil ActualCost") |
| 2302 | } |
| 2303 | |
| 2304 | if *cost1 != *cost2 { |
| 2305 | t.Errorf("ActualCost mismatch across evaluations: first=%d, second=%d", *cost1, *cost2) |
| 2306 | } |
| 2307 | } |
| 2308 | |
| 2309 | func TestPartialVars(t *testing.T) { |
| 2310 | env := testEnv(t, |
nothing calls this directly
no test coverage detected