From: Iain Lewis Date: Mon, 24 Nov 2008 17:36:44 +0000 (+0000) Subject: Adding some tests for array_product X-Git-Tag: BEFORE_HEAD_NS_CHANGES_MERGE~98 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e512037ced1ad6eba769ea0a5ce92a594918eb09;p=php Adding some tests for array_product --- diff --git a/ext/standard/tests/array/array_product_error.phpt b/ext/standard/tests/array/array_product_error.phpt new file mode 100644 index 0000000000..b8465bc605 --- /dev/null +++ b/ext/standard/tests/array/array_product_error.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test array_product() function : error conditions +--FILE-- + +===DONE=== +--EXPECTF-- +*** Testing array_product() : error conditions *** + +-- Testing array_product() function with Zero arguments -- + +Warning: array_product() expects exactly 1 parameter, 0 given in %sarray_product_error.php on line %d +NULL + +-- Testing array_product() function with more than expected no. of arguments -- + +Warning: array_product() expects exactly 1 parameter, 2 given in %sarray_product_error.php on line %d +NULL + +-- Testing array_product() function incorrect argument type -- + +Warning: array_product() expects parameter 1 to be array, Unicode string given in %sarray_product_error.php on line %d +NULL +===DONE=== \ No newline at end of file diff --git a/ext/standard/tests/array/array_product_variation1.phpt b/ext/standard/tests/array/array_product_variation1.phpt new file mode 100644 index 0000000000..cd2ed71ae6 --- /dev/null +++ b/ext/standard/tests/array/array_product_variation1.phpt @@ -0,0 +1,58 @@ +--TEST-- +Test array_product() function : variation +--FILE-- + true, "boolean (false)" => false, + "string" => "hello", "numeric string" => "12", + "resource" => $fp, "object" => new A(), "null" => null, + "array" => array(3,2)); + +foreach ($types as $desc => $type) { + echo $desc . "\n"; + var_dump(array_product(array($type))); + echo "\n"; +} + +fclose($fp); +?> +===DONE=== +--EXPECTF-- +*** Testing array_product() : variation - using non numeric values *** +boolean (true) +int(1) + +boolean (false) +int(0) + +string +int(0) + +numeric string +int(12) + +resource +int(%d) + +object +int(1) + +null +int(0) + +array +int(1) + +===DONE=== \ No newline at end of file diff --git a/ext/standard/tests/array/array_product_variation2.phpt b/ext/standard/tests/array/array_product_variation2.phpt new file mode 100644 index 0000000000..94a54505e2 --- /dev/null +++ b/ext/standard/tests/array/array_product_variation2.phpt @@ -0,0 +1,22 @@ +--TEST-- +Test array_product() function : variation - using a keyed array +--FILE-- + 2, "janet" => 5)) ); +?> +===DONE=== +--EXPECTF-- +*** Testing array_product() : variations *** + +-- Testing array_product() function with a keyed array -- +int(10) +===DONE=== diff --git a/ext/standard/tests/array/array_product_variation3.phpt b/ext/standard/tests/array/array_product_variation3.phpt new file mode 100644 index 0000000000..87b7be756a --- /dev/null +++ b/ext/standard/tests/array/array_product_variation3.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test array_product() function : variation - negative numbers +--FILE-- + +===DONE=== +--EXPECTF-- +*** Testing array_product() : variations - negative numbers*** + +-- Testing array_product() function with one negative number -- +int(-2) + +-- Testing array_product() function with two negative numbers -- +int(6) + +-- Testing array_product() function with three negative numbers -- +int(-24) + +-- Testing array_product() function with negative floats -- +float(-1.5) + +-- Testing array_product() function with negative floats -- +float(-9.9999999E+15) +===DONE=== \ No newline at end of file diff --git a/ext/standard/tests/array/array_product_variation4.phpt b/ext/standard/tests/array/array_product_variation4.phpt new file mode 100644 index 0000000000..a018611d3e --- /dev/null +++ b/ext/standard/tests/array/array_product_variation4.phpt @@ -0,0 +1,29 @@ +--TEST-- +Test array_product() function : variation - testing with a very large array +--FILE-- + +===DONE=== +--EXPECTF-- +*** Testing array_product() : variations *** + +-- Testing array_product() function with a very large array -- +float(INF) +===DONE=== diff --git a/ext/standard/tests/array/array_product_variation5.phpt b/ext/standard/tests/array/array_product_variation5.phpt new file mode 100644 index 0000000000..33e7997d0a --- /dev/null +++ b/ext/standard/tests/array/array_product_variation5.phpt @@ -0,0 +1,223 @@ +--TEST-- +Test array_product() function : usage variation +--FILE-- + 1, 'two' => 2); + +//array of values to iterate over +$inputs = array( + + // int data + 'int 0' => 0, + 'int 1' => 1, + 'int 12345' => 12345, + 'int -12345' => -2345, + + // float data + 'float 10.5' => 10.5, + 'float -10.5' => -10.5, + 'float 12.3456789000e10' => 12.3456789000e10, + 'float -12.3456789000e10' => -12.3456789000e10, + 'float .5' => .5, + + // null data + 'uppercase NULL' => NULL, + 'lowercase null' => null, + + // boolean data + 'lowercase true' => true, + 'lowercase false' =>false, + 'uppercase TRUE' =>TRUE, + 'uppercase FALSE' =>FALSE, + + // empty data + 'empty string DQ' => "", + 'empty string SQ' => '', + + // string data + 'string DQ' => "string", + 'string SQ' => 'string', + 'mixed case string' => "sTrInG", + 'heredoc' => $heredoc, + + // object data + 'instance of classWithToString' => new classWithToString(), + 'instance of classWithoutToString' => new classWithoutToString(), + + // undefined data + 'undefined var' => @$undefined_var, + + // unset data + 'unset var' => @$unset_var, +); + +// loop through each element of the array for input + +foreach($inputs as $key =>$value) { + echo "\n--$key--\n"; + var_dump( array_product($value) ); +}; + +?> +===DONE=== +--EXPECTF-- +*** Testing array_product() : usage variation *** + +--int 0-- + +Warning: array_product() expects parameter 1 to be array, integer given in %sarray_product_variation5.php on line %d +NULL + +--int 1-- + +Warning: array_product() expects parameter 1 to be array, integer given in %sarray_product_variation5.php on line %d +NULL + +--int 12345-- + +Warning: array_product() expects parameter 1 to be array, integer given in %sarray_product_variation5.php on line %d +NULL + +--int -12345-- + +Warning: array_product() expects parameter 1 to be array, integer given in %sarray_product_variation5.php on line %d +NULL + +--float 10.5-- + +Warning: array_product() expects parameter 1 to be array, double given in %sarray_product_variation5.php on line %d +NULL + +--float -10.5-- + +Warning: array_product() expects parameter 1 to be array, double given in %sarray_product_variation5.php on line %d +NULL + +--float 12.3456789000e10-- + +Warning: array_product() expects parameter 1 to be array, double given in %sarray_product_variation5.php on line %d +NULL + +--float -12.3456789000e10-- + +Warning: array_product() expects parameter 1 to be array, double given in %sarray_product_variation5.php on line %d +NULL + +--float .5-- + +Warning: array_product() expects parameter 1 to be array, double given in %sarray_product_variation5.php on line %d +NULL + +--uppercase NULL-- + +Warning: array_product() expects parameter 1 to be array, null given in %sarray_product_variation5.php on line %d +NULL + +--lowercase null-- + +Warning: array_product() expects parameter 1 to be array, null given in %sarray_product_variation5.php on line %d +NULL + +--lowercase true-- + +Warning: array_product() expects parameter 1 to be array, boolean given in %sarray_product_variation5.php on line %d +NULL + +--lowercase false-- + +Warning: array_product() expects parameter 1 to be array, boolean given in %sarray_product_variation5.php on line %d +NULL + +--uppercase TRUE-- + +Warning: array_product() expects parameter 1 to be array, boolean given in %sarray_product_variation5.php on line %d +NULL + +--uppercase FALSE-- + +Warning: array_product() expects parameter 1 to be array, boolean given in %sarray_product_variation5.php on line %d +NULL + +--empty string DQ-- + +Warning: array_product() expects parameter 1 to be array, Unicode string given in %sarray_product_variation5.php on line %d +NULL + +--empty string SQ-- + +Warning: array_product() expects parameter 1 to be array, Unicode string given in %sarray_product_variation5.php on line %d +NULL + +--string DQ-- + +Warning: array_product() expects parameter 1 to be array, Unicode string given in %sarray_product_variation5.php on line %d +NULL + +--string SQ-- + +Warning: array_product() expects parameter 1 to be array, Unicode string given in %sarray_product_variation5.php on line %d +NULL + +--mixed case string-- + +Warning: array_product() expects parameter 1 to be array, Unicode string given in %sarray_product_variation5.php on line %d +NULL + +--heredoc-- + +Warning: array_product() expects parameter 1 to be array, Unicode string given in %sarray_product_variation5.php on line %d +NULL + +--instance of classWithToString-- + +Warning: array_product() expects parameter 1 to be array, object given in %sarray_product_variation5.php on line %d +NULL + +--instance of classWithoutToString-- + +Warning: array_product() expects parameter 1 to be array, object given in %sarray_product_variation5.php on line %d +NULL + +--undefined var-- + +Warning: array_product() expects parameter 1 to be array, null given in %sarray_product_variation5.php on line %d +NULL + +--unset var-- + +Warning: array_product() expects parameter 1 to be array, null given in %sarray_product_variation5.php on line %d +NULL +===DONE=== \ No newline at end of file