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

Function TestCostSizingStrategy

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

Source from the content-addressed store, hash-verified

5702}
5703
5704func TestCostSizingStrategy(t *testing.T) {
5705 env, err := NewEnv(
5706 CostSizingStrategy(cost.AggregateSizingStrategy()),
5707 Variable("str", StringType),
5708 )
5709 if err != nil {
5710 t.Fatalf("NewEnv failed: %v", err)
5711 }
5712 ast, iss := env.Compile(`str.startsWith("prefix")`)
5713 if iss.Err() != nil {
5714 t.Fatalf("Compile failed: %v", iss.Err())
5715 }
5716 prg, err := env.Program(ast, CostTracking(nil))
5717 if err != nil {
5718 t.Fatalf("Program failed: %v", err)
5719 }
5720 evalDetails := &EvalDetails{}
5721 res, valDetails, err := prg.Eval(map[string]any{
5722 "str": "prefix_hello_world",
5723 })
5724 if err != nil {
5725 t.Fatalf("Eval failed: %v", err)
5726 }
5727 if res != types.True {
5728 t.Errorf("got %v, want true", res)
5729 }
5730 evalDetails = valDetails
5731 actualCost := *evalDetails.ActualCost()
5732 if actualCost == 0 {
5733 t.Errorf("expected non-zero actual cost, got %d", actualCost)
5734 }
5735}
5736
5737func TestCostModel(t *testing.T) {
5738 model1 := cost.MemberOverload(overloads.StartsWithString,

Callers

nothing calls this directly

Calls 10

CompileMethod · 0.95
ProgramMethod · 0.95
ActualCostMethod · 0.95
AggregateSizingStrategyFunction · 0.92
CostSizingStrategyFunction · 0.85
CostTrackingFunction · 0.85
ErrMethod · 0.80
NewEnvFunction · 0.70
VariableFunction · 0.70
EvalMethod · 0.65

Tested by

no test coverage detected