| 70 | } |
| 71 | |
| 72 | func TestOptimize_count_threshold_lte(t *testing.T) { |
| 73 | tree, err := parser.Parse(`count(items, .active) <= 50`) |
| 74 | require.NoError(t, err) |
| 75 | |
| 76 | err = optimizer.Optimize(&tree.Node, nil) |
| 77 | require.NoError(t, err) |
| 78 | |
| 79 | // Operator should remain <=, but count should have threshold set |
| 80 | binary, ok := tree.Node.(*BinaryNode) |
| 81 | require.True(t, ok, "expected BinaryNode, got %T", tree.Node) |
| 82 | assert.Equal(t, "<=", binary.Operator) |
| 83 | |
| 84 | count, ok := binary.Left.(*BuiltinNode) |
| 85 | require.True(t, ok, "expected BuiltinNode, got %T", binary.Left) |
| 86 | assert.Equal(t, "count", count.Name) |
| 87 | require.NotNil(t, count.Threshold) |
| 88 | assert.Equal(t, 51, *count.Threshold) // threshold = N + 1 for <= operator |
| 89 | } |
| 90 | |
| 91 | func TestOptimize_count_threshold_correctness(t *testing.T) { |
| 92 | tests := []struct { |