Annotation of embedaddon/php/ext/standard/tests/array/array_shuffle_basic.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: array_shuffle(): Test return type and value for expected input
3: --FILE--
4: <?php
5: /*
6: * proto bool shuffle ( array &$array )
7: * Function is implemented in ext/standard/array.c
8: */
9: $numbers = range(1, 20);
10: echo "*** testing array_shuffle \n";
11: $a = array();
12: var_dump(shuffle($a));
13: var_dump($a);
14: $a = array(1);
15: var_dump(shuffle($a));
16: var_dump($a);
17: $a = array(2 => 1);
18: var_dump(shuffle($a));
19: var_dump($a);
20: $a = array("a" => 1);
21: var_dump(shuffle($a));
22: var_dump($a);
23: $a = array(array(1, 2, 3));
24: var_dump(shuffle($a));
25: var_dump($a);
26: $a = array(1, 1, 1, 1);
27: var_dump(shuffle($a));
28: var_dump($a);
29: $arr1 = array(5 => 1, 6 => 2, 7 => 3, 8 => 9);
30: $arr2 = array(5 => 1, 6 => 2, 7 => 3, 8 => 9);
31: shuffle($arr1);
32: echo "this should be 0->...." . count(array_diff($arr1, $arr2)) . "\n";
33: echo "this should be 4->...." . count(array_intersect($arr1, $arr2)) . "\n";
34: $bigarray = range(1, 400);
35: shuffle($bigarray);
36: echo "this should be 400->...." . count($bigarray) . "\n";
37: echo "*** testing pass by reference \n";
38: $original = $bigarray;
39: shuffle($bigarray);
40: $diffarray = array_diff_assoc($original, $bigarray);
41: if (count($diffarray) < 350) {
42: // with 400 entries, the probability that 50 entries or more get the same
43: // key-> value association should be so close to zero it wont happen in the lifetime of the
44: // universe.
45: echo "shuffled array seems to be similar to original\n";
46: var_dump($original);
47: var_dump($bigarray);
48: } else {
49: echo "test passed \n";
50: }
51: ?>
52: --EXPECT--
53: *** testing array_shuffle
54: bool(true)
55: array(0) {
56: }
57: bool(true)
58: array(1) {
59: [0]=>
60: int(1)
61: }
62: bool(true)
63: array(1) {
64: [0]=>
65: int(1)
66: }
67: bool(true)
68: array(1) {
69: [0]=>
70: int(1)
71: }
72: bool(true)
73: array(1) {
74: [0]=>
75: array(3) {
76: [0]=>
77: int(1)
78: [1]=>
79: int(2)
80: [2]=>
81: int(3)
82: }
83: }
84: bool(true)
85: array(4) {
86: [0]=>
87: int(1)
88: [1]=>
89: int(1)
90: [2]=>
91: int(1)
92: [3]=>
93: int(1)
94: }
95: this should be 0->....0
96: this should be 4->....4
97: this should be 400->....400
98: *** testing pass by reference
99: test passed
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>