1--TEST-- 2Test 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 14echo "*** Testing str_shuffle() : basic functionality ***\n"; 15 16// Initialize all required variables 17$str = 'This testcase tests the str_shuffle() function.'; 18var_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 28for ($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 47if ($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 *** 57string(47) "%s" 58TEST PASSED 59===DONE===