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