xref: /PHP-8.0/ext/gmp/tests/gmp_fact.phpt (revision 65f14b0d)
1--TEST--
2gmp_fact() basic tests
3--SKIPIF--
4<?php if (!extension_loaded("gmp")) print "skip"; ?>
5--FILE--
6<?php
7
8var_dump(gmp_strval(gmp_fact(0)));
9try {
10    var_dump(gmp_strval(gmp_fact("")));
11} catch (\ValueError $e) {
12    echo $e->getMessage() . \PHP_EOL;
13}
14var_dump(gmp_strval(gmp_fact("0")));
15try {
16    var_dump(gmp_strval(gmp_fact("-1")));
17} catch (\ValueError $e) {
18    echo $e->getMessage() . \PHP_EOL;
19}
20try {
21    var_dump(gmp_strval(gmp_fact(-1)));
22} catch (\ValueError $e) {
23    echo $e->getMessage() . \PHP_EOL;
24}
25
26var_dump(gmp_strval(gmp_fact(1.1)));
27var_dump(gmp_strval(gmp_fact(20)));
28var_dump(gmp_strval(gmp_fact("50")));
29var_dump(gmp_strval(gmp_fact("10")));
30var_dump(gmp_strval(gmp_fact("0000")));
31
32$n = gmp_init(12);
33var_dump(gmp_strval(gmp_fact($n)));
34$n = gmp_init(-10);
35try {
36    var_dump(gmp_strval(gmp_fact($n)));
37} catch (\ValueError $e) {
38    echo $e->getMessage() . \PHP_EOL;
39}
40
41try {
42    var_dump(gmp_fact(array()));
43} catch (\TypeError $e) {
44    echo $e->getMessage() . \PHP_EOL;
45}
46
47echo "Done\n";
48?>
49--EXPECT--
50string(1) "1"
51gmp_fact(): Argument #1 ($num) is not an integer string
52string(1) "1"
53gmp_fact(): Argument #1 ($num) must be greater than or equal to 0
54gmp_fact(): Argument #1 ($num) must be greater than or equal to 0
55string(1) "1"
56string(19) "2432902008176640000"
57string(65) "30414093201713378043612608166064768844377641568960512000000000000"
58string(7) "3628800"
59string(1) "1"
60string(9) "479001600"
61gmp_fact(): Argument #1 ($num) must be greater than or equal to 0
62gmp_fact(): Argument #1 ($num) must be of type GMP|string|int, array given
63Done
64