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

Function TestMath

ext/math_test.go:27–235  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func TestMath(t *testing.T) {
28 mathTests := []struct {
29 expr string
30 in any
31 }{
32 // Tests for math.least
33 {expr: "math.least(-0.5) == -0.5"},
34 {expr: "math.least(-1) == -1"},
35 {expr: "math.least(1u) == 1u"},
36 {expr: "math.least(42.0, -0.5) == -0.5"},
37 {expr: "math.least(-1, 0) == -1"},
38 {expr: "math.least(-1, -1) == -1"},
39 {expr: "math.least(1u, 42u) == 1u"},
40 {expr: "math.least(42.0, -0.5, -0.25) == -0.5"},
41 {expr: "math.least(-1, 0, 1) == -1"},
42 {expr: "math.least(-1, -1, -1) == -1"},
43 {expr: "math.least(1u, 42u, 0u) == 0u"},
44 // math.least two arg overloads across type.
45 {expr: "math.least(1, 1.0) == 1"},
46 {expr: "math.least(1, -2.0) == -2.0"},
47 {expr: "math.least(2, 1u) == 1u"},
48 {expr: "math.least(1.5, 2) == 1.5"},
49 {expr: "math.least(1.5, -2) == -2"},
50 {expr: "math.least(2.5, 1u) == 1u"},
51 {expr: "math.least(1u, 2) == 1u"},
52 {expr: "math.least(1u, -2) == -2"},
53 {expr: "math.least(2u, 2.5) == 2u"},
54 // math.least with dynamic values across type.
55 {expr: "math.least(1u, dyn(42)) == 1"},
56 {expr: "math.least(1u, dyn(42), dyn(0.0)) == 0u"},
57 // math.least with a list literal.
58 {expr: "math.least([1u, 42u, 0u]) == 0u"},
59 // math.least with expression arguments.
60 {
61 expr: "math.least(a, b) == a",
62 in: map[string]any{
63 "a": 1,
64 "b": 2,
65 },
66 },
67 {
68 expr: "math.least(numbers) == dyn(a)",
69 in: map[string]any{
70 "a": -21,
71 "numbers": []float64{-21.0, -10.5, 1.0},
72 },
73 },
74
75 // Tests for math.greatest
76 {expr: "math.greatest(-0.5) == -0.5"},
77 {expr: "math.greatest(-1) == -1"},
78 {expr: "math.greatest(1u) == 1u"},
79 {expr: "math.greatest(42.0, -0.5) == 42.0"},
80 {expr: "math.greatest(-1, 0) == 0"},
81 {expr: "math.greatest(-1, -1) == -1"},
82 {expr: "math.greatest(1u, 42u) == 42u"},
83 {expr: "math.greatest(42.0, -0.5, -0.25) == 42.0"},
84 {expr: "math.greatest(-1, 0, 1) == 1"},

Callers

nothing calls this directly

Calls 9

VariableFunction · 0.92
NoVarsFunction · 0.92
testMathEnvFunction · 0.85
ErrMethod · 0.80
CheckMethod · 0.80
ProgramMethod · 0.80
ParseMethod · 0.65
EvalMethod · 0.65
ValueMethod · 0.65

Tested by

no test coverage detected