Expand tests for factorial

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

Discussion: https://www.postgresql.org/message-id/flat/6ce1df0e-86a3-e544-743a-f357ff663f68%402ndquadrant.com
This commit is contained in:
Peter Eisentraut 2020-06-18 08:41:31 +02:00
parent 2b2a070d98
commit 9d402c73ad
4 changed files with 52 additions and 16 deletions

View File

@ -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
-----

View File

@ -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)

View File

@ -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;

View File

@ -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);