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

Function TestTwoVarComprehensionsCost

ext/comprehensions_test.go:218–394  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

216}
217
218func TestTwoVarComprehensionsCost(t *testing.T) {
219 tests := []struct {
220 name string
221 expr string
222 vars []cel.EnvOption
223 in map[string]any
224 hints map[string]uint64
225 estimatedCost checker.CostEstimate
226 actualCost uint64
227 }{
228 {
229 name: "all list literal",
230 expr: `[1, 2, 3, 4].all(i, v, i < 5 && v > 0)`,
231 estimatedCost: checker.CostEstimate{Min: 23, Max: 39},
232 actualCost: 39,
233 },
234 {
235 name: "all map literal - true",
236 expr: `{1: 1, 2: 2, 3: 3}.all(i, v, i < 5 && v > 0)`,
237 estimatedCost: checker.CostEstimate{Min: 40, Max: 52},
238 actualCost: 52,
239 },
240 {
241 name: "all map literal - false",
242 expr: `!{0: 0}.all(i, v, i < 5 && v > 0)`,
243 estimatedCost: checker.CostEstimate{Min: 35, Max: 39},
244 actualCost: 39,
245 },
246 {
247 name: "all map(int,int) variable",
248 expr: `m.all(i, v, i < 5 && v > 0)`,
249 vars: []cel.EnvOption{cel.Variable("m", cel.MapType(cel.IntType, cel.IntType))},
250 hints: map[string]uint64{
251 "m": 3,
252 },
253 in: map[string]any{
254 "m": map[int]int{1: 1, 2: 2},
255 },
256 estimatedCost: checker.CostEstimate{Min: 2, Max: 23},
257 actualCost: 16,
258 },
259 {
260 name: "all map(string,string) variable",
261 expr: `m.all(k, v, k < v)`,
262 vars: []cel.EnvOption{cel.Variable("m", cel.MapType(cel.StringType, cel.StringType))},
263 hints: map[string]uint64{
264 "m": 3,
265 "m.@keys": 16,
266 "m.@values": 128,
267 },
268 in: map[string]any{
269 "m": map[string]string{"he": "hello", "go": "goodbye"},
270 },
271 estimatedCost: checker.CostEstimate{Min: 2, Max: 23},
272 actualCost: 14,
273 },
274 {
275 name: "transformList empty",

Callers

nothing calls this directly

Calls 8

VariableFunction · 0.92
FixedCostEstimateFunction · 0.92
testCompreEnvFunction · 0.85
testCheckCostFunction · 0.85
testEvalWithCostFunction · 0.85
ErrMethod · 0.80
CheckMethod · 0.80
ParseMethod · 0.65

Tested by

no test coverage detected