MCPcopy Create free account
hub / github.com/cel-expr/cel-go / TestCostTrackingConsistentAcrossEvals

Function TestCostTrackingConsistentAcrossEvals

cel/cel_test.go:2267–2307  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2265}
2266
2267func 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
2309func TestPartialVars(t *testing.T) {
2310 env := testEnv(t,

Callers

nothing calls this directly

Calls 9

CostTrackingFunction · 0.85
ErrMethod · 0.80
CheckMethod · 0.80
ProgramMethod · 0.80
testEnvFunction · 0.70
VariableFunction · 0.70
CompileMethod · 0.65
EvalMethod · 0.65
ActualCostMethod · 0.45

Tested by

no test coverage detected