From 09e35a5107ab7bc121984d2c974e265cda84137f Mon Sep 17 00:00:00 2001 From: Raghubansh Kumar Date: Mon, 12 Nov 2007 15:54:35 +0000 Subject: [PATCH] New testcases for krsort() function --- ext/standard/tests/array/krsort_basic.phpt | 132 ++++++ ext/standard/tests/array/krsort_error.phpt | 78 ++++ ext/standard/tests/array/krsort_object.phpt | 242 +++++++++++ .../tests/array/krsort_variation1.phpt | 397 ++++++++++++++++++ .../tests/array/krsort_variation10.phpt | 98 +++++ .../tests/array/krsort_variation11.phpt | 81 ++++ .../tests/array/krsort_variation2.phpt | 307 ++++++++++++++ .../tests/array/krsort_variation3.phpt | 303 +++++++++++++ .../tests/array/krsort_variation4.phpt | 114 +++++ .../tests/array/krsort_variation5.phpt | 236 +++++++++++ .../tests/array/krsort_variation6.phpt | 114 +++++ .../tests/array/krsort_variation7.phpt | 177 ++++++++ .../tests/array/krsort_variation8.phpt | Bin 0 -> 3328 bytes .../tests/array/krsort_variation9.phpt | 257 ++++++++++++ 14 files changed, 2536 insertions(+) create mode 100644 ext/standard/tests/array/krsort_basic.phpt create mode 100644 ext/standard/tests/array/krsort_error.phpt create mode 100644 ext/standard/tests/array/krsort_object.phpt create mode 100644 ext/standard/tests/array/krsort_variation1.phpt create mode 100644 ext/standard/tests/array/krsort_variation10.phpt create mode 100644 ext/standard/tests/array/krsort_variation11.phpt create mode 100644 ext/standard/tests/array/krsort_variation2.phpt create mode 100644 ext/standard/tests/array/krsort_variation3.phpt create mode 100644 ext/standard/tests/array/krsort_variation4.phpt create mode 100644 ext/standard/tests/array/krsort_variation5.phpt create mode 100644 ext/standard/tests/array/krsort_variation6.phpt create mode 100644 ext/standard/tests/array/krsort_variation7.phpt create mode 100644 ext/standard/tests/array/krsort_variation8.phpt create mode 100644 ext/standard/tests/array/krsort_variation9.phpt diff --git a/ext/standard/tests/array/krsort_basic.phpt b/ext/standard/tests/array/krsort_basic.phpt new file mode 100644 index 0000000000..913256897b --- /dev/null +++ b/ext/standard/tests/array/krsort_basic.phpt @@ -0,0 +1,132 @@ +--TEST-- +Test krsort() function : basic functionality +--FILE-- + "l", "orange" => "o", "banana" => "b" ); +// an array containing unsorted numeric values with indices +$unsorted_numerics = array( 100 => 4, 33 => 3, 555 => 2, 22 => 1 ); + +echo "\n-- Testing krsort() by supplying string array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_strings; +var_dump( krsort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying numeric array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_numerics; +var_dump( krsort($temp_array) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying string array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_strings; +var_dump( krsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying numeric array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $unsorted_numerics; +var_dump( krsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying string array, 'flag' = SORT_STRING --\n"; +$temp_array = $unsorted_strings; +var_dump( krsort($temp_array, SORT_STRING) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "\n-- Testing krsort() by supplying numeric array, 'flag' = SORT_NUMERIC --\n"; +$temp_array = $unsorted_numerics; +var_dump( krsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump( $temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : basic functionality *** + +-- Testing krsort() by supplying string array, 'flag' value is defualt -- +bool(true) +array(3) { + ["orange"]=> + string(1) "o" + ["lemon"]=> + string(1) "l" + ["banana"]=> + string(1) "b" +} + +-- Testing krsort() by supplying numeric array, 'flag' value is defualt -- +bool(true) +array(4) { + [555]=> + int(2) + [100]=> + int(4) + [33]=> + int(3) + [22]=> + int(1) +} + +-- Testing krsort() by supplying string array, 'flag' = SORT_REGULAR -- +bool(true) +array(3) { + ["orange"]=> + string(1) "o" + ["lemon"]=> + string(1) "l" + ["banana"]=> + string(1) "b" +} + +-- Testing krsort() by supplying numeric array, 'flag' = SORT_REGULAR -- +bool(true) +array(4) { + [555]=> + int(2) + [100]=> + int(4) + [33]=> + int(3) + [22]=> + int(1) +} + +-- Testing krsort() by supplying string array, 'flag' = SORT_STRING -- +bool(true) +array(3) { + ["orange"]=> + string(1) "o" + ["lemon"]=> + string(1) "l" + ["banana"]=> + string(1) "b" +} + +-- Testing krsort() by supplying numeric array, 'flag' = SORT_NUMERIC -- +bool(true) +array(4) { + [555]=> + int(2) + [100]=> + int(4) + [33]=> + int(3) + [22]=> + int(1) +} +Done diff --git a/ext/standard/tests/array/krsort_error.phpt b/ext/standard/tests/array/krsort_error.phpt new file mode 100644 index 0000000000..1bca5f928d --- /dev/null +++ b/ext/standard/tests/array/krsort_error.phpt @@ -0,0 +1,78 @@ +--TEST-- +Test krsort() function : error conditions +--FILE-- + 1, 2 => 2); +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_STRING" => SORT_STRING, "SORT_NUMERIC" => SORT_NUMERIC); +$extra_arg = 10; + +// loop through $flag_value array and call krsort with all possible sort flag values +foreach($flags as $key => $flag){ + echo "\n- Sort flag = $key -\n"; + $temp_array = $array_arg; + var_dump( krsort($temp_array,$flag, $extra_arg) ); + var_dump($temp_array); +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing krsort() : error conditions *** + +-- Testing krsort() function with zero arguments -- + +Warning: krsort() expects at least 1 parameter, 0 given in %s on line %d +bool(false) + +-- Testing krsort() function with more than expected no. of arguments -- + +- Sort flag = SORT_REGULAR - + +Warning: krsort() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +array(2) { + [1]=> + int(1) + [2]=> + int(2) +} + +- Sort flag = SORT_STRING - + +Warning: krsort() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +array(2) { + [1]=> + int(1) + [2]=> + int(2) +} + +- Sort flag = SORT_NUMERIC - + +Warning: krsort() expects at most 2 parameters, 3 given in %s on line %d +bool(false) +array(2) { + [1]=> + int(1) + [2]=> + int(2) +} +Done diff --git a/ext/standard/tests/array/krsort_object.phpt b/ext/standard/tests/array/krsort_object.phpt new file mode 100644 index 0000000000..36d8589a82 --- /dev/null +++ b/ext/standard/tests/array/krsort_object.phpt @@ -0,0 +1,242 @@ +--TEST-- +Test krsort() function : object functionality - sort objects +--FILE-- +class_value = $value; + } +} + +// class declaration for string objects +class String +{ + public $class_value; + // initializing object member value + function __construct($value){ + $this->class_value = $value; + } + + // return string value + function __tostring() { + return (string)$this->value; + } + +} + +// array of integer objects with different key values +$unsorted_int_obj = array ( + 10 => new Integer(11), 20 => new Integer(66), + 3 => new Integer(23), 4 => new Integer(-5), + 50 => new Integer(0.001), 6 => new Integer(0) +); + +// array of string objects with different key values +$unsorted_str_obj = array ( + "axx" => new String("axx"), "t" => new String("t"), + "w" => new String("w"), "py" => new String("py"), + "apple" => new String("apple"), "Orange" => new String("Orange"), + "Lemon" => new String("Lemon"), "aPPle" => new String("aPPle") +); + + +echo "\n-- Testing krsort() by supplying various object arrays, 'flag' value is defualt --\n"; + +// testing krsort() function by supplying integer object array, flag value is defualt +$temp_array = $unsorted_int_obj; +var_dump(krsort($temp_array) ); +var_dump($temp_array); + +// testing krsort() function by supplying string object array, flag value is defualt +$temp_array = $unsorted_str_obj; +var_dump(krsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying various object arrays, 'flag' value is SORT_REGULAR --\n"; +// testing krsort() function by supplying integer object array, flag value = SORT_REGULAR +$temp_array = $unsorted_int_obj; +var_dump(krsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +// testing krsort() function by supplying string object array, flag value = SORT_REGULAR +$temp_array = $unsorted_str_obj; +var_dump(krsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : object functionality *** + +-- Testing krsort() by supplying various object arrays, 'flag' value is defualt -- +bool(true) +array(6) { + [50]=> + object(Integer)#%d (1) { + ["class_value"]=> + float(0.001) + } + [20]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(66) + } + [10]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(11) + } + [6]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(0) + } + [4]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(-5) + } + [3]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(23) + } +} +bool(true) +array(8) { + ["w"]=> + object(String)#%d (1) { + ["class_value"]=> + string(1) "w" + } + ["t"]=> + object(String)#%d (1) { + ["class_value"]=> + string(1) "t" + } + ["py"]=> + object(String)#%d (1) { + ["class_value"]=> + string(2) "py" + } + ["axx"]=> + object(String)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + ["apple"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + ["aPPle"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + ["Orange"]=> + object(String)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + ["Lemon"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } +} + +-- Testing krsort() by supplying various object arrays, 'flag' value is SORT_REGULAR -- +bool(true) +array(6) { + [50]=> + object(Integer)#%d (1) { + ["class_value"]=> + float(0.001) + } + [20]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(66) + } + [10]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(11) + } + [6]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(0) + } + [4]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(-5) + } + [3]=> + object(Integer)#%d (1) { + ["class_value"]=> + int(23) + } +} +bool(true) +array(8) { + ["w"]=> + object(String)#%d (1) { + ["class_value"]=> + string(1) "w" + } + ["t"]=> + object(String)#%d (1) { + ["class_value"]=> + string(1) "t" + } + ["py"]=> + object(String)#%d (1) { + ["class_value"]=> + string(2) "py" + } + ["axx"]=> + object(String)#%d (1) { + ["class_value"]=> + string(3) "axx" + } + ["apple"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "apple" + } + ["aPPle"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "aPPle" + } + ["Orange"]=> + object(String)#%d (1) { + ["class_value"]=> + string(6) "Orange" + } + ["Lemon"]=> + object(String)#%d (1) { + ["class_value"]=> + string(5) "Lemon" + } +} +Done diff --git a/ext/standard/tests/array/krsort_variation1.phpt b/ext/standard/tests/array/krsort_variation1.phpt new file mode 100644 index 0000000000..e4cbaf8d2c --- /dev/null +++ b/ext/standard/tests/array/krsort_variation1.phpt @@ -0,0 +1,397 @@ +--TEST-- +Test krsort() function : usage variations - unexpected values for 'array' argument +--FILE-- + +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying different unexpected values for 'array' argument -- + +-- Flag values are defualt, SORT_REGULAR, SORT_NUMERIC, SORT_STRING -- +-- Iteration 1 -- + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, integer given in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, double given in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +-- Iteration 11 -- + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, null given in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, boolean given in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: krsort() expects parameter 1 to be array, object given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, object given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, object given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, object given in %s on line %d +bool(false) +-- Iteration 21 -- + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 22 -- + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, string given in %s on line %d +bool(false) +-- Iteration 23 -- + +Warning: krsort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) + +Warning: krsort() expects parameter 1 to be array, resource given in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/krsort_variation10.phpt b/ext/standard/tests/array/krsort_variation10.phpt new file mode 100644 index 0000000000..f56d2870b8 --- /dev/null +++ b/ext/standard/tests/array/krsort_variation10.phpt @@ -0,0 +1,98 @@ +--TEST-- +Test krsort() function : usage variations - sort heredoc strings +--FILE-- + "Heredoc", + $simple_heredoc2 => "HEREDOC", + $multiline_heredoc => "heredoc string\twith!@# and 123\nTest this!!!" +); + +echo "\n-- Testing krsort() by supplying heredoc string array, 'flag' value is defualt --\n"; +$temp_array = $array; +var_dump(krsort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying heredoc string array, 'flag' = SORT_REGULAR --\n"; +$temp_array = $array; +var_dump(krsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying heredoc string array, 'flag' = SORT_STRING --\n"; +$temp_array = $array; +var_dump(krsort($temp_array, SORT_STRING) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying heredoc string array, 'flag' value is defualt -- +bool(true) +array(3) { + ["heredoc string with!@# and 123 +Test this!!!"]=> + string(43) "heredoc string with!@# and 123 +Test this!!!" + ["Heredoc"]=> + string(7) "Heredoc" + ["HEREDOC"]=> + string(7) "HEREDOC" +} + +-- Testing krsort() by supplying heredoc string array, 'flag' = SORT_REGULAR -- +bool(true) +array(3) { + ["heredoc string with!@# and 123 +Test this!!!"]=> + string(43) "heredoc string with!@# and 123 +Test this!!!" + ["Heredoc"]=> + string(7) "Heredoc" + ["HEREDOC"]=> + string(7) "HEREDOC" +} + +-- Testing krsort() by supplying heredoc string array, 'flag' = SORT_STRING -- +bool(true) +array(3) { + ["heredoc string with!@# and 123 +Test this!!!"]=> + string(43) "heredoc string with!@# and 123 +Test this!!!" + ["Heredoc"]=> + string(7) "Heredoc" + ["HEREDOC"]=> + string(7) "HEREDOC" +} +Done diff --git a/ext/standard/tests/array/krsort_variation11.phpt b/ext/standard/tests/array/krsort_variation11.phpt new file mode 100644 index 0000000000..0cfa4821a2 --- /dev/null +++ b/ext/standard/tests/array/krsort_variation11.phpt @@ -0,0 +1,81 @@ +--TEST-- +Test krsort() function : usage variations - sort bool values +--FILE-- + true, false => false, TRUE => TRUE, FALSE => FALSE); + +echo "\n-- Testing krsort() by supplying boolean value array, 'flag' value is defualt --\n"; +$temp_array = $bool_values; +var_dump(krsort($temp_array) ); +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $bool_values; +var_dump(krsort($temp_array, SORT_REGULAR) ); +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $bool_values; +var_dump(krsort($temp_array, SORT_NUMERIC) ); +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_STRING --\n"; +$temp_array = $bool_values; +var_dump(krsort($temp_array, SORT_STRING) ); +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying boolean value array, 'flag' value is defualt -- +bool(true) +array(2) { + [1]=> + bool(true) + [0]=> + bool(false) +} + +-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(2) { + [1]=> + bool(true) + [0]=> + bool(false) +} + +-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(2) { + [1]=> + bool(true) + [0]=> + bool(false) +} + +-- Testing krsort() by supplying boolean value array, 'flag' value is SORT_STRING -- +bool(true) +array(2) { + [1]=> + bool(true) + [0]=> + bool(false) +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/krsort_variation2.phpt b/ext/standard/tests/array/krsort_variation2.phpt new file mode 100644 index 0000000000..c567f766cb --- /dev/null +++ b/ext/standard/tests/array/krsort_variation2.phpt @@ -0,0 +1,307 @@ +--TEST-- +Test krsort() function : usage variations - unexpected values for 'sort_flags' argument +--FILE-- + 10, 2 => 2, 45 => 45); + +//array of unexpected 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 krsort() +// when 'sort_flags' arugment is supplied with different values +echo "\n-- Testing krsort() 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( krsort($temp_array, $value) ); + var_dump($temp_array); + $counter++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying different unexpected values for 'sort_flags' argument -- +-- Iteration 1 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 2 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 3 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 4 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 5 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 6 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 7 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 8 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 9 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 10 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 11 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 12 -- +bool(true) +array(3) { + [45]=> + int(45) + [10]=> + int(10) + [2]=> + int(2) +} +-- Iteration 13 -- + +Warning: krsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 14 -- + +Warning: krsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 15 -- + +Warning: krsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 16 -- + +Warning: krsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 17 -- + +Warning: krsort() expects parameter 2 to be long, object given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 18 -- + +Warning: krsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 19 -- + +Warning: krsort() expects parameter 2 to be long, string given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +-- Iteration 20 -- + +Warning: krsort() expects parameter 2 to be long, resource given in %s on line %d +bool(false) +array(3) { + [10]=> + int(10) + [2]=> + int(2) + [45]=> + int(45) +} +Done diff --git a/ext/standard/tests/array/krsort_variation3.phpt b/ext/standard/tests/array/krsort_variation3.phpt new file mode 100644 index 0000000000..b3ec565bad --- /dev/null +++ b/ext/standard/tests/array/krsort_variation3.phpt @@ -0,0 +1,303 @@ +--TEST-- +Test krsort() 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 key values + array(1.0 => 10.5, 0.2 => -10.5, 3.1 => 10.5e2, 4 => 10.6E-2, .5 => .5, 6 => .0001, -7 => -.1), + + // mixed value array with different types of keys + 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 keys contains minimum and maximum ranges + array( 2147483647 => 1 , 2147483648 => 2, -2147483647 => 3, -2147483648 => 4, -0 => 5) +); + +// set of possible flag values +$flags = array("SORT_REGULAR" => SORT_REGULAR, "SORT_NUMERIC" => SORT_NUMERIC); + +$count = 1; +echo "\n-- Testing krsort() by supplying various integer/float arrays --\n"; + +// loop through to test krsort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With defualt sort flag -\n"; + $temp_array = $array; + var_dump(krsort($temp_array) ); + var_dump($temp_array); + + // loop through $flags array and call krsort() with all possible sort flag values + foreach($flags as $key => $flag){ + echo "- Sort flag = $key -\n"; + $temp_array = $array; + var_dump(krsort($temp_array, $flag) ); + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying various integer/float arrays -- + +-- Iteration 1 -- +- With defualt sort flag - +bool(true) +array(9) { + [8]=> + int(41) + [7]=> + int(0) + [5]=> + int(31) + [3]=> + int(21) + [1]=> + int(11) + [-2]=> + int(-11) + [-4]=> + int(-21) + [-6]=> + int(-31) + [-10]=> + int(-41) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(9) { + [8]=> + int(41) + [7]=> + int(0) + [5]=> + int(31) + [3]=> + int(21) + [1]=> + int(11) + [-2]=> + int(-11) + [-4]=> + int(-21) + [-6]=> + int(-31) + [-10]=> + int(-41) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(9) { + [8]=> + int(41) + [7]=> + int(0) + [5]=> + int(31) + [3]=> + int(21) + [1]=> + int(11) + [-2]=> + int(-11) + [-4]=> + int(-21) + [-6]=> + int(-31) + [-10]=> + int(-41) +} + +-- Iteration 2 -- +- With defualt sort flag - +bool(true) +array(6) { + [6]=> + float(0.0001) + [4]=> + float(0.106) + [3]=> + float(1050) + [1]=> + float(10.5) + [0]=> + float(0.5) + [-7]=> + float(-0.1) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(6) { + [6]=> + float(0.0001) + [4]=> + float(0.106) + [3]=> + float(1050) + [1]=> + float(10.5) + [0]=> + float(0.5) + [-7]=> + float(-0.1) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(6) { + [6]=> + float(0.0001) + [4]=> + float(0.106) + [3]=> + float(1050) + [1]=> + float(10.5) + [0]=> + float(0.5) + [-7]=> + float(-0.1) +} + +-- Iteration 3 -- +- With defualt sort flag - +bool(true) +array(11) { + [11]=> + int(33) + [9]=> + float(0.106) + [7]=> + int(2) + [6]=> + float(0.09) + [5]=> + int(0) + [4]=> + int(-1) + [2]=> + float(0.0021) + [1]=> + float(0.0001) + [-3]=> + float(-0.01) + [-8]=> + float(-0.9) + [-10]=> + float(-0.106) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + [11]=> + int(33) + [9]=> + float(0.106) + [7]=> + int(2) + [6]=> + float(0.09) + [5]=> + int(0) + [4]=> + int(-1) + [2]=> + float(0.0021) + [1]=> + float(0.0001) + [-3]=> + float(-0.01) + [-8]=> + float(-0.9) + [-10]=> + float(-0.106) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(11) { + [11]=> + int(33) + [9]=> + float(0.106) + [7]=> + int(2) + [6]=> + float(0.09) + [5]=> + int(0) + [4]=> + int(-1) + [2]=> + float(0.0021) + [1]=> + float(0.0001) + [-3]=> + float(-0.01) + [-8]=> + float(-0.9) + [-10]=> + float(-0.106) +} + +-- Iteration 4 -- +- With defualt sort flag - +bool(true) +array(4) { + [2147483647]=> + int(1) + [0]=> + int(5) + [-2147483647]=> + int(3) + [-2147483648]=> + int(4) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(4) { + [2147483647]=> + int(1) + [0]=> + int(5) + [-2147483647]=> + int(3) + [-2147483648]=> + int(4) +} +- Sort flag = SORT_NUMERIC - +bool(true) +array(4) { + [2147483647]=> + int(1) + [0]=> + int(5) + [-2147483647]=> + int(3) + [-2147483648]=> + int(4) +} +Done diff --git a/ext/standard/tests/array/krsort_variation4.phpt b/ext/standard/tests/array/krsort_variation4.phpt new file mode 100644 index 0000000000..3df924ac82 --- /dev/null +++ b/ext/standard/tests/array/krsort_variation4.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test krsort() function : usage variations - sort octal values +--FILE-- + 01, 0321 => 02, 0345 => 03, 066 => 04, 0772 => 05, + 077 => 06, -066 => -01, -0345 => -02, 0 => 0 +); + +echo "\n-- Testing krsort() by supplying octal value array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_oct_array; +var_dump( krsort($temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying octal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_oct_array; +var_dump( krsort($temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying octal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_oct_array; +var_dump( krsort($temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying octal value array, 'flag' value is defualt -- +bool(true) +array(9) { + [669]=> + int(1) + [506]=> + int(5) + [229]=> + int(3) + [209]=> + int(2) + [63]=> + int(6) + [54]=> + int(4) + [0]=> + int(0) + [-54]=> + int(-1) + [-229]=> + int(-2) +} + +-- Testing krsort() by supplying octal value array, 'flag' value is SORT_REGULAR -- +bool(true) +array(9) { + [669]=> + int(1) + [506]=> + int(5) + [229]=> + int(3) + [209]=> + int(2) + [63]=> + int(6) + [54]=> + int(4) + [0]=> + int(0) + [-54]=> + int(-1) + [-229]=> + int(-2) +} + +-- Testing krsort() by supplying octal value array, 'flag' value is SORT_NUMERIC -- +bool(true) +array(9) { + [669]=> + int(1) + [506]=> + int(5) + [229]=> + int(3) + [209]=> + int(2) + [63]=> + int(6) + [54]=> + int(4) + [0]=> + int(0) + [-54]=> + int(-1) + [-229]=> + int(-2) +} +Done diff --git a/ext/standard/tests/array/krsort_variation5.phpt b/ext/standard/tests/array/krsort_variation5.phpt new file mode 100644 index 0000000000..c118fb9381 --- /dev/null +++ b/ext/standard/tests/array/krsort_variation5.phpt @@ -0,0 +1,236 @@ +--TEST-- +Test krsort() 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 containing different strings with key values + array ( 'Lemon' => "lemoN", 'o' => "Orange", 'B' => "banana", 'Apple' => "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 krsort() by supplying various string arrays --\n"; + +// loop through to test krsort() with different arrays +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With defualt sort flag -\n"; + $temp_array = $array; + var_dump(krsort($temp_array) ); // expecting : bool(true) + var_dump($temp_array); + + // loop through $flags array and call krsort() with all possible sort flag values + foreach($flags as $key => $flag){ + echo "- Sort flag = $key -\n"; + $temp_array = $array; + var_dump(krsort($temp_array, $flag) ); // expecting : bool(true) + var_dump($temp_array); + } + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying various string arrays -- + +-- Iteration 1 -- +- With defualt sort flag - +bool(true) +array(11) { + ["\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 +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + ["\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 +} +- Sort flag = SORT_STRING - +bool(true) +array(11) { + ["\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 +} + +-- Iteration 2 -- +- With defualt sort flag - +bool(true) +array(11) { + ["x"]=> + string(1) "X" + ["te"]=> + string(4) "Test" + ["t"]=> + string(4) "TTTT" + ["o"]=> + string(6) "Orange" + ["X"]=> + string(1) "x" + ["W"]=> + string(2) "ww" + ["T"]=> + string(3) "ttt" + ["O"]=> + string(6) "oraNGe" + ["Lemon"]=> + string(5) "lemoN" + ["B"]=> + string(6) "BANANA" + ["Apple"]=> + string(5) "apple" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(11) { + ["x"]=> + string(1) "X" + ["te"]=> + string(4) "Test" + ["t"]=> + string(4) "TTTT" + ["o"]=> + string(6) "Orange" + ["X"]=> + string(1) "x" + ["W"]=> + string(2) "ww" + ["T"]=> + string(3) "ttt" + ["O"]=> + string(6) "oraNGe" + ["Lemon"]=> + string(5) "lemoN" + ["B"]=> + string(6) "BANANA" + ["Apple"]=> + string(5) "apple" +} +- Sort flag = SORT_STRING - +bool(true) +array(11) { + ["x"]=> + string(1) "X" + ["te"]=> + string(4) "Test" + ["t"]=> + string(4) "TTTT" + ["o"]=> + string(6) "Orange" + ["X"]=> + string(1) "x" + ["W"]=> + string(2) "ww" + ["T"]=> + string(3) "ttt" + ["O"]=> + string(6) "oraNGe" + ["Lemon"]=> + string(5) "lemoN" + ["B"]=> + string(6) "BANANA" + ["Apple"]=> + string(5) "apple" +} +Done diff --git a/ext/standard/tests/array/krsort_variation6.phpt b/ext/standard/tests/array/krsort_variation6.phpt new file mode 100644 index 0000000000..167d0ee7d6 --- /dev/null +++ b/ext/standard/tests/array/krsort_variation6.phpt @@ -0,0 +1,114 @@ +--TEST-- +Test krsort() 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 krsort() by supplying hexadecimal value array, 'flag' value is defualt --\n"; +$temp_array = $unsorted_hex_array; +var_dump(krsort( $temp_array) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying hexadecimal value array, 'flag' value is SORT_REGULAR --\n"; +$temp_array = $unsorted_hex_array; +var_dump(krsort( $temp_array, SORT_REGULAR) ); // expecting : bool(true) +var_dump($temp_array); + +echo "\n-- Testing krsort() by supplying hexadecimal value array, 'flag' value is SORT_NUMERIC --\n"; +$temp_array = $unsorted_hex_array; +var_dump(krsort( $temp_array, SORT_NUMERIC) ); // expecting : bool(true) +var_dump($temp_array); + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() 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 krsort() 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 krsort() 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 diff --git a/ext/standard/tests/array/krsort_variation7.phpt b/ext/standard/tests/array/krsort_variation7.phpt new file mode 100644 index 0000000000..9ba3fc5447 --- /dev/null +++ b/ext/standard/tests/array/krsort_variation7.phpt @@ -0,0 +1,177 @@ +--TEST-- +Test krsort() function : usage variations - sort array with diff. sub arrays +--FILE-- + array(), + + // array contains null sub array + 2 => array( 1 => array() ), + + // array of arrays along with some values + 3 => array(4 => 44, 1 => 11, 3 => array(64,61) ), + + // array contains sub arrays + 4 => array ( 3 => array(33,-5,6), 1 => array(11), + 2 => array(22,-55), 0 => array() ) +); + + +$count = 1; +echo "\n-- Testing krsort() by supplying various arrays containing sub arrays --\n"; + +// loop through to test krsort() with different arrays +foreach ($various_arrays as $array) { + + echo "\n-- Iteration $count --\n"; + echo "- With defualt sort flag -\n"; + $temp_array = $array; + var_dump( krsort($temp_array) ); + var_dump($temp_array); + + echo "- Sort flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump( krsort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying various arrays containing sub arrays -- + +-- Iteration 1 -- +- With defualt sort flag - +bool(true) +array(0) { +} +- Sort flag = SORT_REGULAR - +bool(true) +array(0) { +} + +-- Iteration 2 -- +- With defualt sort flag - +bool(true) +array(1) { + [1]=> + array(0) { + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(1) { + [1]=> + array(0) { + } +} + +-- Iteration 3 -- +- With defualt sort flag - +bool(true) +array(3) { + [4]=> + int(44) + [3]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + [1]=> + int(11) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + [4]=> + int(44) + [3]=> + array(2) { + [0]=> + int(64) + [1]=> + int(61) + } + [1]=> + int(11) +} + +-- Iteration 4 -- +- With defualt sort flag - +bool(true) +array(4) { + [3]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [1]=> + array(1) { + [0]=> + int(11) + } + [0]=> + array(0) { + } +} +- Sort flag = SORT_REGULAR - +bool(true) +array(4) { + [3]=> + array(3) { + [0]=> + int(33) + [1]=> + int(-5) + [2]=> + int(6) + } + [2]=> + array(2) { + [0]=> + int(22) + [1]=> + int(-55) + } + [1]=> + array(1) { + [0]=> + int(11) + } + [0]=> + array(0) { + } +} +Done diff --git a/ext/standard/tests/array/krsort_variation8.phpt b/ext/standard/tests/array/krsort_variation8.phpt new file mode 100644 index 0000000000000000000000000000000000000000..20276ade6cf57b7f95b1d3fd58bc28827739817d GIT binary patch literal 3328 zcmeHIZExE)5Z-6~ih~g>k|Fs;v5PfbQVgp*3=7sGae)C&V9*ww2$dy)qS6>c|NEXJ zsYI$>pu_TMs12Lcy*#`--aU$<`Rr;QMc!Oinm($kP}&b@Q|D`)7CD_#U5Q&s_d=zD zB^5=)Mzl>IWCD3s%POQ}mMu4#xUG&!RFue#s53phdUrWrUe12|aPi9}`S1Q9UC>6P z8QUmX!GzL^>bz7kk!vkhnGDE_qPM?a%n;SjugkmA8}{kFDs-WDr6h#3DvHd-N9`)&stkxvFX&8HiaUWpisB$r@vxnT zOU?wHq??UYoClZQwvl&anrdmE=*-#s9#PNKW!$5)b1U_O5EXFp_(_h2=vDPvZN_7ZOb0$4uamY{90Pg!CGezeg1$ZgNkItlg!7sptci&h zOGuN!Xl%q-p;=kY3Yy;3?x)yCG228j@0^3#nCf8n@+W+)iQU6J8oaasyutHa)zS*g z4ifW(C8R$;TwJg_uN-MlxInPNP^{L8bv3(?MlJ|m5!1*VJpw@-^A7(GWSv|;j7IF# ztWPkFq*-wg;A}O_#tYC}wk5CgDBAByj8s*ZWwzr^Z84SY9Yn)ZactX;2?%t>V?j}5 z`t}F|P}&wk7k0Yxl?N(ZCiS-T8@g;+2ZYET4cdxl4!AqH|1s*2+Hl{H!&nxFxPLS#&>$Sb0qb>f;;-Yx@nfKS zDYzUC9Rb$t9x-Z;U~B#@n%9A~vk5sXrw6h8!0clF9A47_xE(`WEdvY6WM(0qX=CXw z`imYw>P&~m*D&XvuaO!(Q*B3$t2ab!v|SZ4=^50>-LGxYhRp--^Yctkd+I@b-$w{z T_kDyON35Bi|LF+vOU(NRicghH literal 0 HcmV?d00001 diff --git a/ext/standard/tests/array/krsort_variation9.phpt b/ext/standard/tests/array/krsort_variation9.phpt new file mode 100644 index 0000000000..d7d8343b08 --- /dev/null +++ b/ext/standard/tests/array/krsort_variation9.phpt @@ -0,0 +1,257 @@ +--TEST-- +Test krsort() function : usage variations - sort array with/without key values +--FILE-- + 55, 66, 22, 33, 11), + array ("a" => "orange", "banana", "c" => "apple"), + array(1, 2, 3, 4, 5, 6), + array("first", 5 => "second", 1 => "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 krsort() by supplying various arrays with/without key values --\n"; + +// loop through to test krsort() with different arrays, +foreach ($various_arrays as $array) { + echo "\n-- Iteration $count --\n"; + + echo "- With defualt sort flag -\n"; + $temp_array = $array; + var_dump( krsort($temp_array) ); + var_dump($temp_array); + + echo "- Sort flag = SORT_REGULAR -\n"; + $temp_array = $array; + var_dump( krsort($temp_array, SORT_REGULAR) ); + var_dump($temp_array); + $count++; +} + +echo "Done\n"; +?> +--EXPECTF-- +*** Testing krsort() : usage variations *** + +-- Testing krsort() by supplying various arrays with/without key values -- + +-- Iteration 1 -- +- With defualt sort flag - +bool(true) +array(5) { + [9]=> + int(11) + [8]=> + int(33) + [7]=> + int(22) + [6]=> + int(66) + [5]=> + int(55) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(5) { + [9]=> + int(11) + [8]=> + int(33) + [7]=> + int(22) + [6]=> + int(66) + [5]=> + int(55) +} + +-- Iteration 2 -- +- With defualt sort flag - +bool(true) +array(3) { + ["c"]=> + string(5) "apple" + [0]=> + string(6) "banana" + ["a"]=> + string(6) "orange" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + ["c"]=> + string(5) "apple" + [0]=> + string(6) "banana" + ["a"]=> + string(6) "orange" +} + +-- Iteration 3 -- +- With defualt 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 defualt sort flag - +bool(true) +array(3) { + [5]=> + string(6) "second" + [1]=> + string(5) "third" + [0]=> + string(5) "first" +} +- Sort flag = SORT_REGULAR - +bool(true) +array(3) { + [5]=> + string(6) "second" + [1]=> + string(5) "third" + [0]=> + string(5) "first" +} + +-- Iteration 5 -- +- With defualt sort flag - +bool(true) +array(6) { + [9]=> + int(19) + [8]=> + int(1) + [4]=> + int(1) + [3]=> + int(13) + [1]=> + int(1) + [0]=> + int(1) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(6) { + [9]=> + int(19) + [8]=> + int(1) + [4]=> + int(1) + [3]=> + int(13) + [1]=> + int(1) + [0]=> + int(1) +} + +-- Iteration 6 -- +- With defualt 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 defualt sort flag - +bool(true) +array(4) { + ["d"]=> + int(5) + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + ["a"]=> + int(1) +} +- Sort flag = SORT_REGULAR - +bool(true) +array(4) { + ["d"]=> + int(5) + ["c"]=> + array(1) { + ["g"]=> + int(4) + } + ["b"]=> + array(2) { + ["e"]=> + int(2) + ["f"]=> + int(3) + } + ["a"]=> + int(1) +} +Done -- 2.40.0