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

Function TestCostTrackingConsistentAcrossEvals

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

Source from the content-addressed store, hash-verified

2074}
2075
2076func 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
2118func TestPartialVars(t *testing.T) {
2119 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