Commit 9d402c73 authored by Peter Eisentraut's avatar Peter Eisentraut

Expand tests for factorial

Move from int4 to numeric test.  (They were originally int4 functions,
but were reimplemented for numeric in
04a4821a.)  Add some tests for edge
cases.

Discussion: https://www.postgresql.org/message-id/flat/6ce1df0e-86a3-e544-743a-f357ff663f68%402ndquadrant.com
parent 2b2a070d
......@@ -299,18 +299,6 @@ SELECT int4 '1000' < int4 '999' AS false;
f
(1 row)
SELECT 4! AS twenty_four;
twenty_four
-------------
24
(1 row)
SELECT !!3 AS six;
six
-----
6
(1 row)
SELECT 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 AS ten;
ten
-----
......
......@@ -2315,3 +2315,44 @@ FROM (VALUES (0::numeric, 0::numeric),
SELECT lcm(9999 * (10::numeric)^131068 + (10::numeric^131068 - 1), 2); -- overflow
ERROR: value overflows numeric format
--
-- Tests for factorial
--
SELECT 4!;
?column?
----------
24
(1 row)
SELECT !!3;
?column?
----------
6
(1 row)
SELECT factorial(15);
factorial
---------------
1307674368000
(1 row)
SELECT 100000!;
ERROR: value overflows numeric format
SELECT 0!;
?column?
----------
1
(1 row)
SELECT -4!;
?column?
----------
1
(1 row)
SELECT factorial(-4);
factorial
-----------
1
(1 row)
......@@ -114,10 +114,6 @@ SELECT int2 '2' * int4 '2' = int4 '16' / int2 '4' AS true;
SELECT int4 '1000' < int4 '999' AS false;
SELECT 4! AS twenty_four;
SELECT !!3 AS six;
SELECT 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 AS ten;
SELECT 2 + 2 / 2 AS three;
......
......@@ -1111,3 +1111,14 @@ FROM (VALUES (0::numeric, 0::numeric),
(4232.820::numeric, 132.72000::numeric)) AS v(a, b);
SELECT lcm(9999 * (10::numeric)^131068 + (10::numeric^131068 - 1), 2); -- overflow
--
-- Tests for factorial
--
SELECT 4!;
SELECT !!3;
SELECT factorial(15);
SELECT 100000!;
SELECT 0!;
SELECT -4!;
SELECT factorial(-4);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment