From: Raghubansh Kumar Date: Sat, 27 Oct 2007 12:27:49 +0000 (+0000) Subject: New testcases for shuffle() function X-Git-Tag: RELEASE_1_3_1~800 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a2b4c29ee86032a6011f5394e97b02a203da137e;p=php New testcases for shuffle() function --- diff --git a/ext/standard/tests/array/shuffle_basic1.phpt b/ext/standard/tests/array/shuffle_basic1.phpt new file mode 100644 index 0000000000..4bff667a37 --- /dev/null +++ b/ext/standard/tests/array/shuffle_basic1.phpt @@ -0,0 +1,149 @@ +--TEST-- +Test shuffle() function : basic functionality - array with default keys +--FILE-- + +--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 diff --git a/ext/standard/tests/array/shuffle_basic2.phpt b/ext/standard/tests/array/shuffle_basic2.phpt new file mode 100644 index 0000000000..01fc1d4c7a --- /dev/null +++ b/ext/standard/tests/array/shuffle_basic2.phpt @@ -0,0 +1,88 @@ +--TEST-- +Test shuffle() function : basic functionality - with associative array +--FILE-- + 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 diff --git a/ext/standard/tests/array/shuffle_error.phpt b/ext/standard/tests/array/shuffle_error.phpt new file mode 100644 index 0000000000..4df3467a0e --- /dev/null +++ b/ext/standard/tests/array/shuffle_error.phpt @@ -0,0 +1,53 @@ +--TEST-- +Test shuffle() function : error conditions +--FILE-- + 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 diff --git a/ext/standard/tests/array/shuffle_variation1.phpt b/ext/standard/tests/array/shuffle_variation1.phpt new file mode 100644 index 0000000000..597c1e92ec --- /dev/null +++ b/ext/standard/tests/array/shuffle_variation1.phpt @@ -0,0 +1,212 @@ +--TEST-- +Test shuffle() function : usage variations - unexpected values for 'array_arg' argument +--FILE-- + +--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 diff --git a/ext/standard/tests/array/shuffle_variation2.phpt b/ext/standard/tests/array/shuffle_variation2.phpt new file mode 100644 index 0000000000..f9fdccbd78 --- /dev/null +++ b/ext/standard/tests/array/shuffle_variation2.phpt @@ -0,0 +1,211 @@ +--TEST-- +Test shuffle() function : usage variation - with MultiDimensional array +--FILE-- + +--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 diff --git a/ext/standard/tests/array/shuffle_variation3.phpt b/ext/standard/tests/array/shuffle_variation3.phpt new file mode 100644 index 0000000000..3e20383aff --- /dev/null +++ b/ext/standard/tests/array/shuffle_variation3.phpt @@ -0,0 +1,232 @@ +--TEST-- +Test shuffle() function : usage variation - arrays with diff. types of values +--FILE-- + +--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 diff --git a/ext/standard/tests/array/shuffle_variation4.phpt b/ext/standard/tests/array/shuffle_variation4.phpt new file mode 100644 index 0000000000..34c1a06449 --- /dev/null +++ b/ext/standard/tests/array/shuffle_variation4.phpt @@ -0,0 +1,230 @@ +--TEST-- +Test shuffle() function : usage variation - associative arrays with diff. types of values +--FILE-- + 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 diff --git a/ext/standard/tests/array/shuffle_variation5.phpt b/ext/standard/tests/array/shuffle_variation5.phpt new file mode 100644 index 0000000000..3428e5678a --- /dev/null +++ b/ext/standard/tests/array/shuffle_variation5.phpt @@ -0,0 +1,119 @@ +--TEST-- +Test shuffle() function : usage variation - arrays with diff heredoc strings +--FILE-- + "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