From ee89cea00ba7840a9ddb0d2f3d7e6de85ea28a08 Mon Sep 17 00:00:00 2001 From: Raghubansh Kumar Date: Mon, 15 Oct 2007 06:33:32 +0000 Subject: [PATCH] New testcases for array_flip() function --- .../tests/array/array_flip_basic.phpt | 110 +++++++ .../tests/array/array_flip_error.phpt | 45 +++ .../tests/array/array_flip_variation1.phpt | 274 ++++++++++++++++++ .../tests/array/array_flip_variation2.phpt | Bin 0 -> 2848 bytes .../tests/array/array_flip_variation3.phpt | Bin 0 -> 4020 bytes .../tests/array/array_flip_variation4.phpt | 119 ++++++++ .../tests/array/array_flip_variation5.phpt | 123 ++++++++ 7 files changed, 671 insertions(+) create mode 100644 ext/standard/tests/array/array_flip_basic.phpt create mode 100644 ext/standard/tests/array/array_flip_error.phpt create mode 100644 ext/standard/tests/array/array_flip_variation1.phpt create mode 100644 ext/standard/tests/array/array_flip_variation2.phpt create mode 100644 ext/standard/tests/array/array_flip_variation3.phpt create mode 100644 ext/standard/tests/array/array_flip_variation4.phpt create mode 100644 ext/standard/tests/array/array_flip_variation5.phpt diff --git a/ext/standard/tests/array/array_flip_basic.phpt b/ext/standard/tests/array/array_flip_basic.phpt new file mode 100644 index 0000000000..7c3b08e534 --- /dev/null +++ b/ext/standard/tests/array/array_flip_basic.phpt @@ -0,0 +1,110 @@ +--TEST-- +Test array_flip() function : basic functionality +--FILE-- + value flipped + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_flip() : basic functionality ***\n"; + +// array with default keys - numeric values +$input = array(1, 2); +var_dump( array_flip($input) ); + +// array with default keys - string values +$input = array('value1', "value2"); +var_dump( array_flip($input) ); + +// associative arrays - key as string +$input = array('key1' => 1, "key2" => 2); +var_dump( array_flip($input) ); + +// associative arrays - key as numeric +$input = array(1 => 'one', 2 => "two"); +var_dump( array_flip($input) ); + +// combination of associative and non-associative array +$input = array(1 => 'one','two', 3 => 'three', 4, "five" => 5); +var_dump( array_flip($input) ); +echo "Done" +?> +--EXPECTF-- +*** Testing array_flip() : basic functionality *** +array(2) { + [1]=> + int(0) + [2]=> + int(1) +} +array(2) { + ["value1"]=> + int(0) + ["value2"]=> + int(1) +} +array(2) { + [1]=> + string(4) "key1" + [2]=> + string(4) "key2" +} +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +array(5) { + ["one"]=> + int(1) + ["two"]=> + int(2) + ["three"]=> + int(3) + [4]=> + int(4) + [5]=> + string(4) "five" +} +Done +--UEXPECTF-- +*** Testing array_flip() : basic functionality *** +array(2) { + [1]=> + int(0) + [2]=> + int(1) +} +array(2) { + [u"value1"]=> + int(0) + [u"value2"]=> + int(1) +} +array(2) { + [1]=> + unicode(4) "key1" + [2]=> + unicode(4) "key2" +} +array(2) { + [u"one"]=> + int(1) + [u"two"]=> + int(2) +} +array(5) { + [u"one"]=> + int(1) + [u"two"]=> + int(2) + [u"three"]=> + int(3) + [4]=> + int(4) + [5]=> + unicode(4) "five" +} +Done diff --git a/ext/standard/tests/array/array_flip_error.phpt b/ext/standard/tests/array/array_flip_error.phpt new file mode 100644 index 0000000000..f9be2fc269 --- /dev/null +++ b/ext/standard/tests/array/array_flip_error.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test array_flip() function : error conditions +--FILE-- + value flipped + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_flip() : error conditions ***\n"; + +// Zero arguments +echo "-- Testing array_flip() function with Zero arguments --\n"; +var_dump( array_flip() ); + +//one more than the expected number of arguments +echo "-- Testing array_flip() function with more than expected no. of arguments --\n"; +$input = array(1 => 'one', 2 => 'two'); +$extra_arg = 10; +var_dump( array_flip($input, $extra_arg) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_flip() : error conditions *** +-- Testing array_flip() function with Zero arguments -- + +Warning: array_flip() expects exactly 1 parameter, 0 given in %s on line %d +NULL +-- Testing array_flip() function with more than expected no. of arguments -- + +Warning: array_flip() expects exactly 1 parameter, 2 given in %s on line %d +NULL +Done +--UEXPECTF-- +*** Testing array_flip() : error conditions *** +-- Testing array_flip() function with Zero arguments -- + +Warning: array_flip() expects exactly 1 parameter, 0 given in %s on line %d +NULL +-- Testing array_flip() function with more than expected no. of arguments -- + +Warning: array_flip() expects exactly 1 parameter, 2 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_flip_variation1.phpt b/ext/standard/tests/array/array_flip_variation1.phpt new file mode 100644 index 0000000000..3207f0102c --- /dev/null +++ b/ext/standard/tests/array/array_flip_variation1.phpt @@ -0,0 +1,274 @@ +--TEST-- +Test array_flip() function : usage variations - unexpected values for 'input' argument +--FILE-- + value flipped + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_flip() : usage variations - unexpected values for 'input' ***\n"; + +//get an unset variable +$unset_var = 10; +unset ($unset_var); + +//class definition for object variable +class MyClass +{ + public function __toString() + { + return 'object'; + } +} + +//resource variable +$fp = fopen(__FILE__,'r'); + +//array of values for 'input' argument +$values = array( + // int data + /*1*/ 0, + 1, + 12345, + -2345, + + // float data + /*5*/ 10.5, + -10.5, + 10.5e10, + 10.6E-10, + .5, + + // null data + /*10*/ NULL, + null, + + // boolean data + /*12*/ true, + false, + TRUE, + /*15*/ FALSE, + + // empty data + "", + '', + + // string data + "string", + 'string', + + // object data + /*20*/ new MyClass(), + + // undefined data + @$undefined_var, + + // unset data + @$unset_var, + + //resource data + /*23*/ $fp +); + +// loop through each element of $values for 'input' argument +for($count = 0; $count < count($values); $count++) { + echo "-- Iteration ".($count + 1). " --\n"; + var_dump( array_flip($values[$count]) ); +}; + +//closing resource +fclose($fp); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_flip() : usage variations - unexpected values for 'input' *** +-- Iteration 1 -- + +Warning: array_flip() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 2 -- + +Warning: array_flip() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_flip() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_flip() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_flip() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_flip() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: array_flip() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: array_flip() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: array_flip() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 15 -- + +Warning: array_flip() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 16 -- + +Warning: array_flip() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: array_flip() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: array_flip() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_flip() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_flip() expects parameter 1 to be array, object given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_flip() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_flip() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 23 -- + +Warning: array_flip() expects parameter 1 to be array, resource given in %s on line %d +NULL +Done +--UEXPECTF-- +*** Testing array_flip() : usage variations - unexpected values for 'input' *** +-- Iteration 1 -- + +Warning: array_flip() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 2 -- + +Warning: array_flip() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_flip() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_flip() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_flip() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_flip() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: array_flip() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: array_flip() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: array_flip() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 15 -- + +Warning: array_flip() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 16 -- + +Warning: array_flip() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: array_flip() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: array_flip() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_flip() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_flip() expects parameter 1 to be array, object given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_flip() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_flip() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 23 -- + +Warning: array_flip() expects parameter 1 to be array, resource given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_flip_variation2.phpt b/ext/standard/tests/array/array_flip_variation2.phpt new file mode 100644 index 0000000000000000000000000000000000000000..b03fa0fa85730bc7e3aba465cb3626caa0387da2 GIT binary patch literal 2848 zcmcIm?`s=55WTO}Uoj^PYn!a?wVk$?I%!JlKq1_f#({&&5!P!t7F}x>t<=Pn{_h=0 zEAJ1dp@sHKNaj7wJk7k(CJYzzt3?=+1uGQ9QpUU6b;|Q@57t^Fie~~&Ko{{HgU_+# zv56EALcm3?Rp5@mJy#o8@%5TXCKP;PyMlz_#rw-Srk=gdH#r&h;e*Unrgk|4%xP=Y zE4o0(=Is&a!#h?alIN!434CNqOHnU}MPL@5p{!IhFrss|0(0;x(=uU@WGi+8>_H6+ z6^m6YS3_H4kdXe6pdiwRh1_v**OCrgfYY&8d8fB{F?)_Bn+#~bkB6~m=5(WNC+%eG zOt!ieOP3BX$&H||P|L7(YJ*K&WeF5YV)lY`*fv+YTOU4!*=#odXAu$e;}roQoq})k zlpRo}!~upm#WJ0(P8CnNIHbNHdklOfJJo1B0qh7Vbj6SBrBH{(vm;^XzaK}Q+5 ziE#1e@~R0KA+DUzI99x3fq&ZHO*!*Rd2ef(ADWmyG&U3a`}*?IN~xm0;*yJ4?o3VO z(U_uzWp~sY(4}jO!>hJ0sf)Bxb7y-8zbEA_+Ix!kX>6|T^}(tltGT_7w%^8TsgZdQ zMRLz<91wh+Z&!Mock9nl`I-W9hW2s4Q4+Uky1f6V~>v zL|vpi=>f&zQY*M(jSpF7LoKT@@g{GC+1ja&o0JGC;5aomHaSLA{KvA*YKeM|tkS+t zed7z!%xJjIgD&ZT%UX0CFWqx~?rTBtWAV&|*T3J0`Uxji*r63QecFqf ze&39mKH)}9ziUTLE2l+e=e6MGznO+1>pVaFI?r2D)5kpNnR`>#(|K2VQe{hQmVHI- mEBS~xZ_GN+iz}C^{w6mP?Zy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+*/ + +/* +* Trying different invalid values for 'input' array argument +*/ + +echo "*** Testing array_flip() : different invalid values in 'input' array argument ***\n"; + +// class definition for object data +class MyClass +{ + public function __toString() + { + return 'object'; + } +} +$obj = new MyClass(); + +// resource data +$fp = fopen(__FILE__, 'r'); + +$input = array( + // float values + 'float_value1' => 1.2, + 'float_value2' => 0.5, + 'flaot_value3' => 3.4E3, + 'flaot_value4' => 5.6E-6, + + // bool values + 'bool_value1' => true, + 'bool_value2' => false, + 'bool_value3' => TRUE, + 'bool_value4' => FALSE, + + // null values + 'null_value1' => null, + + // array value + 'array_value' => array(1), + + // object value + 'obj_value' => $obj, + + // resource value + 'resource_value' => $fp, +); + +var_dump( array_flip($input) ); + +// closing resource +fclose($fp); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_flip() : different invalid values in 'input' array argument *** + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d +array(0) { +} +Done +--UEXPECTF-- +*** Testing array_flip() : different invalid values in 'input' array argument *** + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d + +Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d +array(0) { +} +Done \ No newline at end of file diff --git a/ext/standard/tests/array/array_flip_variation5.phpt b/ext/standard/tests/array/array_flip_variation5.phpt new file mode 100644 index 0000000000..d45af595f7 --- /dev/null +++ b/ext/standard/tests/array/array_flip_variation5.phpt @@ -0,0 +1,123 @@ +--TEST-- +Test array_flip() function : usage variations - 'input' argument with repeatitive keys and values +--FILE-- + value flipped + * Source code: ext/standard/array.c +*/ + +/* +* Using different types of repeatitive keys as well as values for 'input' array +*/ + +echo "*** Testing array_flip() : 'input' array with repeatitive keys/values ***\n"; + +// array with numeric key repeatition +$input = array(1 => 'value', 2 => 'VALUE', 1 => "VaLuE", 3.4 => 4, 3.4 => 5); +var_dump( array_flip($input) ); + +// array with string key repeatition +$input = array("key" => 1, "two" => 'TWO', 'three' => 3, 'key' => "FOUR"); +var_dump( array_flip($input) ); + +// array with bool key repeatition +$input = array(true => 1, false => 0, TRUE => -1); +var_dump( array_flip($input) ); + +// array with null key repeatition +$input = array(null => "Hello", NULL => 0); +var_dump( array_flip($input) ); + +// array with numeric value repeatition +$input = array('one' => 1, 'two' => 2, 3 => 1, "index" => 1); +var_dump( array_flip($input) ); + +//array with string value repeatition +$input = array('key1' => "value1", "key2" => '2', 'key3' => 'value1'); +var_dump( array_flip($input) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_flip() : 'input' array with repeatitive keys/values *** +array(3) { + ["VaLuE"]=> + int(1) + ["VALUE"]=> + int(2) + [5]=> + int(3) +} +array(3) { + ["FOUR"]=> + string(3) "key" + ["TWO"]=> + string(3) "two" + [3]=> + string(5) "three" +} +array(2) { + [-1]=> + int(1) + [0]=> + int(0) +} +array(1) { + [0]=> + string(0) "" +} +array(2) { + [1]=> + string(5) "index" + [2]=> + string(3) "two" +} +array(2) { + ["value1"]=> + string(4) "key3" + [2]=> + string(4) "key2" +} +Done +--UEXPECTF-- +*** Testing array_flip() : 'input' array with repeatitive keys/values *** +array(3) { + [u"VaLuE"]=> + int(1) + [u"VALUE"]=> + int(2) + [5]=> + int(3) +} +array(3) { + [u"FOUR"]=> + unicode(3) "key" + [u"TWO"]=> + unicode(3) "two" + [3]=> + unicode(5) "three" +} +array(2) { + [-1]=> + int(1) + [0]=> + int(0) +} +array(1) { + [0]=> + unicode(0) "" +} +array(2) { + [1]=> + unicode(5) "index" + [2]=> + unicode(3) "two" +} +array(2) { + [u"value1"]=> + unicode(4) "key3" + [2]=> + unicode(4) "key2" +} +Done -- 2.50.1