xref: /PHP-8.2/ext/gmp/tests/gmp_nextprime.phpt (revision e9f783fc)
1--TEST--
2gmp_nextprime()
3--EXTENSIONS--
4gmp
5--FILE--
6<?php
7
8$n = gmp_nextprime(-1);
9var_dump(gmp_strval($n));
10$n = gmp_nextprime(0);
11var_dump(gmp_strval($n));
12$n = gmp_nextprime(-1000);
13var_dump(gmp_strval($n));
14$n = gmp_nextprime(1000);
15var_dump(gmp_strval($n));
16$n = gmp_nextprime(100000);
17var_dump(gmp_strval($n));
18try {
19    $n = gmp_nextprime(array());
20    var_dump(gmp_strval($n));
21} catch (\TypeError $e) {
22    echo $e->getMessage() . \PHP_EOL;
23}
24try {
25    $n = gmp_nextprime("");
26    var_dump(gmp_strval($n));
27} catch (\ValueError $e) {
28    echo $e->getMessage() . \PHP_EOL;
29}
30try {
31    $n = gmp_nextprime(new stdclass());
32    var_dump(gmp_strval($n));
33} catch (\TypeError $e) {
34    echo $e->getMessage() . \PHP_EOL;
35}
36
37echo "Done\n";
38?>
39--EXPECT--
40string(1) "2"
41string(1) "2"
42string(1) "2"
43string(4) "1009"
44string(6) "100003"
45gmp_nextprime(): Argument #1 ($num) must be of type GMP|string|int, array given
46gmp_nextprime(): Argument #1 ($num) is not an integer string
47gmp_nextprime(): Argument #1 ($num) must be of type GMP|string|int, stdClass given
48Done
49