kraghuba Sat Oct 27 12:27:49 2007 UTC
Added files: (Branch: PHP_5_3)
/php-src/ext/standard/tests/array shuffle_error.phpt
shuffle_variation1.phpt
shuffle_variation2.phpt
shuffle_variation3.phpt
shuffle_variation4.phpt
shuffle_variation5.phpt
shuffle_basic1.phpt
shuffle_basic2.phpt
Log:
New testcases for shuffle() function
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/shuffle_error.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/shuffle_error.phpt
+++ php-src/ext/standard/tests/array/shuffle_error.phpt
--TEST--
Test shuffle() function : error conditions
--FILE--
<?php
/* Prototype : bool shuffle(array $array_arg)
* Description: Randomly shuffle the contents of an array
* Source code: ext/standard/array.c
*/
/* Test shuffle() to see that warning messages are emitted
* when invalid number of arguments are passed to the function
*/
echo "*** Testing shuffle() : error conditions ***\n";
// zero arguments
echo "\n-- Testing shuffle() function with Zero arguments --\n";
var_dump( shuffle() );
// more than the expected number of arguments
echo "\n-- Testing shuffle() function with more than expected no. of arguments
--\n";
$array_arg = array(1, "two" => 2);
$extra_arg = 10;
var_dump( shuffle($array_arg, $extra_arg) );
// printing the input array to check that it is not affected
// by above shuffle() function calls
echo "\n-- original input array --\n";
var_dump( $array_arg );
echo "Done";
?>
--EXPECTF--
*** Testing shuffle() : error conditions ***
-- Testing shuffle() function with Zero arguments --
Warning: shuffle() expects exactly 1 parameter, 0 given in %s on line %d
bool(false)
-- Testing shuffle() function with more than expected no. of arguments --
Warning: shuffle() expects exactly 1 parameter, 2 given in %s on line %d
bool(false)
-- original input array --
array(2) {
[0]=>
int(1)
["two"]=>
int(2)
}
Done
--UEXPECTF--
*** Testing shuffle() : error conditions ***
-- Testing shuffle() function with Zero arguments --
Warning: shuffle() expects exactly 1 parameter, 0 given in %s on line %d
bool(false)
-- Testing shuffle() function with more than expected no. of arguments --
Warning: shuffle() expects exactly 1 parameter, 2 given in %s on line %d
bool(false)
-- original input array --
array(2) {
[0]=>
int(1)
[u"two"]=>
int(2)
}
Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/shuffle_variation1.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/shuffle_variation1.phpt
+++ php-src/ext/standard/tests/array/shuffle_variation1.phpt
--TEST--
Test shuffle() function : usage variations - unexpected values for 'array_arg'
argument
--FILE--
<?php
/* Prototype : bool shuffle(array $array_arg)
* Description: Randomly shuffle the contents of an array
* Source code: ext/standard/array.c
*/
/*
* Test behaviour of shuffle() when unexpected values are passed for 'array_arg'
* argument and verify that function outputs required warning messages wherever
applicable
*/
echo "*** Testing shuffle() : with unexpected values for 'array_arg' argument
***\n";
//get an unset variable
$unset_var = 10;
unset ($unset_var);
//get a resource variable
$fp = fopen(__FILE__, "r");
//define a class
class test
{
var $t = 10;
function __toString()
{
return "object";
}
}
//array of values to iterate over
$values = array(
// int data
/*1*/ 0,
1,
12345,
-2345,
// float data
/*5*/ 10.5,
-10.5,
12.3456789000e10,
12.3456789000E-10,
.5,
// null data
/*10*/ NULL,
null,
// boolean data
/*12*/ true,
false,
TRUE,
FALSE,
// empty data
/*16*/ "",
'',
// string data
/*18*/ "string",
'string',
// object data
/*20*/ new test(),
// undefined data
/*21*/ @$undefined_var,
// unset data
/*22*/ @$unset_var,
/*23*/ // resource data
$fp
);
// loop through the array to test shuffle() function
// with each element of the array
$count = 1;
foreach($values as $value) {
echo "\n-- Iteration $count --\n";
var_dump( shuffle($value) );
$count++;
};
// closing the resource
fclose($fp);
echo "Done";
?>
--EXPECTF--
*** Testing shuffle() : with unexpected values for 'array_arg' argument ***
-- Iteration 1 --
Warning: shuffle() expects parameter 1 to be array, integer given in %s on line
%d
bool(false)
-- Iteration 2 --
Warning: shuffle() expects parameter 1 to be array, integer given in %s on line
%d
bool(false)
-- Iteration 3 --
Warning: shuffle() expects parameter 1 to be array, integer given in %s on line
%d
bool(false)
-- Iteration 4 --
Warning: shuffle() expects parameter 1 to be array, integer given in %s on line
%d
bool(false)
-- Iteration 5 --
Warning: shuffle() expects parameter 1 to be array, double given in %s on line
%d
bool(false)
-- Iteration 6 --
Warning: shuffle() expects parameter 1 to be array, double given in %s on line
%d
bool(false)
-- Iteration 7 --
Warning: shuffle() expects parameter 1 to be array, double given in %s on line
%d
bool(false)
-- Iteration 8 --
Warning: shuffle() expects parameter 1 to be array, double given in %s on line
%d
bool(false)
-- Iteration 9 --
Warning: shuffle() expects parameter 1 to be array, double given in %s on line
%d
bool(false)
-- Iteration 10 --
Warning: shuffle() expects parameter 1 to be array, null given in %s on line %d
bool(false)
-- Iteration 11 --
Warning: shuffle() expects parameter 1 to be array, null given in %s on line %d
bool(false)
-- Iteration 12 --
Warning: shuffle() expects parameter 1 to be array, boolean given in %s on line
%d
bool(false)
-- Iteration 13 --
Warning: shuffle() expects parameter 1 to be array, boolean given in %s on line
%d
bool(false)
-- Iteration 14 --
Warning: shuffle() expects parameter 1 to be array, boolean given in %s on line
%d
bool(false)
-- Iteration 15 --
Warning: shuffle() expects parameter 1 to be array, boolean given in %s on line
%d
bool(false)
-- Iteration 16 --
Warning: shuffle() expects parameter 1 to be array, string given in %s on line
%d
bool(false)
-- Iteration 17 --
Warning: shuffle() expects parameter 1 to be array, string given in %s on line
%d
bool(false)
-- Iteration 18 --
Warning: shuffle() expects parameter 1 to be array, string given in %s on line
%d
bool(false)
-- Iteration 19 --
Warning: shuffle() expects parameter 1 to be array, string given in %s on line
%d
bool(false)
-- Iteration 20 --
Warning: shuffle() expects parameter 1 to be array, object given in %s on line
%d
bool(false)
-- Iteration 21 --
Warning: shuffle() expects parameter 1 to be array, null given in %s on line %d
bool(false)
-- Iteration 22 --
Warning: shuffle() expects parameter 1 to be array, null given in %s on line %d
bool(false)
-- Iteration 23 --
Warning: shuffle() expects parameter 1 to be array, resource given in %s on
line %d
bool(false)
Done
--UEXPECTF--
*** Testing shuffle() : with unexpected values for 'array_arg' argument ***
-- Iteration 1 --
Warning: shuffle() expects parameter 1 to be array, integer given in %s on line
%d
bool(false)
-- Iteration 2 --
Warning: shuffle() expects parameter 1 to be array, integer given in %s on line
%d
bool(false)
-- Iteration 3 --
Warning: shuffle() expects parameter 1 to be array, integer given in %s on line
%d
bool(false)
-- Iteration 4 --
Warning: shuffle() expects parameter 1 to be array, integer given in %s on line
%d
bool(false)
-- Iteration 5 --
Warning: shuffle() expects parameter 1 to be array, double given in %s on line
%d
bool(false)
-- Iteration 6 --
Warning: shuffle() expects parameter 1 to be array, double given in %s on line
%d
bool(false)
-- Iteration 7 --
Warning: shuffle() expects parameter 1 to be array, double given in %s on line
%d
bool(false)
-- Iteration 8 --
Warning: shuffle() expects parameter 1 to be array, double given in %s on line
%d
bool(false)
-- Iteration 9 --
Warning: shuffle() expects parameter 1 to be array, double given in %s on line
%d
bool(false)
-- Iteration 10 --
Warning: shuffle() expects parameter 1 to be array, null given in %s on line %d
bool(false)
-- Iteration 11 --
Warning: shuffle() expects parameter 1 to be array, null given in %s on line %d
bool(false)
-- Iteration 12 --
Warning: shuffle() expects parameter 1 to be array, boolean given in %s on line
%d
bool(false)
-- Iteration 13 --
Warning: shuffle() expects parameter 1 to be array, boolean given in %s on line
%d
bool(false)
-- Iteration 14 --
Warning: shuffle() expects parameter 1 to be array, boolean given in %s on line
%d
bool(false)
-- Iteration 15 --
Warning: shuffle() expects parameter 1 to be array, boolean given in %s on line
%d
bool(false)
-- Iteration 16 --
Warning: shuffle() expects parameter 1 to be array, Unicode string given in %s
on line %d
bool(false)
-- Iteration 17 --
Warning: shuffle() expects parameter 1 to be array, Unicode string given in %s
on line %d
bool(false)
-- Iteration 18 --
Warning: shuffle() expects parameter 1 to be array, Unicode string given in %s
on line %d
bool(false)
-- Iteration 19 --
Warning: shuffle() expects parameter 1 to be array, Unicode string given in %s
on line %d
bool(false)
-- Iteration 20 --
Warning: shuffle() expects parameter 1 to be array, object given in %s on line
%d
bool(false)
-- Iteration 21 --
Warning: shuffle() expects parameter 1 to be array, null given in %s on line %d
bool(false)
-- Iteration 22 --
Warning: shuffle() expects parameter 1 to be array, null given in %s on line %d
bool(false)
-- Iteration 23 --
Warning: shuffle() expects parameter 1 to be array, resource given in %s on
line %d
bool(false)
Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/shuffle_variation2.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/shuffle_variation2.phpt
+++ php-src/ext/standard/tests/array/shuffle_variation2.phpt
--TEST--
Test shuffle() function : usage variation - with MultiDimensional array
--FILE--
<?php
/* Prototype : bool shuffle(array $array_arg)
* Description: Randomly shuffle the contents of an array
* Source code: ext/standard/array.c
*/
/*
* Test behaviour of shuffle() function when multi-dimensional array is
* passed to 'array_arg' argument
*/
echo "*** Testing shuffle() : with multi-dimensional array ***\n";
// initialise the multi-dimensional array
$array_arg = array(
array(1, 2, 3),
array(4, 5, 6),
array(7, 8, 9),
array(10000, 20000000, 30000000),
array(0, 0, 0),
array(012, 023, 034),
array(0x1, 0x0, 0xa)
);
// calling shuffle() function with multi-dimensional array
var_dump( shuffle($array_arg) );
echo "\nThe output array is:\n";
var_dump( $array_arg );
// looping to test shuffle() with each sub-array in the multi-dimensional array
echo "\n*** Testing shuffle() with arrays having different types of values
***\n";
$counter = 1;
for($i=0; $i<=6; $i++) {
echo "\n-- Iteration $counter --\n";
var_dump( shuffle($array_arg[$i]) );
echo "\nThe output array is:\n";
var_dump( $array_arg[$i] );
$counter++;
}
echo "Done";
?>
--EXPECTF--
*** Testing shuffle() : with multi-dimensional array ***
bool(true)
The output array is:
array(7) {
[0]=>
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
[1]=>
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
[2]=>
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
[3]=>
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
[4]=>
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
[5]=>
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
[6]=>
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
}
*** Testing shuffle() with arrays having different types of values ***
-- Iteration 1 --
bool(true)
The output array is:
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
-- Iteration 2 --
bool(true)
The output array is:
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
-- Iteration 3 --
bool(true)
The output array is:
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
-- Iteration 4 --
bool(true)
The output array is:
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
-- Iteration 5 --
bool(true)
The output array is:
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
-- Iteration 6 --
bool(true)
The output array is:
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
-- Iteration 7 --
bool(true)
The output array is:
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
Done
--UEXPECTF--
*** Testing shuffle() : with multi-dimensional array ***
bool(true)
The output array is:
array(7) {
[0]=>
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
[1]=>
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
[2]=>
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
[3]=>
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
[4]=>
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
[5]=>
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
[6]=>
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
}
*** Testing shuffle() with arrays having different types of values ***
-- Iteration 1 --
bool(true)
The output array is:
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
-- Iteration 2 --
bool(true)
The output array is:
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
-- Iteration 3 --
bool(true)
The output array is:
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
-- Iteration 4 --
bool(true)
The output array is:
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
-- Iteration 5 --
bool(true)
The output array is:
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
-- Iteration 6 --
bool(true)
The output array is:
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
-- Iteration 7 --
bool(true)
The output array is:
array(3) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
}
Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/shuffle_variation3.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/shuffle_variation3.phpt
+++ php-src/ext/standard/tests/array/shuffle_variation3.phpt
--TEST--
Test shuffle() function : usage variation - arrays with diff types of values
--FILE--
<?php
/* Prototype : bool shuffle(array $array_arg)
* Description: Randomly shuffle the contents of an array
* Source code: ext/standard/array.c
*/
/*
* Test behaviour of shuffle() function when arrays having different
* types of values, are passed to 'array_arg' argument
*/
echo "*** Testing shuffle() : arrays with diff types of values ***\n";
// initialise different arrays
$array_arg = array(
// array with positive int values
/*1*/ array(0, 1, 2, 2147483647 ),
// array with negative int values
array(-1, -2, -2147483647 ),
// array with positive float values
/*3*/ array(0.23, 1.34, 0e2, 200e-2, 30e2, 10e0, 2147473648.90),
// array with negative float values
array(-0.23, -1.34, -200e-2, -30e2, -10e0, -2147473649.80),
// array with single quoted and double quoted strings
/*5*/ array('one', "123numbers", 'hello\tworld', "hello world\0",
'12.34floatnum'),
// array with bool values
array(true, TRUE, FALSE, false),
// array with positive hexa values
/*7*/ array(0x123, 0xabc, 0xABC, 0xac, 0xAb1, 0x9fa),
// array with negative hexa values
array(-0x123, -0xabc, -0xABC, -0xAb1, -0x9fa),
// array with positive octal values
/*9*/ array(0123, 02348, 034, 00),
// array with negative octal values
/*10*/ array(-0123, -02348, -034),
);
// looping to test shuffle() with each sub-array in the $array_arg array
echo "\n*** Testing shuffle() with arrays having different types of values
***\n";
$counter = 1;
foreach($array_arg as $arr) {
echo "\n-- Iteration $counter --\n";
var_dump( shuffle($arr) );
echo "\nThe output array is:\n";
var_dump( $arr );
$counter++;
}
echo "Done";
?>
--EXPECTF--
*** Testing shuffle() : arrays with diff types of values ***
*** Testing shuffle() with arrays having different types of values ***
-- Iteration 1 --
bool(true)
The output array is:
array(4) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
[3]=>
int(%d)
}
-- Iteration 2 --
bool(true)
The output array is:
array(3) {
[0]=>
int(-%d)
[1]=>
int(-%d)
[2]=>
int(-%d)
}
-- Iteration 3 --
bool(true)
The output array is:
array(7) {
[0]=>
float(%f)
[1]=>
float(%f)
[2]=>
float(%f)
[3]=>
float(%f)
[4]=>
float(%f)
[5]=>
float(%f)
[6]=>
float(%f)
}
-- Iteration 4 --
bool(true)
The output array is:
array(6) {
[0]=>
float(-%f)
[1]=>
float(-%f)
[2]=>
float(-%f)
[3]=>
float(-%f)
[4]=>
float(-%f)
[5]=>
float(-%f)
}
-- Iteration 5 --
bool(true)
The output array is:
array(5) {
[0]=>
string(%d) "%s"
[1]=>
string(%d) "%s"
[2]=>
string(%d) "%s"
[3]=>
string(%d) "%s"
[4]=>
string(%d) "%s"
}
-- Iteration 6 --
bool(true)
The output array is:
array(4) {
[0]=>
bool(%s)
[1]=>
bool(%s)
[2]=>
bool(%s)
[3]=>
bool(%s)
}
-- Iteration 7 --
bool(true)
The output array is:
array(6) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
[3]=>
int(%d)
[4]=>
int(%d)
[5]=>
int(%d)
}
-- Iteration 8 --
bool(true)
The output array is:
array(5) {
[0]=>
int(-%d)
[1]=>
int(-%d)
[2]=>
int(-%d)
[3]=>
int(-%d)
[4]=>
int(-%d)
}
-- Iteration 9 --
bool(true)
The output array is:
array(4) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
[3]=>
int(%d)
}
-- Iteration 10 --
bool(true)
The output array is:
array(3) {
[0]=>
int(-%d)
[1]=>
int(-%d)
[2]=>
int(-%d)
}
Done
--UEXPECTF--
*** Testing shuffle() : arrays with diff types of values ***
*** Testing shuffle() with arrays having different types of values ***
-- Iteration 1 --
bool(true)
The output array is:
array(4) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
[3]=>
int(%d)
}
-- Iteration 2 --
bool(true)
The output array is:
array(3) {
[0]=>
int(-%d)
[1]=>
int(-%d)
[2]=>
int(-%d)
}
-- Iteration 3 --
bool(true)
The output array is:
array(7) {
[0]=>
float(%f)
[1]=>
float(%f)
[2]=>
float(%f)
[3]=>
float(%f)
[4]=>
float(%f)
[5]=>
float(%f)
[6]=>
float(%f)
}
-- Iteration 4 --
bool(true)
The output array is:
array(6) {
[0]=>
float(-%f)
[1]=>
float(-%f)
[2]=>
float(-%f)
[3]=>
float(-%f)
[4]=>
float(-%f)
[5]=>
float(-%f)
}
-- Iteration 5 --
bool(true)
The output array is:
array(5) {
[0]=>
unicode(%d) "%s"
[1]=>
unicode(%d) "%s"
[2]=>
unicode(%d) "%s"
[3]=>
unicode(%d) "%s"
[4]=>
unicode(%d) "%s"
}
-- Iteration 6 --
bool(true)
The output array is:
array(4) {
[0]=>
bool(%s)
[1]=>
bool(%s)
[2]=>
bool(%s)
[3]=>
bool(%s)
}
-- Iteration 7 --
bool(true)
The output array is:
array(6) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
[3]=>
int(%d)
[4]=>
int(%d)
[5]=>
int(%d)
}
-- Iteration 8 --
bool(true)
The output array is:
array(5) {
[0]=>
int(-%d)
[1]=>
int(-%d)
[2]=>
int(-%d)
[3]=>
int(-%d)
[4]=>
int(-%d)
}
-- Iteration 9 --
bool(true)
The output array is:
array(4) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
[3]=>
int(%d)
}
-- Iteration 10 --
bool(true)
The output array is:
array(3) {
[0]=>
int(-%d)
[1]=>
int(-%d)
[2]=>
int(-%d)
}
Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/shuffle_variation4.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/shuffle_variation4.phpt
+++ php-src/ext/standard/tests/array/shuffle_variation4.phpt
--TEST--
Test shuffle() function : usage variation - associative arrays with diff types
of values
--FILE--
<?php
/* Prototype : bool shuffle(array $array_arg)
* Description: Randomly shuffle the contents of an array
* Source code: ext/standard/array.c
*/
/*
* Test behaviour of shuffle() function when associative arrays
* having different types of values, are passed to 'array_arg' argument
*/
echo "*** Testing shuffle() : associative arrays with diff types of values
***\n";
// initialise different arrays
$array_arg = array(
// array with positive int values
/*1*/ array("zero" => 0, 1 => 1, "two" => 2, "max_int" => 2147483647 ),
// array with negative int values
array("minus_one" => -1, 'minus_two' => -2, "min_int" => -2147483647 ),
// array with positive float values
/*3*/ array("float1" => 0.23, 'float2' => 1.34, "exp1" => 0e2, 'exp2' =>
200e-2, "exp3" => 10e0),
// array with negative float values
array(-0.23 => -0.23, -1.34 => -1.34, -200e-2 => -200e-2, -30 => -30e0,
-2147473649.80),
// array with single and double quoted strings
/*5*/ array('1' => 'one', "str1" => "123numbers", '' => 'hello\tworld', "" =>
"hello world\0", "12.34floatnum"),
// array with bool values
array('1' => TRUE, "1" => TRUE, "0" => FALSE, '0' => FALSE),
// array with positive hexa values
/*7*/ array("hex1" => 0x123, 'hex2' => 0xabc, "hex\t3" => 0xABC, "hex\04" =>
0xAb1),
// array with negative hexa values
array(NULL => -0x123, "NULL" => -0xabc, "-ABC" => -0xABC, -0xAB1 =>
-0xAb1),
// array with positive octal values
/*9*/ array(0123 => 0123, "02348" => 02348, '034' => 034, 00 => 00),
// array with negative octal values
array(-0123 => -0123, "-02348" => -02348, '-034' => -034),
// array with null values
/*11*/ array(NULL => NULL, "null" => NULL, "NULL" => NULL)
);
// looping to test shuffle() with each sub-array in the $array_arg array
echo "\n*** Testing shuffle() with arrays having different types of values
***\n";
$counter = 1;
foreach($array_arg as $arr) {
echo "\n-- Iteration $counter --\n";
var_dump( shuffle($arr) );
echo "\nThe output array is:\n";
var_dump( $arr );
$counter++;
}
echo "Done";
?>
--EXPECTF--
*** Testing shuffle() : associative arrays with diff types of values ***
*** Testing shuffle() with arrays having different types of values ***
-- Iteration 1 --
bool(true)
The output array is:
array(4) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
[3]=>
int(%d)
}
-- Iteration 2 --
bool(true)
The output array is:
array(3) {
[0]=>
int(-%d)
[1]=>
int(-%d)
[2]=>
int(-%d)
}
-- Iteration 3 --
bool(true)
The output array is:
array(5) {
[0]=>
float(%f)
[1]=>
float(%f)
[2]=>
float(%f)
[3]=>
float(%f)
[4]=>
float(%f)
}
-- Iteration 4 --
bool(true)
The output array is:
array(5) {
[0]=>
float(-%f)
[1]=>
float(-%f)
[2]=>
float(-%f)
[3]=>
float(-%f)
[4]=>
float(-%f)
}
-- Iteration 5 --
bool(true)
The output array is:
array(4) {
[0]=>
string(%d) "%s"
[1]=>
string(%d) "%s"
[2]=>
string(%d) "%s"
[3]=>
string(%d) "%s"
}
-- Iteration 6 --
bool(true)
The output array is:
array(2) {
[0]=>
bool(%s)
[1]=>
bool(%s)
}
-- Iteration 7 --
bool(true)
The output array is:
array(4) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
[3]=>
int(%d)
}
-- Iteration 8 --
bool(true)
The output array is:
array(4) {
[0]=>
int(-%d)
[1]=>
int(-%d)
[2]=>
int(-%d)
[3]=>
int(-%d)
}
-- Iteration 9 --
bool(true)
The output array is:
array(4) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
[3]=>
int(%d)
}
-- Iteration 10 --
bool(true)
The output array is:
array(3) {
[0]=>
int(-%d)
[1]=>
int(-%d)
[2]=>
int(-%d)
}
-- Iteration 11 --
bool(true)
The output array is:
array(3) {
[0]=>
NULL
[1]=>
NULL
[2]=>
NULL
}
Done
--UEXPECTF--
*** Testing shuffle() : associative arrays with diff types of values ***
*** Testing shuffle() with arrays having different types of values ***
-- Iteration 1 --
bool(true)
The output array is:
array(4) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
[3]=>
int(%d)
}
-- Iteration 2 --
bool(true)
The output array is:
array(3) {
[0]=>
int(-%d)
[1]=>
int(-%d)
[2]=>
int(-%d)
}
-- Iteration 3 --
bool(true)
The output array is:
array(5) {
[0]=>
float(%f)
[1]=>
float(%f)
[2]=>
float(%f)
[3]=>
float(%f)
[4]=>
float(%f)
}
-- Iteration 4 --
bool(true)
The output array is:
array(5) {
[0]=>
float(-%f)
[1]=>
float(-%f)
[2]=>
float(-%f)
[3]=>
float(-%f)
[4]=>
float(-%f)
}
-- Iteration 5 --
bool(true)
The output array is:
array(4) {
[0]=>
unicode(%d) "%s"
[1]=>
unicode(%d) "%s"
[2]=>
unicode(%d) "%s"
[3]=>
unicode(%d) "%s"
}
-- Iteration 6 --
bool(true)
The output array is:
array(2) {
[0]=>
bool(%s)
[1]=>
bool(%s)
}
-- Iteration 7 --
bool(true)
The output array is:
array(4) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
[3]=>
int(%d)
}
-- Iteration 8 --
bool(true)
The output array is:
array(4) {
[0]=>
int(-%d)
[1]=>
int(-%d)
[2]=>
int(-%d)
[3]=>
int(-%d)
}
-- Iteration 9 --
bool(true)
The output array is:
array(4) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
[3]=>
int(%d)
}
-- Iteration 10 --
bool(true)
The output array is:
array(3) {
[0]=>
int(-%d)
[1]=>
int(-%d)
[2]=>
int(-%d)
}
-- Iteration 11 --
bool(true)
The output array is:
array(3) {
[0]=>
NULL
[1]=>
NULL
[2]=>
NULL
}
Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/shuffle_variation5.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/shuffle_variation5.phpt
+++ php-src/ext/standard/tests/array/shuffle_variation5.phpt
--TEST--
Test shuffle() function : usage variation - arrays with diff heredoc strings
--FILE--
<?php
/* Prototype : bool shuffle(array $array_arg)
* Description: Randomly shuffle the contents of an array
* Source code: ext/standard/array.c
*/
/*
* Test behaviour of shuffle() when an array of heredoc strings is passed to
* 'array_arg' argument of the function
*/
echo "*** Testing shuffle() : with array containing heredoc strings ***\n";
// defining different heredoc strings
$empty_heredoc = <<<EOT
EOT;
$heredoc_with_newline = <<<EOT
\n
EOT;
$heredoc_with_characters = <<<EOT
first line of heredoc string
second line of heredoc string
third line of heredocstring
EOT;
$heredoc_with_newline_and_tabs = <<<EOT
hello\tworld\nhello\nworld\n
EOT;
$heredoc_with_alphanumerics = <<<EOT
hello123world456
1234hello\t1234
EOT;
$heredoc_with_embedded_nulls = <<<EOT
hello\0world\0hello
\0hello\0
EOT;
// defining array with values as heredoc strings
$heredoc_array = array(
$empty_heredoc,
$heredoc_with_newline,
$heredoc_with_characters,
$heredoc_with_newline_and_tabs,
$heredoc_with_alphanumerics,
$heredoc_with_embedded_nulls
);
// defining array with keys as heredoc strings
$heredoc_asso_array = array(
$empty_heredoc => "heredoc1",
$heredoc_with_newline => "heredoc2",
$heredoc_with_characters => "heredoc3",
$heredoc_with_newline_and_tabs => "heredoc3",
$heredoc_with_alphanumerics => "heredoc4",
$heredoc_with_embedded_nulls => "heredoc5"
);
// test shuffle() with array containing heredoc strings as values
echo "\n-- with array of heredoc strings --\n";
var_dump( shuffle($heredoc_array) );
echo "\nThe output array is:\n";
var_dump( $heredoc_array );
// test shuffle() with array containing heredoc strings as its keys
echo "\n-- with array having heredoc strings as keys --\n";
var_dump( shuffle($heredoc_asso_array) );
echo "\nThe output array is:\n";
var_dump( $heredoc_asso_array );
echo "Done";
?>
--EXPECTREGEX--
\*\*\* Testing shuffle\(\) : with array containing heredoc strings \*\*\*
-- with array of heredoc strings --
bool\(true\)
The output array is:
array\(6\) {
\[0\]=>
string\([0-9]*\) "[0-9 a-z \n \0 \t]*"
\[1\]=>
string\([0-9]*\) "[0-9 a-z \n \0 \t]*"
\[2\]=>
string\([0-9]*\) "[0-9 a-z \n \0 \t]*"
\[3\]=>
string\([0-9]*\) "[0-9 a-z \n \0 \t]*"
\[4\]=>
string\([0-9]*\) "[0-9 a-z \n \0 \t]*"
\[5\]=>
string\([0-9]*\) "[0-9 a-z \n \0 \t]*"
}
-- with array having heredoc strings as keys --
bool\(true\)
The output array is:
array\(6\) {
\[0\]=>
string\(8\) "[heredoc 1-5]*"
\[1\]=>
string\(8\) "[heredoc 1-5]*"
\[2\]=>
string\(8\) "[heredoc 1-5]*"
\[3\]=>
string\(8\) "[heredoc 1-5]*"
\[4\]=>
string\(8\) "[heredoc 1-5]*"
\[5\]=>
string\(8\) "[heredoc 1-5]*"
}
Done
--UEXPECTREGEX--
\*\*\* Testing shuffle\(\) : with array containing heredoc strings \*\*\*
-- with array of heredoc strings --
bool\(true\)
The output array is:
array\(6\) {
\[0\]=>
unicode\([0-9]*\) "[0-9 a-z \n \0 \t]*"
\[1\]=>
unicode\([0-9]*\) "[0-9 a-z \n \0 \t]*"
\[2\]=>
unicode\([0-9]*\) "[0-9 a-z \n \0 \t]*"
\[3\]=>
unicode\([0-9]*\) "[0-9 a-z \n \0 \t]*"
\[4\]=>
unicode\([0-9]*\) "[0-9 a-z \n \0 \t]*"
\[5\]=>
unicode\([0-9]*\) "[0-9 a-z \n \0 \t]*"
}
-- with array having heredoc strings as keys --
bool\(true\)
The output array is:
array\(6\) {
\[0\]=>
unicode\(8\) "[heredoc 1-5]*"
\[1\]=>
unicode\(8\) "[heredoc 1-5]*"
\[2\]=>
unicode\(8\) "[heredoc 1-5]*"
\[3\]=>
unicode\(8\) "[heredoc 1-5]*"
\[4\]=>
unicode\(8\) "[heredoc 1-5]*"
\[5\]=>
unicode\(8\) "[heredoc 1-5]*"
}
Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/shuffle_basic1.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/shuffle_basic1.phpt
+++ php-src/ext/standard/tests/array/shuffle_basic1.phpt
--TEST--
Test shuffle() function : basic functionality - array with default keys
--FILE--
<?php
/* Prototype : bool shuffle(array $array_arg)
* Description: Randomly shuffle the contents of an array
* Source code: ext/standard/array.c
*/
/*
* Test behaviour of shuffle when an array with default keys
* is passed to the 'array_arg' argument and check for the
* changes in the input array by printing the input array
* before and after shuffle() function is applied on it
*/
echo "*** Testing shuffle() : with arrays having default keys ***\n";
// Initialise the array with integers
$array_arg_int = array(0, 10, 20, 30, 40, 50, 60, 70, 80);
// Initialise the array with strings
$array_arg_strings = array("one", 'two', 'three', "four", "five", " ", 'six', '
', "seven");
/* Testing shuffle() function with array of integers */
// printing the input array with integers before the shuffle operation
echo "\n-- input array of integers before shuffle() function is applied --\n";
var_dump( $array_arg_int );
// applying shuffle() function on the input array of integers
echo "\n-- return value from shuffle() function --\n";
var_dump( shuffle($array_arg_int) ); // prints the return value from shuffle()
function
echo "\n-- resultant array after shuffle() function is applied --\n";
var_dump( $array_arg_int );
/* Testing shuffle() function with array of strings */
// printing the input array with strings before the shuffle operation
echo "\n-- input array of strings before shuffle() function is applied --\n";
var_dump( $array_arg_strings );
// applying shuffle() function on the input array of strings
echo "\n-- return value from shuffle() function --\n";
var_dump( shuffle($array_arg_strings) ); // prints the return value from
shuffle() function
echo "\n-- resultant array after shuffle() function is applied --\n";
var_dump( $array_arg_strings );
echo "Done";
?>
--EXPECTF--
*** Testing shuffle() : with arrays having default keys ***
-- input array of integers before shuffle() function is applied --
array(9) {
[0]=>
int(0)
[1]=>
int(10)
[2]=>
int(20)
[3]=>
int(30)
[4]=>
int(40)
[5]=>
int(50)
[6]=>
int(60)
[7]=>
int(70)
[8]=>
int(80)
}
-- return value from shuffle() function --
bool(true)
-- resultant array after shuffle() function is applied --
array(9) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
[3]=>
int(%d)
[4]=>
int(%d)
[5]=>
int(%d)
[6]=>
int(%d)
[7]=>
int(%d)
[8]=>
int(%d)
}
-- input array of strings before shuffle() function is applied --
array(9) {
[0]=>
string(3) "one"
[1]=>
string(3) "two"
[2]=>
string(5) "three"
[3]=>
string(4) "four"
[4]=>
string(4) "five"
[5]=>
string(1) " "
[6]=>
string(3) "six"
[7]=>
string(1) " "
[8]=>
string(5) "seven"
}
-- return value from shuffle() function --
bool(true)
-- resultant array after shuffle() function is applied --
array(9) {
[0]=>
string(%d) "%s"
[1]=>
string(%d) "%s"
[2]=>
string(%d) "%s"
[3]=>
string(%d) "%s"
[4]=>
string(%d) "%s"
[5]=>
string(%d) "%s"
[6]=>
string(%d) "%s"
[7]=>
string(%d) "%s"
[8]=>
string(%d) "%s"
}
Done
--UEXPECTF--
*** Testing shuffle() : with arrays having default keys ***
-- input array of integers before shuffle() function is applied --
array(9) {
[0]=>
int(0)
[1]=>
int(10)
[2]=>
int(20)
[3]=>
int(30)
[4]=>
int(40)
[5]=>
int(50)
[6]=>
int(60)
[7]=>
int(70)
[8]=>
int(80)
}
-- return value from shuffle() function --
bool(true)
-- resultant array after shuffle() function is applied --
array(9) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
[3]=>
int(%d)
[4]=>
int(%d)
[5]=>
int(%d)
[6]=>
int(%d)
[7]=>
int(%d)
[8]=>
int(%d)
}
-- input array of strings before shuffle() function is applied --
array(9) {
[0]=>
unicode(3) "one"
[1]=>
unicode(3) "two"
[2]=>
unicode(5) "three"
[3]=>
unicode(4) "four"
[4]=>
unicode(4) "five"
[5]=>
unicode(1) " "
[6]=>
unicode(3) "six"
[7]=>
unicode(1) " "
[8]=>
unicode(5) "seven"
}
-- return value from shuffle() function --
bool(true)
-- resultant array after shuffle() function is applied --
array(9) {
[0]=>
unicode(%d) "%s"
[1]=>
unicode(%d) "%s"
[2]=>
unicode(%d) "%s"
[3]=>
unicode(%d) "%s"
[4]=>
unicode(%d) "%s"
[5]=>
unicode(%d) "%s"
[6]=>
unicode(%d) "%s"
[7]=>
unicode(%d) "%s"
[8]=>
unicode(%d) "%s"
}
Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/shuffle_basic2.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/shuffle_basic2.phpt
+++ php-src/ext/standard/tests/array/shuffle_basic2.phpt
--TEST--
Test shuffle() function : basic functionality - with associative array
--FILE--
<?php
/* Prototype : bool shuffle(array $array_arg)
* Description: Randomly shuffle the contents of an array
* Source code: ext/standard/array.c
*/
/*
* Test behaviour of shuffle when an associative array is
* passed to the 'array_arg' argument and check for the
* changes in the input array by printing the input array
* before and after shuffle() function is applied on it
*/
echo "*** Testing shuffle() : with associative array ***\n";
// Initialise the associative array
$array_arg = array(
'one' => 1, 2 => 02, 'three' => 3,
4 => 4, '#5' => 5, 'SIX' => 6,
"seven" => 0x7, "#8" => 012, "nine" => 9
);
// printing the input array before the shuffle operation
echo "\n-- input array before shuffle() function is applied --\n";
var_dump( $array_arg );
// applying shuffle() function on the input array
echo "\n-- return value from shuffle() function --\n";
var_dump( shuffle($array_arg) ); // prints the return value from shuffle()
function
echo "\n-- resultant array after shuffle() function is applied --\n";
var_dump( $array_arg );
echo "Done";
?>
--EXPECTF--
*** Testing shuffle() : with associative array ***
-- input array before shuffle() function is applied --
array(9) {
["one"]=>
int(1)
[2]=>
int(2)
["three"]=>
int(3)
[4]=>
int(4)
["#5"]=>
int(5)
["SIX"]=>
int(6)
["seven"]=>
int(7)
["#8"]=>
int(10)
["nine"]=>
int(9)
}
-- return value from shuffle() function --
bool(true)
-- resultant array after shuffle() function is applied --
array(9) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
[3]=>
int(%d)
[4]=>
int(%d)
[5]=>
int(%d)
[6]=>
int(%d)
[7]=>
int(%d)
[8]=>
int(%d)
}
Done
--UEXPECTF--
*** Testing shuffle() : with associative array ***
-- input array before shuffle() function is applied --
array(9) {
[u"one"]=>
int(1)
[2]=>
int(2)
[u"three"]=>
int(3)
[4]=>
int(4)
[u"#5"]=>
int(5)
[u"SIX"]=>
int(6)
[u"seven"]=>
int(7)
[u"#8"]=>
int(10)
[u"nine"]=>
int(9)
}
-- return value from shuffle() function --
bool(true)
-- resultant array after shuffle() function is applied --
array(9) {
[0]=>
int(%d)
[1]=>
int(%d)
[2]=>
int(%d)
[3]=>
int(%d)
[4]=>
int(%d)
[5]=>
int(%d)
[6]=>
int(%d)
[7]=>
int(%d)
[8]=>
int(%d)
}
Done
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php