MCPcopy Create free account
hub / github.com/expr-lang/expr / TestOptimize_sum_range_reversed

Function TestOptimize_sum_range_reversed

optimizer/sum_range_test.go:203–225  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

201}
202
203func TestOptimize_sum_range_reversed(t *testing.T) {
204 // When n < m (e.g., 10..1), the range is empty and sum should return 0.
205 // The optimization should NOT apply (n >= m check), so runtime handles it.
206 tests := []struct {
207 expr string
208 want int
209 }{
210 {`sum(10..1)`, 0},
211 {`sum(5..3)`, 0},
212 {`sum(100..1)`, 0},
213 }
214
215 for _, tt := range tests {
216 t.Run(tt.expr, func(t *testing.T) {
217 program, err := expr.Compile(tt.expr)
218 require.NoError(t, err)
219
220 output, err := expr.Run(program, nil)
221 require.NoError(t, err)
222 assert.Equal(t, tt.want, output)
223 })
224 }
225}
226
227func TestOptimize_sum_range_reversed_not_optimized(t *testing.T) {
228 // Verify that reversed ranges are NOT optimized (left as BuiltinNode)

Callers

nothing calls this directly

Calls 5

CompileFunction · 0.92
NoErrorFunction · 0.92
RunFunction · 0.92
EqualFunction · 0.92
RunMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…