forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgmp_random_range.phpt
81 lines (66 loc) · 1.86 KB
/
gmp_random_range.phpt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
--TEST--
gmp_random_range() basic tests
--SKIPIF--
<?php if (!extension_loaded("gmp")) print "skip"; ?>
--FILE--
<?php
$minusTen = gmp_init(-10);
$plusTen = gmp_init(10);
$zero = gmp_init(0);
var_dump(gmp_random_range());
var_dump(gmp_random_range(10));
var_dump(gmp_random_range(10, -10));
var_dump(gmp_random_range($plusTen, $minusTen));
var_dump(gmp_random_range($plusTen, $zero));
// If these error the test fails.
gmp_random_range(0, 10);
gmp_random_range(1, 10);
gmp_random_range(-1, 10);
gmp_random_range(-10, 0);
gmp_random_range(-10, -1);
gmp_random_range(0, $plusTen);
gmp_random_range(1, $plusTen);
gmp_random_range(-1, $plusTen);
gmp_random_range($zero, $plusTen);
gmp_random_range($minusTen, $plusTen);
// 0.5 seconds to make sure the numbers stay in range
$start = microtime(true);
while (1) {
for ($i = 0; $i < 5000; $i++) {
$result = gmp_random_range(0, 1000);
if ($result < 0 || $result > 1000) {
print "RANGE VIOLATION 1\n";
var_dump($result);
break 2;
}
$result = gmp_random_range(-1000, 0);
if ($result < -1000 || $result > 0) {
print "RANGE VIOLATION 2\n";
var_dump($result);
break 2;
}
$result = gmp_random_range(-500, 500);
if ($result < -500 || $result > 500) {
print "RANGE VIOLATION 3\n";
var_dump($result);
break 2;
}
}
if (microtime(true) - $start > 0.5) {
break;
}
}
echo "Done\n";
?>
--EXPECTF--
Warning: gmp_random_range() expects exactly 2 parameters, 0 given in %s on line %d
NULL
Warning: gmp_random_range() expects exactly 2 parameters, 1 given in %s on line %d
NULL
Warning: gmp_random_range(): The minimum value must be less than the maximum value in %s on line %d
bool(false)
Warning: gmp_random_range(): The minimum value must be less than the maximum value in %s on line %d
bool(false)
Warning: gmp_random_range(): The minimum value must be less than the maximum value in %s on line %d
bool(false)
Done