Annotation of embedaddon/php/ext/standard/tests/strings/str_shuffle_basic.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test str_shuffle() function : basic functionality
3: --FILE--
4: <?php
5: /* Prototype : string str_shuffle ( string $str )
6: * Description: Randomly shuffles a string
7: * Source code: ext/standard/string.c
8: */
9:
10: /*
11: * Testing str_shuffle() : basic functionality
12: */
13:
14: echo "*** Testing str_shuffle() : basic functionality ***\n";
15:
16: // Initialize all required variables
17: $str = 'This testcase tests the str_shuffle() function.';
18: var_dump(str_shuffle($str));
19:
20:
21: // For a given i/p string ensure that all combinations are
22: // generated given a reasonable sample of calls
23: $a = array();
24: $trys = 1000;
25: $ip = 'abcd';
26: $len_ip = strlen($ip);
27:
28: for ($i = 0; $i < $trys; $i++) {
29: $op = str_shuffle($ip);
30:
31: if (!is_string($op) || strlen($op) != $len_ip) {
32: echo "TEST FAILED\n";
33: }
34:
35: // Combination already hit ?
36: if (empty($a[$op])) {
37: // No first time init
38: $a[$op] = 0;
39: }
40:
41: // Increment count for this combination
42: $a[$op]++;
43: }
44:
45: $combinations = count($a);
46:
47: if ($combinations != 24) {
48: echo "TEST FAILED.. Only $combinations out of a possible 24 combinations used\n";
49: } else {
50: echo "TEST PASSED\n";
51: }
52:
53: ?>
54: ===DONE===
55: --EXPECTF--
56: *** Testing str_shuffle() : basic functionality ***
57: string(47) "%s"
58: TEST PASSED
59: ===DONE===
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>