From: Robert Nicholson Date: Mon, 4 Feb 2008 00:05:24 +0000 (+0000) Subject: - added some new tests for arsort X-Git-Tag: RELEASE_1_3_1~140 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a9418da4fc71e65c7cb0c82896cddd813680dee4;p=php - added some new tests for arsort --- diff --git a/ext/standard/tests/array/arsort_error.phpt b/ext/standard/tests/array/arsort_error.phpt new file mode 100644 index 0000000000..676d8265ed --- /dev/null +++ b/ext/standard/tests/array/arsort_error.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test arsort() function : error conditions +--FILE-- + SORT_REGULAR, "SORT_STRING" => SORT_STRING, "SORT_NUMERIC" => SORT_NUMERIC); +$extra_arg = 10; + +// loop through $flag_value array and setting all possible flag values +foreach($flags as $key => $flag){ + echo "\nSort flag = $key\n"; + var_dump( arsort($array_arg,$flag, $extra_arg) ); + + // dump the input array to ensure that it wasn't changed + var_dump($array_arg); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing arsort() : error conditions *** + +-- Testing arsort() function with Zero arguments -- + +Warning: arsort() expects at least 1 parameter, 0 given in %sarsort_error.php on line %d +bool(false) + +-- Testing arsort() function with more than expected no. of arguments -- + +Sort flag = SORT_REGULAR + +Warning: arsort() expects at most 2 parameters, 3 given in %sarsort_error.php on line %d +bool(false) +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +Sort flag = SORT_STRING + +Warning: arsort() expects at most 2 parameters, 3 given in %sarsort_error.php on line %d +bool(false) +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} + +Sort flag = SORT_NUMERIC + +Warning: arsort() expects at most 2 parameters, 3 given in %sarsort_error.php on line %d +bool(false) +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation1.phpt b/ext/standard/tests/array/arsort_variation1.phpt new file mode 100644 index 0000000000..1545abe34e --- /dev/null +++ b/ext/standard/tests/array/arsort_variation1.phpt @@ -0,0 +1,399 @@ +--TEST-- +Test arsort() function : usage variations - unexpected values for 'array_arg' argument +--FILE-- + 0, + 1 => 1, + 2 => 12345, + 3 => -2345, + + // float data + 4 => 10.5, + 5 => -10.5, + 6 => 10.5e3, + 7 => 10.6E-2, + 8 => .5, + + // null data + 9 => NULL, + 10 => null, + + // boolean data + 11 => true, + 12 => false, + 13 => TRUE, + 14 => FALSE, + + // empty data + 15 => "", + 16 => '', + + // string data + 17 => "string", + 18 => 'string', + + // object data + 19 => new stdclass(), + + // undefined data + 20 => @undefined_var, + + // unset data + 21 => @unset_var, + + // resource variable + 22 => $fp + +); + +// loop though each element of the array and check the working of arsort() +// when $array arugment is supplied with different values from $unexpected_values +echo "\n-- Testing arsort() by supplying different unexpected values for 'array' argument --\n"; +echo "\n-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING --\n"; + +$counter = 1; +for($index = 0; $index < count($unexpected_values); $index ++) { + echo "-- Iteration $counter --\n"; + $value = $unexpected_values [$index]; + var_dump( arsort($value) ); // expecting : bool(false) + var_dump( arsort($value, SORT_REGULAR) ); // expecting : bool(false) + var_dump( arsort($value, SORT_NUMERIC) ); // expecting : bool(false) + var_dump( arsort($value, SORT_STRING) ); // expecting : bool(false) + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying different unexpected values for 'array' argument -- + +-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING -- +-- Iteration 1 -- + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 2 -- + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 3 -- + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 4 -- + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, integer given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 5 -- + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 6 -- + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 7 -- + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 8 -- + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 9 -- + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, double given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 10 -- + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 11 -- + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, null given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 12 -- + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 13 -- + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 14 -- + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 15 -- + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, boolean given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 16 -- + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 17 -- + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 18 -- + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 19 -- + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 20 -- + +Warning: arsort() expects parameter 1 to be array, object given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, object given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, object given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, object given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 21 -- + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 22 -- + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, string given in %sarsort_variation1.php on line %d +bool(false) +-- Iteration 23 -- + +Warning: arsort() expects parameter 1 to be array, resource given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, resource given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, resource given in %sarsort_variation1.php on line %d +bool(false) + +Warning: arsort() expects parameter 1 to be array, resource given in %sarsort_variation1.php on line %d +bool(false) +Done \ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation10.phpt b/ext/standard/tests/array/arsort_variation10.phpt new file mode 100644 index 0000000000..ec483df3ad --- /dev/null +++ b/ext/standard/tests/array/arsort_variation10.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test arsort() function : usage variations - sort octal values +--FILE-- + 01235, 0321 => 0321, 0345 => 0345, 066 => 066, 0772 => 0772, + 077 => 077, -066 => -066, -0345 => -0345, 0 => 0 +); + +echo "\n-- Testing arsort() by supplying octal value array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_oct_array; +var_dump( arsort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying octal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_oct_array; +var_dump( arsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying octal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_oct_array; +var_dump( arsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying octal value array, 'flag' value is defualt -- +bool(true) +array(9) { + [669]=> + int(669) + [506]=> + int(506) + [229]=> + int(229) + [209]=> + int(209) + [63]=> + int(63) + [54]=> + int(54) + [0]=> + int(0) + [-54]=> + int(-54) + [-229]=> + int(-229) +} + +-- Testing arsort() by supplying octal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [669]=> + int(669) + [506]=> + int(506) + [229]=> + int(229) + [209]=> + int(209) + [63]=> + int(63) + [54]=> + int(54) + [0]=> + int(0) + [-54]=> + int(-54) + [-229]=> + int(-229) +} + +-- Testing arsort() by supplying octal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [669]=> + int(669) + [506]=> + int(506) + [229]=> + int(229) + [209]=> + int(209) + [63]=> + int(63) + [54]=> + int(54) + [0]=> + int(0) + [-54]=> + int(-54) + [-229]=> + int(-229) +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation11.phpt b/ext/standard/tests/array/arsort_variation11.phpt new file mode 100644 index 0000000000..e8bfd772ee Binary files /dev/null and b/ext/standard/tests/array/arsort_variation11.phpt differ diff --git a/ext/standard/tests/array/arsort_variation2.phpt b/ext/standard/tests/array/arsort_variation2.phpt new file mode 100644 index 0000000000..ab04b44099 --- /dev/null +++ b/ext/standard/tests/array/arsort_variation2.phpt @@ -0,0 +1,308 @@ +--TEST-- +Test arsort() function : usage variations - unexpected values for 'sort_flags' argument +--FILE-- + 10, 2 => 2, 3 => 45); + +//array of values to iterate over +$unexpected_values = array( + + // int data +/*1*/ -2345, + + // float data +/*2*/ 10.5, + -10.5, + 10.5e2, + 10.6E-2, + .5, + + // null data +/*7*/ NULL, + null, + + // boolean data +/*9*/ true, + false, + TRUE, + FALSE, + + // empty data +/*13*/ "", + '', + + // string data +/*15*/ "string", + 'string', + + // object data +/*16*/ new stdclass(), + + // undefined data +/*17*/ @undefined_var, + + // unset data +/*18*/ @unset_var, + + // resource variable +/*19*/ $fp + +); + +// loop though each element of the array and check the working of arsort() +// when $flag arugment is supplied with different values from $unexpected_values +echo "\n-- Testing arsort() by supplying different unexpected values for 'sort_flags' argument --\n"; + +$counter = 1; +for($index = 0; $index < count($unexpected_values); $index ++) { + echo "-- Iteration $counter --\n"; + $value = $unexpected_values [$index]; + $temp_array = $unsorted_values; + var_dump( arsort($temp_array, $value) ); + var_dump($temp_array); + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying different unexpected values for 'sort_flags' argument -- +-- Iteration 1 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 2 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 3 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 4 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 5 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 6 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 7 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 8 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 9 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 10 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 11 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 12 -- +bool(true) +array(3) { + [3]=> + int(45) + [1]=> + int(10) + [2]=> + int(2) +} +-- Iteration 13 -- + +Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 14 -- + +Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 15 -- + +Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 16 -- + +Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 17 -- + +Warning: arsort() expects parameter 2 to be long, object given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 18 -- + +Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 19 -- + +Warning: arsort() expects parameter 2 to be long, string given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +-- Iteration 20 -- + +Warning: arsort() expects parameter 2 to be long, resource given in %sarsort_variation2.php on line %d +bool(false) +array(3) { + [1]=> + int(10) + [2]=> + int(2) + [3]=> + int(45) +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation3.phpt b/ext/standard/tests/array/arsort_variation3.phpt new file mode 100644 index 0000000000..ada9dedb1d --- /dev/null +++ b/ext/standard/tests/array/arsort_variation3.phpt @@ -0,0 +1,61 @@ +--TEST-- +Test arsort() function : usage variations - sort integer/float values +--FILE-- + 11, 2 => -11, 3 => 21, 4 => -21, 5 => 31, 6 => -31, 7 => 0, 8 => 41, 10 =>-41), + + // float value array + array(1 => 10.5, 2 => -10.5, 3 => 10.5e2, 4 => 10.6E-2, 5 => .5, 6 => .0001, 7 => -.1), + + // mixed value array + array(1 => .0001, 2 => .0021, 3 => -.01, 4 => -1, 5 => 0, 6 => .09, 7 => 2, 8 => -.9, 9 => 10.6E-2, 10 => -10.6E-2, 11 => 33), + + // array values contains minimum and maximum ranges + array(1 => 2147483647, 2 => 2147483648, 3 => -2147483647, 4 => -2147483648, 5 => -0, 6 => 0, 7 => -2147483649) +); + +// set of possible flag values +$flag_value = array("SORT_REGULAR" => SORT_REGULAR, "SORT_NUMERIC" => SORT_NUMERIC); + +$count = 1; +echo "\n-- Testing arsort() by supplying various integer/float arrays --\n"; + +// loop through to test arsort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(arsort($temp_array) ); + var_dump($temp_array); + + // loop through $flag_value array and setting all possible flag values + foreach($flag_value as $key => $flag){ + echo "- Sort_flag = $key -\n"; + $temp_array = $array; + var_dump(arsort($temp_array, $flag) ); + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> diff --git a/ext/standard/tests/array/arsort_variation4.phpt b/ext/standard/tests/array/arsort_variation4.phpt new file mode 100644 index 0000000000..a76a180f40 --- /dev/null +++ b/ext/standard/tests/array/arsort_variation4.phpt @@ -0,0 +1,79 @@ +--TEST-- +Test arsort() function : usage variations - sort reference variables +--FILE-- + &$value1 , 2 => &$value2, 3 => &$value3); + +echo "\n-- Testing arsort() by supplying reference variable array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_numerics; +var_dump( arsort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying reference variable array, 'flag' = SORT_REGULAR --\n"; +$temp_array = &$unsorted_numerics; +var_dump( arsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing arsort() by supplying reference variable array, 'flag' = SORT_NUMERIC --\n"; +$temp_array = &$unsorted_numerics; +var_dump( arsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() :usage variations *** + +-- Testing arsort() by supplying reference variable array, 'flag' value is defualt -- +bool(true) +array(3) { + [3]=> + &int(555) + [1]=> + &int(100) + [2]=> + &int(33) +} + +-- Testing arsort() by supplying reference variable array, 'flag' = SORT_REGULAR -- +bool(true) +array(3) { + [3]=> + &int(555) + [1]=> + &int(100) + [2]=> + &int(33) +} + +-- Testing arsort() by supplying reference variable array, 'flag' = SORT_NUMERIC -- +bool(true) +array(3) { + [3]=> + &int(555) + [1]=> + &int(100) + [2]=> + &int(33) +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation5.phpt b/ext/standard/tests/array/arsort_variation5.phpt new file mode 100644 index 0000000000..a0392d63f5 --- /dev/null +++ b/ext/standard/tests/array/arsort_variation5.phpt @@ -0,0 +1,248 @@ +--TEST-- +Test arsort() function : usage variations - sort strings +--FILE-- + null, "NULL" => NULL, "\a" => "\a", "\cx" => "\cx", "\e" => "\e", + "\f" => "\f", "\n" =>"\n", "\r" => "\r", "\t" => "\t", "\xhh" => "\xhh", + "\ddd" => "\ddd", "\v" => "\v" + ), + + // array contains combination of capital/small letters + array ('l' => "lemoN", 'O' => "Orange", 'b' => "banana", 'a' => "apple", 'Te' => "Test", + 'T' => "TTTT", 't' => "ttt", 'w' => "ww", 'x' => "x", 'X' => "X", 'o' => "oraNGe", + 'B' => "BANANA" + ) +); + +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING); + +$count = 1; +echo "\n-- Testing arsort() by supplying various string arrays --\n"; + +// loop through to test arsort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(arsort($temp_array) ); // expecting : bool(true) + var_dump($temp_array); + + // loop through $flags array and setting all possible flag values + foreach($flags as $key => $flag){ + echo "- Sort_flag = $key -\n"; + $temp_array = $array; + var_dump(arsort($temp_array, $flag) ); // expecting : bool(true) + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying various string arrays -- + +-- Iteration 1 -- +- With default sort_flag - +bool(true) +array(12) { + ["\xhh"]=> + string(4) "\xhh" + ["\e"]=> + string(2) "\e" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + ["null"]=> + NULL + ["NULL"]=> + NULL +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(12) { + ["\xhh"]=> + string(4) "\xhh" + ["\e"]=> + string(2) "\e" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + ["null"]=> + NULL + ["NULL"]=> + NULL +} +- Sort_flag = SORT_STRING - +bool(true) +array(12) { + ["\xhh"]=> + string(4) "\xhh" + ["\e"]=> + string(2) "\e" + ["\ddd"]=> + string(4) "\ddd" + ["\cx"]=> + string(3) "\cx" + ["\a"]=> + string(2) "\a" + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + [" "]=> + string(1) " " + [" +"]=> + string(1) " +" + [" "]=> + string(1) " " + ["null"]=> + NULL + ["NULL"]=> + NULL +} + +-- Iteration 2 -- +- With default sort_flag - +bool(true) +array(12) { + ["x"]=> + string(1) "x" + ["w"]=> + string(2) "ww" + ["t"]=> + string(3) "ttt" + ["o"]=> + string(6) "oraNGe" + ["l"]=> + string(5) "lemoN" + ["b"]=> + string(6) "banana" + ["a"]=> + string(5) "apple" + ["X"]=> + string(1) "X" + ["Te"]=> + string(4) "Test" + ["T"]=> + string(4) "TTTT" + ["O"]=> + string(6) "Orange" + ["B"]=> + string(6) "BANANA" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(12) { + ["x"]=> + string(1) "x" + ["w"]=> + string(2) "ww" + ["t"]=> + string(3) "ttt" + ["o"]=> + string(6) "oraNGe" + ["l"]=> + string(5) "lemoN" + ["b"]=> + string(6) "banana" + ["a"]=> + string(5) "apple" + ["X"]=> + string(1) "X" + ["Te"]=> + string(4) "Test" + ["T"]=> + string(4) "TTTT" + ["O"]=> + string(6) "Orange" + ["B"]=> + string(6) "BANANA" +} +- Sort_flag = SORT_STRING - +bool(true) +array(12) { + ["x"]=> + string(1) "x" + ["w"]=> + string(2) "ww" + ["t"]=> + string(3) "ttt" + ["o"]=> + string(6) "oraNGe" + ["l"]=> + string(5) "lemoN" + ["b"]=> + string(6) "banana" + ["a"]=> + string(5) "apple" + ["X"]=> + string(1) "X" + ["Te"]=> + string(4) "Test" + ["T"]=> + string(4) "TTTT" + ["O"]=> + string(6) "Orange" + ["B"]=> + string(6) "BANANA" +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation6.phpt b/ext/standard/tests/array/arsort_variation6.phpt new file mode 100644 index 0000000000..687b20a714 --- /dev/null +++ b/ext/standard/tests/array/arsort_variation6.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test arsort() function : usage variations - sort hexadecimal values +--FILE-- + 0x1AB, 0xFFF => 0xFFF, 0xF => 0xF, 0xFF => 0xFF, 0x2AA => 0x2AA, 0xBB => 0xBB, + 0x1ab => 0x1ab, 0xff => 0xff, -0xff => -0xFF, 0 => 0, -0x2aa => -0x2aa + ); + +echo "\n-- Testing arsort() by supplying hexadecimal value array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_hex_array; +var_dump(arsort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_hex_array; +var_dump(arsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_hex_array; +var_dump(arsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying hexadecimal value array, 'flag' value is defualt -- +bool(true) +array(9) { + [4095]=> + int(4095) + [682]=> + int(682) + [427]=> + int(427) + [255]=> + int(255) + [187]=> + int(187) + [15]=> + int(15) + [0]=> + int(0) + [-255]=> + int(-255) + [-682]=> + int(-682) +} + +-- Testing arsort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [4095]=> + int(4095) + [682]=> + int(682) + [427]=> + int(427) + [255]=> + int(255) + [187]=> + int(187) + [15]=> + int(15) + [0]=> + int(0) + [-255]=> + int(-255) + [-682]=> + int(-682) +} + +-- Testing arsort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [4095]=> + int(4095) + [682]=> + int(682) + [427]=> + int(427) + [255]=> + int(255) + [187]=> + int(187) + [15]=> + int(15) + [0]=> + int(0) + [-255]=> + int(-255) + [-682]=> + int(-682) +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation7.phpt b/ext/standard/tests/array/arsort_variation7.phpt new file mode 100644 index 0000000000..97195b709f --- /dev/null +++ b/ext/standard/tests/array/arsort_variation7.phpt @@ -0,0 +1,98 @@ +--TEST-- +Test arsort() function : usage variations - sort bool values +--FILE-- + true, 2 => false, 3 => TRUE, 4 => FALSE); + +echo "\n-- Testing arsort() by supplying bool value array, 'flag' value is defualt --\n"; +$temp_array = $bool_values; +var_dump(arsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying bool value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $bool_values; +var_dump(arsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying bool value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $bool_values; +var_dump(arsort($temp_array, SORT_NUMERIC) ); +var_dump($temp_array); + +echo "\n-- Testing arsort() by supplying bool value array, 'flag' value is SORT_STRING --\n"; +$temp_array = $bool_values; +var_dump(arsort($temp_array, SORT_STRING) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying bool value array, 'flag' value is defualt -- +bool(true) +array(4) { + [3]=> + bool(true) + [1]=> + bool(true) + [4]=> + bool(false) + [2]=> + bool(false) +} + +-- Testing arsort() by supplying bool value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(4) { + [3]=> + bool(true) + [1]=> + bool(true) + [4]=> + bool(false) + [2]=> + bool(false) +} + +-- Testing arsort() by supplying bool value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(4) { + [3]=> + bool(true) + [1]=> + bool(true) + [4]=> + bool(false) + [2]=> + bool(false) +} + +-- Testing arsort() by supplying bool value array, 'flag' value is SORT_STRING -- +bool(true) +array(4) { + [3]=> + bool(true) + [1]=> + bool(true) + [4]=> + bool(false) + [2]=> + bool(false) +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation8.phpt b/ext/standard/tests/array/arsort_variation8.phpt new file mode 100644 index 0000000000..c2473160c9 --- /dev/null +++ b/ext/standard/tests/array/arsort_variation8.phpt @@ -0,0 +1,180 @@ +--TEST-- +Test arsort() function : usage variations - sort array with diff. sub arrays, 'sort_flags' as default/SORT_REGULAR +--FILE-- + array(), + + // array contains null sub array + "array[1]" => array( "sub_array[1][0]" => array() ), + + // array of arrays along with some values + "array[2]" => array("data[2,0]" => 44, "data[2,1]" => 11, "sub_array[2][0] " => array(64,61) ), + + // array contains sub arrays + "array[3]" => array ( "sub_array[3][0]" => array(33,-5,6), "sub_array[3][1]" => array(11), + "sub_array[3][2]" => array(22,-55), "sub_array[3][3]" => array() ) +); + + +$count = 1; +echo "\n-- Testing arsort() by supplying various arrays containing sub arrays --\n"; + +// loop through to test arsort() with different arrays +foreach ($various_arrays as $array) { + + echo "\n-- Iteration $count --\n"; + // testing arsort() function by supplying different arrays, flag value is default + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(arsort($temp_array) ); + var_dump($temp_array); + + // testing arsort() function by supplying different arrays, flag value = SORT_REGULAR + echo "- Sort_flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump(arsort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying various arrays containing sub arrays -- + +-- Iteration 1 -- +- With default sort_flag - +bool(true) +array(0) { +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(0) { +} + +-- Iteration 2 -- +- With default sort_flag - +bool(true) +array(1) { + ["sub_array[1][0]"]=> + array(0) { + } +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(1) { + ["sub_array[1][0]"]=> + array(0) { + } +} + +-- Iteration 3 -- +- With default sort_flag - +bool(true) +array(3) { + ["sub_array[2][0] "]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + ["data[2,0]"]=> + int(44) + ["data[2,1]"]=> + int(11) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(3) { + ["sub_array[2][0] "]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + ["data[2,0]"]=> + int(44) + ["data[2,1]"]=> + int(11) +} + +-- Iteration 4 -- +- With default sort_flag - +bool(true) +array(4) { + ["sub_array[3][0]"]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + ["sub_array[3][2]"]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + ["sub_array[3][1]"]=> + array(1) { + [0]=> + int(11) + } + ["sub_array[3][3]"]=> + array(0) { + } +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(4) { + ["sub_array[3][0]"]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + ["sub_array[3][2]"]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + ["sub_array[3][1]"]=> + array(1) { + [0]=> + int(11) + } + ["sub_array[3][3]"]=> + array(0) { + } +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/arsort_variation9.phpt b/ext/standard/tests/array/arsort_variation9.phpt new file mode 100644 index 0000000000..a034db5d9a --- /dev/null +++ b/ext/standard/tests/array/arsort_variation9.phpt @@ -0,0 +1,258 @@ +--TEST-- +Test arsort() function : usage variations - sorting arrays with/without keys, 'sort_flags' as default/SORT_REGULAR +--FILE-- + 55, 66, 22, 33, 11), + array ("a" => "orange", "banana", "c" => "apple"), + array(1, 2, 3, 4, 5, 6), + array("first", 5 => "second", "third"), + array(1, 1, 8 => 1, 4 => 1, 19, 3 => 13), + array('bar' => 'baz', "foo" => 1), + array('a'=>1,'b'=>array('e'=>2,'f'=>3),'c'=>array('g'=>4),'d'=>5), +); + +$count = 1; +echo "\n-- Testing arsort() by supplying various arrays with key values --\n"; + +// loop through to test arsort() with different arrays, +// to test the new keys for the elements in the sorted array +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With default sort_flag -\n"; + $temp_array = $array; + var_dump(arsort($temp_array) ); + var_dump($temp_array); + + echo "- Sort_flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump(arsort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing arsort() : usage variations *** + +-- Testing arsort() by supplying various arrays with key values -- + +-- Iteration 1 -- +- With default sort_flag - +bool(true) +array(5) { + [6]=> + int(66) + [5]=> + int(55) + [8]=> + int(33) + [7]=> + int(22) + [9]=> + int(11) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(5) { + [6]=> + int(66) + [5]=> + int(55) + [8]=> + int(33) + [7]=> + int(22) + [9]=> + int(11) +} + +-- Iteration 2 -- +- With default sort_flag - +bool(true) +array(3) { + ["a"]=> + string(6) "orange" + [0]=> + string(6) "banana" + ["c"]=> + string(5) "apple" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(3) { + ["a"]=> + string(6) "orange" + [0]=> + string(6) "banana" + ["c"]=> + string(5) "apple" +} + +-- Iteration 3 -- +- With default sort_flag - +bool(true) +array(6) { + [5]=> + int(6) + [4]=> + int(5) + [3]=> + int(4) + [2]=> + int(3) + [1]=> + int(2) + [0]=> + int(1) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(6) { + [5]=> + int(6) + [4]=> + int(5) + [3]=> + int(4) + [2]=> + int(3) + [1]=> + int(2) + [0]=> + int(1) +} + +-- Iteration 4 -- +- With default sort_flag - +bool(true) +array(3) { + [6]=> + string(5) "third" + [5]=> + string(6) "second" + [0]=> + string(5) "first" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(3) { + [6]=> + string(5) "third" + [5]=> + string(6) "second" + [0]=> + string(5) "first" +} + +-- Iteration 5 -- +- With default sort_flag - +bool(true) +array(6) { + [9]=> + int(19) + [3]=> + int(13) + [4]=> + int(1) + [8]=> + int(1) + [1]=> + int(1) + [0]=> + int(1) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(6) { + [9]=> + int(19) + [3]=> + int(13) + [4]=> + int(1) + [8]=> + int(1) + [1]=> + int(1) + [0]=> + int(1) +} + +-- Iteration 6 -- +- With default sort_flag - +bool(true) +array(2) { + ["foo"]=> + int(1) + ["bar"]=> + string(3) "baz" +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(2) { + ["foo"]=> + int(1) + ["bar"]=> + string(3) "baz" +} + +-- Iteration 7 -- +- With default sort_flag - +bool(true) +array(4) { + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["d"]=> + int(5) + ["a"]=> + int(1) +} +- Sort_flag = SORT_REGULAR - +bool(true) +array(4) { + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["d"]=> + int(5) + ["a"]=> + int(1) +} +Done \ No newline at end of file