Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9d402c7

Browse files
committed
Expand tests for factorial
Move from int4 to numeric test. (They were originally int4 functions, but were reimplemented for numeric in 04a4821.) Add some tests for edge cases. Discussion: https://www.postgresql.org/message-id/flat/6ce1df0e-86a3-e544-743a-f357ff663f68%402ndquadrant.com
1 parent 2b2a070 commit 9d402c7

File tree

4 files changed

+52
-16
lines changed

4 files changed

+52
-16
lines changed

src/test/regress/expected/int4.out

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -299,18 +299,6 @@ SELECT int4 '1000' < int4 '999' AS false;
299299
f
300300
(1 row)
301301

302-
SELECT 4! AS twenty_four;
303-
twenty_four
304-
-------------
305-
24
306-
(1 row)
307-
308-
SELECT !!3 AS six;
309-
six
310-
-----
311-
6
312-
(1 row)
313-
314302
SELECT 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 AS ten;
315303
ten
316304
-----

src/test/regress/expected/numeric.out

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,3 +2315,44 @@ FROM (VALUES (0::numeric, 0::numeric),
23152315

23162316
SELECT lcm(9999 * (10::numeric)^131068 + (10::numeric^131068 - 1), 2); -- overflow
23172317
ERROR: value overflows numeric format
2318+
--
2319+
-- Tests for factorial
2320+
--
2321+
SELECT 4!;
2322+
?column?
2323+
----------
2324+
24
2325+
(1 row)
2326+
2327+
SELECT !!3;
2328+
?column?
2329+
----------
2330+
6
2331+
(1 row)
2332+
2333+
SELECT factorial(15);
2334+
factorial
2335+
---------------
2336+
1307674368000
2337+
(1 row)
2338+
2339+
SELECT 100000!;
2340+
ERROR: value overflows numeric format
2341+
SELECT 0!;
2342+
?column?
2343+
----------
2344+
1
2345+
(1 row)
2346+
2347+
SELECT -4!;
2348+
?column?
2349+
----------
2350+
1
2351+
(1 row)
2352+
2353+
SELECT factorial(-4);
2354+
factorial
2355+
-----------
2356+
1
2357+
(1 row)
2358+

src/test/regress/sql/int4.sql

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,6 @@ SELECT int2 '2' * int4 '2' = int4 '16' / int2 '4' AS true;
114114

115115
SELECT int4 '1000' < int4 '999' AS false;
116116

117-
SELECT 4! AS twenty_four;
118-
119-
SELECT !!3 AS six;
120-
121117
SELECT 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 AS ten;
122118

123119
SELECT 2 + 2 / 2 AS three;

src/test/regress/sql/numeric.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,3 +1111,14 @@ FROM (VALUES (0::numeric, 0::numeric),
11111111
(4232.820::numeric, 132.72000::numeric)) AS v(a, b);
11121112

11131113
SELECT lcm(9999 * (10::numeric)^131068 + (10::numeric^131068 - 1), 2); -- overflow
1114+
1115+
--
1116+
-- Tests for factorial
1117+
--
1118+
SELECT 4!;
1119+
SELECT !!3;
1120+
SELECT factorial(15);
1121+
SELECT 100000!;
1122+
SELECT 0!;
1123+
SELECT -4!;
1124+
SELECT factorial(-4);

0 commit comments

Comments
 (0)