| 1 | #include "catch.hpp" | 
|---|
| 2 | #include "test_helpers.hpp" | 
|---|
| 3 |  | 
|---|
| 4 | using namespace duckdb; | 
|---|
| 5 | using namespace std; | 
|---|
| 6 |  | 
|---|
| 7 | TEST_CASE( "Test trigonometric function", "[function]") { | 
|---|
| 8 | unique_ptr<QueryResult> result; | 
|---|
| 9 | DuckDB db(nullptr); | 
|---|
| 10 | Connection con(db); | 
|---|
| 11 | con.EnableQueryVerification(); | 
|---|
| 12 | REQUIRE_NO_FAIL(con.Query( "CREATE TABLE numbers(n DOUBLE)")); | 
|---|
| 13 | REQUIRE_NO_FAIL(con.Query( "INSERT INTO numbers VALUES (-42),(-1),(0), (1), (42), (NULL)")); | 
|---|
| 14 |  | 
|---|
| 15 | result = con.Query( "SELECT cast(SIN(n::tinyint)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 16 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), 916, -841, 0, 841, -916})); | 
|---|
| 17 | result = con.Query( "SELECT cast(SIN(n::smallint)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 18 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), 916, -841, 0, 841, -916})); | 
|---|
| 19 | result = con.Query( "SELECT cast(SIN(n::integer)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 20 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), 916, -841, 0, 841, -916})); | 
|---|
| 21 | result = con.Query( "SELECT cast(SIN(n::bigint)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 22 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), 916, -841, 0, 841, -916})); | 
|---|
| 23 | result = con.Query( "SELECT cast(SIN(n::float)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 24 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), 916, -841, 0, 841, -916})); | 
|---|
| 25 | result = con.Query( "SELECT cast(SIN(n::double)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 26 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), 916, -841, 0, 841, -916})); | 
|---|
| 27 |  | 
|---|
| 28 | result = con.Query( "SELECT cast(COS(n::tinyint)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 29 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -399, 540, 1000, 540, -399})); | 
|---|
| 30 | result = con.Query( "SELECT cast(COS(n::smallint)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 31 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -399, 540, 1000, 540, -399})); | 
|---|
| 32 | result = con.Query( "SELECT cast(COS(n::integer)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 33 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -399, 540, 1000, 540, -399})); | 
|---|
| 34 | result = con.Query( "SELECT cast(COS(n::bigint)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 35 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -399, 540, 1000, 540, -399})); | 
|---|
| 36 | result = con.Query( "SELECT cast(COS(n::float)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 37 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -399, 540, 1000, 540, -399})); | 
|---|
| 38 | result = con.Query( "SELECT cast(COS(n::double)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 39 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -399, 540, 1000, 540, -399})); | 
|---|
| 40 |  | 
|---|
| 41 | result = con.Query( "SELECT cast(TAN(n::tinyint)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 42 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -2291, -1557, 0, 1557, 2291})); | 
|---|
| 43 | result = con.Query( "SELECT cast(TAN(n::smallint)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 44 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -2291, -1557, 0, 1557, 2291})); | 
|---|
| 45 | result = con.Query( "SELECT cast(TAN(n::integer)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 46 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -2291, -1557, 0, 1557, 2291})); | 
|---|
| 47 | result = con.Query( "SELECT cast(TAN(n::bigint)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 48 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -2291, -1557, 0, 1557, 2291})); | 
|---|
| 49 | result = con.Query( "SELECT cast(TAN(n::float)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 50 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -2291, -1557, 0, 1557, 2291})); | 
|---|
| 51 | result = con.Query( "SELECT cast(TAN(n::double)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 52 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -2291, -1557, 0, 1557, 2291})); | 
|---|
| 53 |  | 
|---|
| 54 | result = con.Query( "SELECT cast(ATAN(n::tinyint)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 55 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -1546, -785, 0, 785, 1546})); | 
|---|
| 56 | result = con.Query( "SELECT cast(ATAN(n::smallint)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 57 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -1546, -785, 0, 785, 1546})); | 
|---|
| 58 | result = con.Query( "SELECT cast(ATAN(n::integer)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 59 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -1546, -785, 0, 785, 1546})); | 
|---|
| 60 | result = con.Query( "SELECT cast(ATAN(n::bigint)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 61 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -1546, -785, 0, 785, 1546})); | 
|---|
| 62 | result = con.Query( "SELECT cast(ATAN(n::float)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 63 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -1546, -785, 0, 785, 1546})); | 
|---|
| 64 | result = con.Query( "SELECT cast(ATAN(n::double)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 65 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -1546, -785, 0, 785, 1546})); | 
|---|
| 66 |  | 
|---|
| 67 | result = | 
|---|
| 68 | con.Query( "SELECT cast(ASIN(n::tinyint)*1000 as bigint) FROM numbers  WHERE n between -1 and 1 ORDER BY n"); | 
|---|
| 69 | REQUIRE(CHECK_COLUMN(result, 0, {-1570, 0, 1570})); | 
|---|
| 70 | result = | 
|---|
| 71 | con.Query( "SELECT cast(ASIN(n::smallint)*1000 as bigint) FROM numbers  WHERE n between -1 and 1 ORDER BY n"); | 
|---|
| 72 | REQUIRE(CHECK_COLUMN(result, 0, {-1570, 0, 1570})); | 
|---|
| 73 | result = | 
|---|
| 74 | con.Query( "SELECT cast(ASIN(n::integer)*1000 as bigint) FROM numbers  WHERE n between -1 and 1 ORDER BY n"); | 
|---|
| 75 | REQUIRE(CHECK_COLUMN(result, 0, {-1570, 0, 1570})); | 
|---|
| 76 | result = con.Query( "SELECT cast(ASIN(n::bigint)*1000 as bigint) FROM numbers  WHERE n between -1 and 1 ORDER BY n"); | 
|---|
| 77 | REQUIRE(CHECK_COLUMN(result, 0, {-1570, 0, 1570})); | 
|---|
| 78 | result = con.Query( "SELECT cast(ASIN(n::float)*1000 as bigint) FROM numbers  WHERE n between -1 and 1 ORDER BY n"); | 
|---|
| 79 | REQUIRE(CHECK_COLUMN(result, 0, {-1570, 0, 1570})); | 
|---|
| 80 | result = con.Query( "SELECT cast(ASIN(n::double)*1000 as bigint) FROM numbers  WHERE n between -1 and 1 ORDER BY n"); | 
|---|
| 81 | REQUIRE(CHECK_COLUMN(result, 0, {-1570, 0, 1570})); | 
|---|
| 82 |  | 
|---|
| 83 | result = | 
|---|
| 84 | con.Query( "SELECT cast(ACOS(n::tinyint)*1000 as bigint) FROM numbers  WHERE n between -1 and 1 ORDER BY n"); | 
|---|
| 85 | REQUIRE(CHECK_COLUMN(result, 0, {3141, 1570, 0})); | 
|---|
| 86 | result = | 
|---|
| 87 | con.Query( "SELECT cast(ACOS(n::smallint)*1000 as bigint) FROM numbers  WHERE n between -1 and 1 ORDER BY n"); | 
|---|
| 88 | REQUIRE(CHECK_COLUMN(result, 0, {3141, 1570, 0})); | 
|---|
| 89 | result = | 
|---|
| 90 | con.Query( "SELECT cast(ACOS(n::integer)*1000 as bigint) FROM numbers  WHERE n between -1 and 1 ORDER BY n"); | 
|---|
| 91 | REQUIRE(CHECK_COLUMN(result, 0, {3141, 1570, 0})); | 
|---|
| 92 | result = con.Query( "SELECT cast(ACOS(n::bigint)*1000 as bigint) FROM numbers  WHERE n between -1 and 1 ORDER BY n"); | 
|---|
| 93 | REQUIRE(CHECK_COLUMN(result, 0, {3141, 1570, 0})); | 
|---|
| 94 | result = con.Query( "SELECT cast(ACOS(n::float)*1000 as bigint) FROM numbers  WHERE n between -1 and 1 ORDER BY n"); | 
|---|
| 95 | REQUIRE(CHECK_COLUMN(result, 0, {3141, 1570, 0})); | 
|---|
| 96 | result = con.Query( "SELECT cast(ACOS(n::double)*1000 as bigint) FROM numbers  WHERE n between -1 and 1 ORDER BY n"); | 
|---|
| 97 | REQUIRE(CHECK_COLUMN(result, 0, {3141, 1570, 0})); | 
|---|
| 98 |  | 
|---|
| 99 | REQUIRE_FAIL(con.Query( "SELECT cast(ASIN(n)*1000 as bigint) FROM numbers ORDER BY n")); | 
|---|
| 100 | // REQUIRE_FAIL(con.Query("SELECT cast(ACOS(n)*1000 as bigint) FROM numbers ORDER BY n")); | 
|---|
| 101 |  | 
|---|
| 102 | result = | 
|---|
| 103 | con.Query( "SELECT cast(COT(n::tinyint)*1000 as bigint) FROM numbers  WHERE n > 0.1 OR N < -0.1 ORDER BY n"); | 
|---|
| 104 | REQUIRE(CHECK_COLUMN(result, 0, {-436, -642, 642, 436})); | 
|---|
| 105 | result = | 
|---|
| 106 | con.Query( "SELECT cast(COT(n::smallint)*1000 as bigint) FROM numbers  WHERE n > 0.1 OR N < -0.1 ORDER BY n"); | 
|---|
| 107 | REQUIRE(CHECK_COLUMN(result, 0, {-436, -642, 642, 436})); | 
|---|
| 108 | result = | 
|---|
| 109 | con.Query( "SELECT cast(COT(n::integer)*1000 as bigint) FROM numbers  WHERE n > 0.1 OR N < -0.1 ORDER BY n"); | 
|---|
| 110 | REQUIRE(CHECK_COLUMN(result, 0, {-436, -642, 642, 436})); | 
|---|
| 111 | result = con.Query( "SELECT cast(COT(n::bigint)*1000 as bigint) FROM numbers  WHERE n > 0.1 OR N < -0.1 ORDER BY n"); | 
|---|
| 112 | REQUIRE(CHECK_COLUMN(result, 0, {-436, -642, 642, 436})); | 
|---|
| 113 | result = con.Query( "SELECT cast(COT(n::float)*1000 as bigint) FROM numbers  WHERE n > 0.1 OR N < -0.1 ORDER BY n"); | 
|---|
| 114 | REQUIRE(CHECK_COLUMN(result, 0, {-436, -642, 642, 436})); | 
|---|
| 115 | result = con.Query( "SELECT cast(COT(n::double)*1000 as bigint) FROM numbers  WHERE n > 0.1 OR N < -0.1 ORDER BY n"); | 
|---|
| 116 | REQUIRE(CHECK_COLUMN(result, 0, {-436, -642, 642, 436})); | 
|---|
| 117 |  | 
|---|
| 118 | result = con.Query( "SELECT cast(ATAN2(n::tinyint, 42)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 119 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -785, -23, 0, 23, 785})); | 
|---|
| 120 | result = con.Query( "SELECT cast(ATAN2(n::smallint, 42)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 121 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -785, -23, 0, 23, 785})); | 
|---|
| 122 | result = con.Query( "SELECT cast(ATAN2(n::integer, 42)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 123 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -785, -23, 0, 23, 785})); | 
|---|
| 124 | result = con.Query( "SELECT cast(ATAN2(n::bigint, 42)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 125 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -785, -23, 0, 23, 785})); | 
|---|
| 126 | result = con.Query( "SELECT cast(ATAN2(n::float, 42)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 127 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -785, -23, 0, 23, 785})); | 
|---|
| 128 | result = con.Query( "SELECT cast(ATAN2(n::double, 42)*1000 as bigint) FROM numbers ORDER BY n"); | 
|---|
| 129 | REQUIRE(CHECK_COLUMN(result, 0, {Value(), -785, -23, 0, 23, 785})); | 
|---|
| 130 | } | 
|---|
| 131 |  | 
|---|