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

Function TestCostTracker_BasicOperations

common/cost/tracker_test.go:42–104  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

40}
41
42func TestCostTracker_BasicOperations(t *testing.T) {
43 tracker, err := cost.NewTracker(nil,
44 cost.TrackerPresenceTestHasCost(true),
45 )
46 if err != nil {
47 t.Fatalf("NewTracker() failed: %v", err)
48 }
49
50 tests := []struct {
51 name string
52 action func()
53 wantCost uint64
54 }{
55 {
56 name: "create_list",
57 action: func() {
58 tracker.CreateList(1, nil)
59 },
60 wantCost: cost.ListCreateBaseCost,
61 },
62 {
63 name: "create_map",
64 action: func() {
65 tracker.CreateMap(2, nil)
66 },
67 wantCost: cost.ListCreateBaseCost + cost.MapCreateBaseCost,
68 },
69 {
70 name: "create_struct",
71 action: func() {
72 tracker.CreateStruct(3, nil)
73 },
74 wantCost: cost.ListCreateBaseCost + cost.MapCreateBaseCost + cost.StructCreateBaseCost,
75 },
76 {
77 name: "eval_attribute",
78 action: func() {
79 tracker.EvalAttribute(4, false, nil)
80 },
81 wantCost: cost.ListCreateBaseCost + cost.MapCreateBaseCost + cost.StructCreateBaseCost + cost.SelectAndIdentCost,
82 },
83 {
84 name: "qualify",
85 action: func() {
86 tracker.Qualify(5)
87 },
88 wantCost: cost.ListCreateBaseCost + cost.MapCreateBaseCost + cost.StructCreateBaseCost + cost.SelectAndIdentCost + 1,
89 },
90 }
91
92 for _, tc := range tests {
93 t.Run(tc.name, func(t *testing.T) {
94 tc.action()
95 if tracker.ActualCost() != tc.wantCost {
96 t.Errorf("ActualCost() = %d, want %d", tracker.ActualCost(), tc.wantCost)
97 }
98 })
99 }

Callers

nothing calls this directly

Calls 9

CreateListMethod · 0.95
CreateMapMethod · 0.95
CreateStructMethod · 0.95
EvalAttributeMethod · 0.95
QualifyMethod · 0.95
ActualCostMethod · 0.95
PresenceTestHasCostMethod · 0.95
NewTrackerFunction · 0.92

Tested by

no test coverage detected