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

Function TestTrackCostAdvanced

interpreter/runtimecost_test.go:38–110  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

36)
37
38func TestTrackCostAdvanced(t *testing.T) {
39 var equalCases = []struct {
40 in any
41 lhsExpr string
42 rhsExpr string
43 }{
44 {
45 lhsExpr: `1`,
46 rhsExpr: `2`,
47 },
48 {
49 lhsExpr: `"abc".contains("d")`,
50 rhsExpr: `"def".contains("d")`,
51 },
52 {
53 lhsExpr: `1 in [4, 5, 6]`,
54 rhsExpr: `2 in [15, 17, 16]`,
55 },
56 }
57 for _, tc := range equalCases {
58 t.Run(tc.lhsExpr+" vs "+tc.rhsExpr, func(t *testing.T) {
59 ctx := constructActivation(t, tc.in)
60 lhsCost, _, err := computeCost(t, tc.lhsExpr, nil, ctx, nil)
61 if err != nil {
62 t.Fatalf("Interpreter.Eval(activation Activation) failed to eval expression due: %v", err)
63 }
64 rhsCost, _, err := computeCost(t, tc.rhsExpr, nil, ctx, nil)
65 if err != nil {
66 t.Fatalf("Interpreter.Eval(activation Activation) failed to eval expression due: %v", err)
67 }
68 if lhsCost != rhsCost {
69 t.Errorf(`Interpreter.Eval(activation Activation) failed return a cost for %s of %d equal to a cost for %s of %d`,
70 tc.lhsExpr, lhsCost, tc.rhsExpr, rhsCost)
71 }
72 })
73
74 }
75 var smallerCases = []struct {
76 in any
77 lhsExpr string
78 rhsExpr string
79 }{
80 {
81 lhsExpr: `1`,
82 rhsExpr: `1 + 2`,
83 },
84 {
85 lhsExpr: `"abc".contains("d")`,
86 rhsExpr: `"abcdhdflsfiehfieubdkwjbdwgxvuyagwsdwdnw qdbgquyidvbwqi".contains("e")`,
87 },
88 {
89 lhsExpr: `1 in [4, 5, 6]`,
90 rhsExpr: `1 in [4, 5, 6, 7, 8, 9]`,
91 },
92 }
93 for _, tc := range smallerCases {
94 t.Run(tc.lhsExpr+" vs "+tc.rhsExpr, func(t *testing.T) {
95 ctx := constructActivation(t, tc.in)

Callers

nothing calls this directly

Calls 2

constructActivationFunction · 0.85
computeCostFunction · 0.85

Tested by

no test coverage detected