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

Function TestCostTrackingConsistentAcrossEvals

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

Source from the content-addressed store, hash-verified

1970}
1971
1972func TestCostTrackingConsistentAcrossEvals(t *testing.T) {
1973 env := testEnv(t,
1974 Variable("val1", IntType),
1975 Variable("val2", IntType),
1976 )
1977 ast, iss := env.Compile(`val1 + val2`)
1978 if iss.Err() != nil {
1979 t.Fatalf("env.Compile() failed: %v", iss.Err())
1980 }
1981 checkedAst, iss := env.Check(ast)
1982 if iss.Err() != nil {
1983 t.Fatalf("env.Check() failed: %v", iss.Err())
1984 }
1985 program, err := env.Program(checkedAst, CostTracking(nil))
1986 if err != nil {
1987 t.Fatalf("env.Program() failed: %v", err)
1988 }
1989 input := map[string]any{"val1": 1, "val2": 2}
1990
1991 _, det1, err := program.Eval(input)
1992 if err != nil {
1993 t.Fatalf("first Eval() failed: %v", err)
1994 }
1995 cost1 := det1.ActualCost()
1996 if cost1 == nil {
1997 t.Fatal("first Eval() returned nil ActualCost")
1998 }
1999
2000 _, det2, err := program.Eval(input)
2001 if err != nil {
2002 t.Fatalf("second Eval() failed: %v", err)
2003 }
2004 cost2 := det2.ActualCost()
2005 if cost2 == nil {
2006 t.Fatal("second Eval() returned nil ActualCost")
2007 }
2008
2009 if *cost1 != *cost2 {
2010 t.Errorf("ActualCost mismatch across evaluations: first=%d, second=%d", *cost1, *cost2)
2011 }
2012}
2013
2014func TestPartialVars(t *testing.T) {
2015 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