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

Function TestOverloadModelValidate

common/cost/validate_test.go:28–240  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

26var unanswerable = ElemOf(Const(4))
27
28func TestOverloadModelValidate(t *testing.T) {
29 tests := []struct {
30 name string
31 model OverloadModel
32 err string
33 }{
34 {
35 name: "valid_cost_only",
36 model: Overload("test_id", EvalCost(Const(1))),
37 },
38 {
39 name: "valid_projections_over_values",
40 model: MemberOverload("test_id",
41 EvalCost(Sum(TargetElem(), ArgKey(0), ElemTotal(Result()))),
42 ResultSize(List(Target(), TargetElem())),
43 ),
44 },
45 {
46 name: "valid_nested_projection",
47 model: Overload("test_id",
48 EvalCost(ElemOf(ElemOf(Arg(0)))),
49 ),
50 },
51 {
52 name: "missing_id",
53 model: Overload("", EvalCost(Const(1))),
54 err: "requires an ID",
55 },
56 {
57 name: "missing_cost",
58 model: Overload("test_id", ResultSize(Arg(0))),
59 err: `overload "test_id" requires an EvalCost expression`,
60 },
61 {
62 name: "projection_over_constant",
63 model: Overload("test_id", EvalCost(unanswerable)),
64 err: `overload "test_id" eval cost: ElemOf is not defined over Const`,
65 },
66 {
67 name: "projection_over_sum",
68 model: Overload("test_id", EvalCost(KeyOf(Sum(Arg(0), Arg(1))))),
69 err: "KeyOf is not defined over Sum",
70 },
71 {
72 name: "total_over_scale",
73 model: Overload("test_id", EvalCost(ElemTotal(Scale(Arg(0), 2.0)))),
74 err: "ElemTotal is not defined over Scale",
75 },
76 {
77 name: "length_over_projection",
78 model: Overload("test_id", EvalCost(Length(ArgElem(0)))),
79 err: "Length is not defined over ElemOf",
80 },
81 {
82 name: "total_over_projection",
83 model: Overload("test_id", EvalCost(KeyTotal(ArgElem(0)))),
84 err: "KeyTotal is not defined over ElemOf: it applies to Arg, Target and Result",
85 },

Callers

nothing calls this directly

Calls 15

EvalCostFunction · 0.85
ConstFunction · 0.85
SumFunction · 0.85
TargetElemFunction · 0.85
ArgKeyFunction · 0.85
ElemTotalFunction · 0.85
ResultFunction · 0.85
ResultSizeFunction · 0.85
ListFunction · 0.85
TargetFunction · 0.85
ElemOfFunction · 0.85
ArgFunction · 0.85

Tested by

no test coverage detected