From 55d0b9780ff836148ab491e7a27a4e2df3fa1b13 Mon Sep 17 00:00:00 2001 From: Raghubansh Kumar Date: Mon, 15 Oct 2007 06:34:35 +0000 Subject: [PATCH] New testcases for array_flip() function --- .../tests/array/array_flip_basic.phpt | 71 +++++++ .../tests/array/array_flip_error.phpt | 34 ++++ .../tests/array/array_flip_variation1.phpt | 178 ++++++++++++++++++ .../tests/array/array_flip_variation2.phpt | Bin 0 -> 2306 bytes .../tests/array/array_flip_variation3.phpt | Bin 0 -> 2978 bytes .../tests/array/array_flip_variation4.phpt | 90 +++++++++ .../tests/array/array_flip_variation5.phpt | 82 ++++++++ 7 files changed, 455 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..08a63fb66b --- /dev/null +++ b/ext/standard/tests/array/array_flip_basic.phpt @@ -0,0 +1,71 @@ +--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 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..64339d76d8 --- /dev/null +++ b/ext/standard/tests/array/array_flip_error.phpt @@ -0,0 +1,34 @@ +--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: Wrong parameter count for array_flip() in %s on line %d +NULL +-- Testing array_flip() function with more than expected no. of arguments -- + +Warning: Wrong parameter count for array_flip() 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..8042803600 --- /dev/null +++ b/ext/standard/tests/array/array_flip_variation1.phpt @@ -0,0 +1,178 @@ +--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(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: array_flip(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: array_flip(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: array_flip(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: array_flip(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: array_flip(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: array_flip(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: array_flip(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: array_flip(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: array_flip(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 11 -- + +Warning: array_flip(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: array_flip(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: array_flip(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: array_flip(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: array_flip(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: array_flip(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: array_flip(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: array_flip(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: array_flip(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 20 -- +array(0) { +} +-- Iteration 21 -- + +Warning: array_flip(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 22 -- + +Warning: array_flip(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 23 -- + +Warning: array_flip(): The argument should be an array in %s on line %d +bool(false) +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..bd8233054f557b24f014e6f5dcc6eec9b8cf2bb2 GIT binary patch literal 2306 zcmb_dU2EG&6z%KIued7$vQ1=Lw!5^cleV-D6vA$4Tv*sFL6*j`sH{;(qb8>Gzwfyk zNtWbg>BABT=AJX>p1B_*&s(o<*PbWVGB*@x9UShrNt_Lav@O!m#44o=D)Qh#(zigz z0Y`H3$c@viFs?m9kFnWN6mPdu%hb>pdB}z5U4OV)L3;T*+ht-hqK{e`We%AnXqLI! z8ExRK)Ex>M(R-PPI?g!b1$~mH&}lmzlF-t-f~};G#HKSD5g)u&g$^Z!Dv}o@pUfmT zK^g@*nv^-lp%_gB42cn~^&w6lde$jU$@*wqJ`{UgtUM>fog!y6!eP{mPj||8(HGk) z-K$ohtsFt*E_GhP%cON`hayHQq}*tz=K$qCGY9I%#aS7>ucMc=TrO9CtbM`%UI`*r z&7qJ;O5#+WoX_KZmdF!M z+`ZA`@m(73WccOI1WB$q`MgYCHR94%d4PLyvE(*@BOWvaT$M`qoB{a+Nh2dP;mDxr zc{L=DagxwRl9pK#gqW7if!vK!$vuP?E=p$QQ*>L$p`BwQpDwSsg@$QJ1OvxJcKrTR zdG12io0Tf5e83KUlU54x7vq;DuuW7@CqQ`WTfPcWkA^&bnlDQBPCivZ>)6gpZP;a> zCC|p0>e~uc1M#&`C{tBG$2=;hN1s`Gq>2sZr$cx9(sTD5E}Xu^f+ZNh9~bcGr9^l- zGjxH1yz*hM!u_Z(Vl-Bp&(=-CEx_7hM7nXVZePlPeoa(v;OvTgE|j_r8O&jTyHQ>q96}>T}j|8aUT`?Y|wrd zt5==C5%&FjkDYbI>nnUFR)2n6y<1=7OYwg_s-k?62mWG6-(l)6ryie$^Y`TyBG_eA zyaUZ!kZ+;(uC`EbX5nUITi6Q=HCx+){3>C!x-H~+C3svAzd~(fFdveG<~pU}BWrfb z;!Q4DosM^TQ>gW&>cUhBeNf19TGQB-VN=1gO`p{>^&42#_*(a!8S5%C*Uq37J(;pD Z{WeMEQmJg+DNk_#t=(#XkaY$Xfsa literal 0 HcmV?d00001 diff --git a/ext/standard/tests/array/array_flip_variation3.phpt b/ext/standard/tests/array/array_flip_variation3.phpt new file mode 100644 index 0000000000000000000000000000000000000000..376bdebb42db1c772a94acf6766b9fe78c953fb2 GIT binary patch literal 2978 zcmb_e-*4MC5bkUFS6sEM{(;E0Vwn{JE}^NT9f$j< z$|4o1!G}R6%0>=w$*$RRA>m6VQ%JJymRIWMeUxX3`fPa3eE;pcpO@HW@v2NqHXXzJ zs*r^|lpL_UZrg26fivA=#9$0>cpX<+shVHH2QHgRm{q#%Cw_p1e?#p+@h^D-YT?JC zsbUUsk?>344{}<|NF-5}Om&Y*%*IoOgxDC~iOx`{!*R58GX@4Y)+l)_vAQf^qcl-t zV*eVl37snUH+PE3BHL93W9#48yjlAj~(*nHlcnoTj zR2^%dE_>xjbu9G{0|C}r3-5|er@;5JJZP3l5gYpKjPFZ%xKrF!^coh6#qyU`z|_YT z>NSNLdE^}OOz__7I@^~y?=24*B~+D=s_dIwW+!VLGrcl%cFY|+>r)Vfb0s0GafhVd8aiU!1WCT z=ZG5!zQen4&pQb})S0imDmu}b4i>SD@@_OBaLOOL(T8w;&WMH)_;XXJ(`HVHW}({C z2I-%HW;Gb-K6M$zhLec{CE_%ysFR6DW`RDiR)%^7ls9Tv02I3IhDzgHz2eVqzdQS$ zFkjLPkH4Z7SVh*-&4+egv;^`K4c0TAC8?64+2C3Hcd0@xmFKxqnK)45aT*ifm<1iF zOopTiDQ`(-052|Hw%uH*4C0UHV?y+VGJv&o^G2vPFWUB&P;GWb*-a**>d;l#i@Zsk zR>Rq7;+YA%AX>liQl94p)*z`{OE`TVO;)RHdk86R`2wMAuh6jL^=_{|A$#F-Ho8Jq z4Bw@@q}i9lt}mL$0}x^i^i3hS$6npwYqb3J{qptdEj~#9v#T;PlJH^#e0MD}k z!5k6ROF$@aU?IXfz7rBEa!`uVWCEHdjZ&eP`OlvKm& zcfocmVu3fzuKXjSd)LuW#)tD;;MT-U<(UJ1iIqiTT~t$d;~;IljHska=s;b)2#nTa z6Yc3`iYf=Pk*C!%@TU&=q*w;azKLypjI?^%}ciFSKP*an9 p$f2MVvki)<9 value flipped + * Source code: ext/standard/array.c +*/ + +/* +* 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, + 'float_value3' => 3.4E3, + 'float_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 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..29222a12ce --- /dev/null +++ b/ext/standard/tests/array/array_flip_variation5.phpt @@ -0,0 +1,82 @@ +--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 -- 2.50.1