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

Function TestMath

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

Source from the content-addressed store, hash-verified

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