1#include "catch.hpp"
2#include "duckdb/common/helper.hpp"
3#include "expression_helper.hpp"
4#include "duckdb/optimizer/rule/arithmetic_simplification.hpp"
5
6using namespace duckdb;
7using namespace std;
8
9TEST_CASE("Arithmetic simplification test", "[optimizer]") {
10 ExpressionHelper helper;
11
12 REQUIRE(helper.AddColumns("X INTEGER").empty());
13
14 helper.AddRule<ArithmeticSimplificationRule>();
15
16 string input, expected_output;
17
18 input = "X+0";
19 expected_output = "X";
20 REQUIRE(helper.VerifyRewrite(input, expected_output));
21
22 input = "0+X";
23 expected_output = "X";
24 REQUIRE(helper.VerifyRewrite(input, expected_output));
25
26 input = "X-0";
27 expected_output = "X";
28 REQUIRE(helper.VerifyRewrite(input, expected_output));
29
30 input = "X*1";
31 expected_output = "X";
32 REQUIRE(helper.VerifyRewrite(input, expected_output));
33
34 input = "X/0";
35 expected_output = "NULL";
36 REQUIRE(helper.VerifyRewrite(input, expected_output));
37
38 input = "X/1";
39 expected_output = "X";
40 REQUIRE(helper.VerifyRewrite(input, expected_output));
41}
42