(t *testing.T)
| 2074 | } |
| 2075 | |
| 2076 | func TestCostTrackingConsistentAcrossEvals(t *testing.T) { |
| 2077 | env := testEnv(t, |
| 2078 | Variable("val1", IntType), |
| 2079 | Variable("val2", IntType), |
| 2080 | ) |
| 2081 | ast, iss := env.Compile(`val1 + val2`) |
| 2082 | if iss.Err() != nil { |
| 2083 | t.Fatalf("env.Compile() failed: %v", iss.Err()) |
| 2084 | } |
| 2085 | checkedAst, iss := env.Check(ast) |
| 2086 | if iss.Err() != nil { |
| 2087 | t.Fatalf("env.Check() failed: %v", iss.Err()) |
| 2088 | } |
| 2089 | program, err := env.Program(checkedAst, CostTracking(nil)) |
| 2090 | if err != nil { |
| 2091 | t.Fatalf("env.Program() failed: %v", err) |
| 2092 | } |
| 2093 | input := map[string]any{"val1": 1, "val2": 2} |
| 2094 | |
| 2095 | _, det1, err := program.Eval(input) |
| 2096 | if err != nil { |
| 2097 | t.Fatalf("first Eval() failed: %v", err) |
| 2098 | } |
| 2099 | cost1 := det1.ActualCost() |
| 2100 | if cost1 == nil { |
| 2101 | t.Fatal("first Eval() returned nil ActualCost") |
| 2102 | } |
| 2103 | |
| 2104 | _, det2, err := program.Eval(input) |
| 2105 | if err != nil { |
| 2106 | t.Fatalf("second Eval() failed: %v", err) |
| 2107 | } |
| 2108 | cost2 := det2.ActualCost() |
| 2109 | if cost2 == nil { |
| 2110 | t.Fatal("second Eval() returned nil ActualCost") |
| 2111 | } |
| 2112 | |
| 2113 | if *cost1 != *cost2 { |
| 2114 | t.Errorf("ActualCost mismatch across evaluations: first=%d, second=%d", *cost1, *cost2) |
| 2115 | } |
| 2116 | } |
| 2117 | |
| 2118 | func TestPartialVars(t *testing.T) { |
| 2119 | env := testEnv(t, |
nothing calls this directly
no test coverage detected