1#include "catch.hpp"
2#include "duckdb/common/file_system.hpp"
3#include "dbgen.hpp"
4#include "test_helpers.hpp"
5
6using namespace duckdb;
7using namespace std;
8
9TEST_CASE("Test simple round usage", "[round]") {
10 unique_ptr<QueryResult> result;
11 DuckDB db(nullptr);
12 Connection con(db);
13 con.EnableQueryVerification();
14
15 REQUIRE_NO_FAIL(con.Query("create table test (col1 double);"));
16 REQUIRE_NO_FAIL(con.Query("insert into test values (2.887);"));
17
18 result = con.Query("select round(col1, -1) from test;");
19 REQUIRE(CHECK_COLUMN(result, 0, {3.0}));
20 result = con.Query("select round(col1, 0) from test;");
21 REQUIRE(CHECK_COLUMN(result, 0, {3.0}));
22 result = con.Query("select round(col1, 1) from test;");
23 REQUIRE(CHECK_COLUMN(result, 0, {2.9}));
24 result = con.Query("select round(col1, 2) from test;");
25 REQUIRE(CHECK_COLUMN(result, 0, {2.89}));
26 result = con.Query("select round(col1, 3) from test;");
27 REQUIRE(CHECK_COLUMN(result, 0, {2.887}));
28 result = con.Query("select round(col1, 4) from test;");
29 REQUIRE(CHECK_COLUMN(result, 0, {2.887}));
30}
31
32TEST_CASE("MonetDB Test: round.Bug-3542.sql", "[monetdb]") {
33 unique_ptr<QueryResult> result;
34 DuckDB db(nullptr);
35 Connection con(db);
36 con.EnableQueryVerification();
37 return;
38
39 REQUIRE_NO_FAIL(con.Query("CREATE TABLE test_num_data (id integer, val numeric(18,10));"));
40 REQUIRE_NO_FAIL(con.Query("INSERT INTO test_num_data VALUES (1, '-0.0');"));
41 REQUIRE_NO_FAIL(con.Query("INSERT INTO test_num_data VALUES (2, '-34338492.215397047');"));
42
43 result = con.Query("SELECT * FROM test_num_data ORDER BY id");
44 REQUIRE(CHECK_COLUMN(result, 0, {1, 2}));
45 REQUIRE(CHECK_COLUMN(result, 1, {0, -34338492.2153970470}));
46
47 result = con.Query("SELECT t1.id, t2.id, t1.val * t2.val FROM test_num_data t1, test_num_data t2 ORDER BY 1, 2;");
48 REQUIRE(CHECK_COLUMN(result, 0, {1, 1, 2, 2}));
49 REQUIRE(CHECK_COLUMN(result, 1, {1, 2, 1, 2}));
50 REQUIRE(CHECK_COLUMN(result, 2, {0, 0, 0, 0, 1179132047626883.59686213585632020900}));
51
52 result = con.Query(
53 "SELECT t1.id, t2.id, round(t1.val * t2.val, 30) FROM test_num_data t1, test_num_data t2 ORDER BY 1, 2;");
54 REQUIRE(CHECK_COLUMN(result, 0, {1, 1, 2, 2}));
55 REQUIRE(CHECK_COLUMN(result, 1, {1, 2, 1, 2}));
56 REQUIRE(CHECK_COLUMN(result, 2, {0, 0, 0, 0, 1179132047626883.596862135856320209000000000000}));
57}
58