diff options
author | Raghubansh Kumar <kraghuba@php.net> | 2007-11-27 14:57:55 +0000 |
---|---|---|
committer | Raghubansh Kumar <kraghuba@php.net> | 2007-11-27 14:57:55 +0000 |
commit | d08088df746bf12f6dfe1e7a8f65e8c51c6fd1ab (patch) | |
tree | 339215c78ca02f1c18e087ce7d684055be160137 | |
parent | 32da061155142fc2e117241fd4f646a93d57321f (diff) | |
download | php-git-d08088df746bf12f6dfe1e7a8f65e8c51c6fd1ab.tar.gz |
New testcases for array_sum() function
-rw-r--r-- | ext/standard/tests/array/array_sum_basic.phpt | 46 | ||||
-rw-r--r-- | ext/standard/tests/array/array_sum_error.phpt | 45 | ||||
-rw-r--r-- | ext/standard/tests/array/array_sum_variation1.phpt | 274 | ||||
-rw-r--r-- | ext/standard/tests/array/array_sum_variation2.phpt | 60 | ||||
-rw-r--r-- | ext/standard/tests/array/array_sum_variation3.phpt | 64 | ||||
-rw-r--r-- | ext/standard/tests/array/array_sum_variation4.phpt | 41 | ||||
-rw-r--r-- | ext/standard/tests/array/array_sum_variation5.phpt | 42 | ||||
-rw-r--r-- | ext/standard/tests/array/array_sum_variation6.phpt | 40 | ||||
-rw-r--r-- | ext/standard/tests/array/array_sum_variation7.phpt | 103 |
9 files changed, 715 insertions, 0 deletions
diff --git a/ext/standard/tests/array/array_sum_basic.phpt b/ext/standard/tests/array/array_sum_basic.phpt new file mode 100644 index 0000000000..c41d0ad0e2 --- /dev/null +++ b/ext/standard/tests/array/array_sum_basic.phpt @@ -0,0 +1,46 @@ +--TEST-- +Test array_sum() function : basic functionality +--FILE-- +<?php +/* Prototype : mixed array_sum(array &input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_sum() : basic functionality ***\n"; + +// array with integer values +$input = array(1, 2, 3, 4, 5); +echo "-- array_sum() with integer array entries --\n"; +var_dump( array_sum($input) ); + +// array with float values +$input = array(1.0, 2.2, 3.4, 4.6); +echo "-- array_sum() with float array entries --\n"; +var_dump( array_sum($input) ); + +// array with integer and float values +$input = array(1, 2.3, 4, 0.6, 10); +echo "-- array_sum() with integer/float array entries --\n"; +var_dump( array_sum($input) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : basic functionality *** +-- array_sum() with integer array entries -- +int(15) +-- array_sum() with float array entries -- +float(11.2) +-- array_sum() with integer/float array entries -- +float(17.9) +Done +--UEXPECTF-- +*** Testing array_sum() : basic functionality *** +-- array_sum() with integer array entries -- +int(15) +-- array_sum() with float array entries -- +float(11.2) +-- array_sum() with integer/float array entries -- +float(17.9) +Done diff --git a/ext/standard/tests/array/array_sum_error.phpt b/ext/standard/tests/array/array_sum_error.phpt new file mode 100644 index 0000000000..d15ca71d44 --- /dev/null +++ b/ext/standard/tests/array/array_sum_error.phpt @@ -0,0 +1,45 @@ +--TEST-- +Test array_sum() function : error conditions +--FILE-- +<?php +/* Prototype : mixed array_sum(array &input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +echo "*** Testing array_sum() : error conditions ***\n"; + +// Zero arguments +echo "-- Testing array_sum() function with zero arguments --\n"; +var_dump( array_sum() ); + +// One more than the expected number of arguments +echo "-- Testing array_sum() function with more than expected no. of arguments --\n"; +$input = array(1, 2, 3, 4); +$extra_arg = 10; +var_dump( array_sum($input, $extra_arg) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : error conditions *** +-- Testing array_sum() function with zero arguments -- + +Warning: array_sum() expects exactly 1 parameter, 0 given in %s on line %d +NULL +-- Testing array_sum() function with more than expected no. of arguments -- + +Warning: array_sum() expects exactly 1 parameter, 2 given in %s on line %d +NULL +Done +--UEXPECTF-- +*** Testing array_sum() : error conditions *** +-- Testing array_sum() function with zero arguments -- + +Warning: array_sum() expects exactly 1 parameter, 0 given in %s on line %d +NULL +-- Testing array_sum() function with more than expected no. of arguments -- + +Warning: array_sum() expects exactly 1 parameter, 2 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_sum_variation1.phpt b/ext/standard/tests/array/array_sum_variation1.phpt new file mode 100644 index 0000000000..c0470673b5 --- /dev/null +++ b/ext/standard/tests/array/array_sum_variation1.phpt @@ -0,0 +1,274 @@ +--TEST-- +Test array_sum() function : usage variations - unexpected values for 'input' argument +--FILE-- +<?php +/* Prototype : mixed array_sum(array $input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +/* +* Passing different scalar/nonscalar values as 'input' argument to array_sum() +*/ + +echo "*** Testing array_sum() : unexpected values for 'input' ***\n"; + +// get an unset variable +$unset_var = 10; +unset ($unset_var); + +// Class definition +class MyClass +{ + public function __toString() + { + return "object"; + } +} + +// different scalar/non scalar values for 'input' argument +$input_values = array( + + // int data +/* 1 */ 0, + 1, + 12345, +/* 4 */ -2345, + + // float data +/* 5 */ 10.5, + -10.5, + 10.1234567e8, + 10.7654321E-8, +/* 9 */ .5, + + // null data +/* 10*/ NULL, + null, + + // boolean data +/* 12*/ true, + false, + TRUE, + FALSE, + + // empty data +/* 16*/ "", + '', + + // string data +/* 18*/ "string", + 'string', + + // object data +/* 20*/ new MyClass(), + + // resource data + $fp = fopen(__FILE__,'r'), + + // undefined data + @$undefined_var, + + // unset data +/* 23*/ @$unset_var, +); + +// loop through each element of the array for input +for($count = 0; $count < count($input_values); $count++) { + echo "-- Iteration ".($count + 1)." --\n"; + var_dump( array_sum($input_values[$count]) ); +}; + +fclose($fp); +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : unexpected values for 'input' *** +-- Iteration 1 -- + +Warning: array_sum() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 2 -- + +Warning: array_sum() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_sum() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_sum() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_sum() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_sum() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_sum() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_sum() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_sum() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_sum() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_sum() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: array_sum() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: array_sum() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: array_sum() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 15 -- + +Warning: array_sum() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 16 -- + +Warning: array_sum() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: array_sum() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: array_sum() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_sum() expects parameter 1 to be array, string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_sum() expects parameter 1 to be array, object given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_sum() expects parameter 1 to be array, resource given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_sum() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 23 -- + +Warning: array_sum() expects parameter 1 to be array, null given in %s on line %d +NULL +Done +--UEXPECTF-- +*** Testing array_sum() : unexpected values for 'input' *** +-- Iteration 1 -- + +Warning: array_sum() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 2 -- + +Warning: array_sum() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 3 -- + +Warning: array_sum() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 4 -- + +Warning: array_sum() expects parameter 1 to be array, integer given in %s on line %d +NULL +-- Iteration 5 -- + +Warning: array_sum() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 6 -- + +Warning: array_sum() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 7 -- + +Warning: array_sum() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 8 -- + +Warning: array_sum() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 9 -- + +Warning: array_sum() expects parameter 1 to be array, double given in %s on line %d +NULL +-- Iteration 10 -- + +Warning: array_sum() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 11 -- + +Warning: array_sum() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 12 -- + +Warning: array_sum() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 13 -- + +Warning: array_sum() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 14 -- + +Warning: array_sum() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 15 -- + +Warning: array_sum() expects parameter 1 to be array, boolean given in %s on line %d +NULL +-- Iteration 16 -- + +Warning: array_sum() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL +-- Iteration 17 -- + +Warning: array_sum() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL +-- Iteration 18 -- + +Warning: array_sum() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL +-- Iteration 19 -- + +Warning: array_sum() expects parameter 1 to be array, Unicode string given in %s on line %d +NULL +-- Iteration 20 -- + +Warning: array_sum() expects parameter 1 to be array, object given in %s on line %d +NULL +-- Iteration 21 -- + +Warning: array_sum() expects parameter 1 to be array, resource given in %s on line %d +NULL +-- Iteration 22 -- + +Warning: array_sum() expects parameter 1 to be array, null given in %s on line %d +NULL +-- Iteration 23 -- + +Warning: array_sum() expects parameter 1 to be array, null given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_sum_variation2.phpt b/ext/standard/tests/array/array_sum_variation2.phpt new file mode 100644 index 0000000000..1ff90e8a3b --- /dev/null +++ b/ext/standard/tests/array/array_sum_variation2.phpt @@ -0,0 +1,60 @@ +--TEST-- +Test array_sum() function : usage variations - array with different integer value +--FILE-- +<?php +/* Prototype : mixed array_sum(array &input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_sum() with different types of integer arrays containing data of following type: +* integer, octal, hexadecimal, maximum and minimum integer values & mixed of all integers +*/ + +echo "*** Testing array_sum() : with different integer array ***\n"; + +// Int array +$int_values = array(3, 2, 100, 150, 25, 350, 0, -3, -1200); +echo "-- Sum of Integer array --\n"; +var_dump( array_sum($int_values) ); + +// Octal array +$octal_values = array(056, 023, 090, 015, -045, 01, -078); +echo "-- Sum of Octal array --\n"; +var_dump( array_sum($octal_values) ); + +// Hexadecimal array +$hex_values = array(0xAE, 0x2B, 0X10, -0xCF, 0X12, -0XF2); +echo "-- Sum of Hex array --\n"; +var_dump( array_sum($hex_values) ); + +// Mixed values int, octal & hex +$mixed_int_value = array(2, 5, -1, 054, 0X3E, 0, -014, -0x2A); +echo "-- Sum of mixed integer values --\n"; +var_dump( array_sum($mixed_int_value) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : with different integer array *** +-- Sum of Integer array -- +int(-573) +-- Sum of Octal array -- +int(35) +-- Sum of Hex array -- +int(-198) +-- Sum of mixed integer values -- +int(58) +Done +--UEXPECTF-- +*** Testing array_sum() : with different integer array *** +-- Sum of Integer array -- +int(-573) +-- Sum of Octal array -- +int(35) +-- Sum of Hex array -- +int(-198) +-- Sum of mixed integer values -- +int(58) +Done diff --git a/ext/standard/tests/array/array_sum_variation3.phpt b/ext/standard/tests/array/array_sum_variation3.phpt new file mode 100644 index 0000000000..8e5b0e308e --- /dev/null +++ b/ext/standard/tests/array/array_sum_variation3.phpt @@ -0,0 +1,64 @@ +--TEST-- +Test array_sum() function : usage variations - array with different float values +--FILE-- +<?php +/* Prototype : mixed array_sum(array $input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +/* + * sum of array containing different float values +*/ + +echo "*** Testing array_sum() : array with different float values ***\n"; + +// Simple float array +$float_input = array( 1.1, 2.3, 0.0, 0.5, -2.3, -0.8, .5); +echo "-- simple float array --\n"; +var_dump( array_sum($float_input) ); + +// float array with scientific notations +$float_input = array( 1.2e2, 23.4e3, -4.1e2, 0.2e2, 2.1e-2, .5e3); +echo "-- float array with scientific notations e and E --\n"; +var_dump( array_sum($float_input) ); +$float_input = array( 1.2E2, 23.4E3, -4.1E2, 0.2E2, 2.1E-2, .5E2); +var_dump( array_sum($float_input) ); + +// Mixed float array +$float_input = array( + 1.2, + 0.5 + -5.8, + 6.334, + -0.65, + 1.2e3, + -2.3e2, + 5.56E3, + -3.82E-2 +); +echo "-- Mixed float array --\n"; +var_dump( array_sum($float_input) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : array with different float values *** +-- simple float array -- +float(1.3) +-- float array with scientific notations e and E -- +float(23630.021) +float(23180.021) +-- Mixed float array -- +float(6531.5458) +Done +--UEXPECTF-- +*** Testing array_sum() : array with different float values *** +-- simple float array -- +float(1.3) +-- float array with scientific notations e and E -- +float(23630.021) +float(23180.021) +-- Mixed float array -- +float(6531.5458) +Done diff --git a/ext/standard/tests/array/array_sum_variation4.phpt b/ext/standard/tests/array/array_sum_variation4.phpt new file mode 100644 index 0000000000..3dc685aa0a --- /dev/null +++ b/ext/standard/tests/array/array_sum_variation4.phpt @@ -0,0 +1,41 @@ +--TEST-- +Test array_sum() function : usage variations - array with duplicate values +--FILE-- +<?php +/* Prototype : mixed array_sum(array $input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +/* +* Checking array_sum() with integer and float array containing duplicate values +*/ + +echo "*** Testing array_sum() : array with duplicate values ***\n"; + +// integer array with duplicate values +$int_input = array( 2, 5, 7, 5, 0, -4, 2, 100); +echo "-- With integer array --\n"; +var_dump( array_sum($int_input) ); + +// float array with duplicate values +$float_input = array( 2.3, 1.9, -4.1, 0.5, 1.9, -4.1, 3.6, 0.5); +echo "-- With float array --\n"; +var_dump( array_sum($float_input) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : array with duplicate values *** +-- With integer array -- +int(117) +-- With float array -- +float(2.5) +Done +--UEXPECTF-- +*** Testing array_sum() : array with duplicate values *** +-- With integer array -- +int(117) +-- With float array -- +float(2.5) +Done diff --git a/ext/standard/tests/array/array_sum_variation5.phpt b/ext/standard/tests/array/array_sum_variation5.phpt new file mode 100644 index 0000000000..231f692c7f --- /dev/null +++ b/ext/standard/tests/array/array_sum_variation5.phpt @@ -0,0 +1,42 @@ +--TEST-- +Test array_sum() function : usage variations - array with reference variables +--FILE-- +<?php +/* Prototype : mixed array_sum(array $input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_sum() with 'input' containing different reference variables +*/ + +echo "*** Testing array_sum() : array with elements as reference ***\n"; + +// different variables which are used as elements of 'array_arg' +$value1 = -5; +$value2 = 100; +$value3 = 0; +$value4 = &$value1; + +// input an array containing elements with reference variables +$input = array( + 0 => 10, + 1 => &$value4, + 2 => &$value2, + 3 => 200, + 4 => &$value3, +); + +var_dump( array_sum($input) ); + +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : array with elements as reference *** +int(305) +Done +--UEXPECTF-- +*** Testing array_sum() : array with elements as reference *** +int(305) +Done diff --git a/ext/standard/tests/array/array_sum_variation6.phpt b/ext/standard/tests/array/array_sum_variation6.phpt new file mode 100644 index 0000000000..404b0af669 --- /dev/null +++ b/ext/standard/tests/array/array_sum_variation6.phpt @@ -0,0 +1,40 @@ +--TEST-- +Test array_sum() function : usage variations - associative array +--FILE-- +<?php +/* Prototype : mixed array_sum(array $input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_sum() with associative array as 'input' argument +*/ + +echo "*** Testing array_sum() : with associative array ***\n"; + +// array with numeric keys +$input = array(0 => 1, 1 => 10, 2 => 0, 3 => -2, 4 => 23.56); +echo "-- with numeric keys --\n"; +var_dump( array_sum($input) ); + +// array with string keys +$input = array('a' => 20, "b" => 50, 'c' => 0, 'd' => -30, "e" => 100); +echo "-- with string keys --\n"; +var_dump( array_sum($input) ); +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : with associative array *** +-- with numeric keys -- +float(32.56) +-- with string keys -- +int(140) +Done +--UEXPECTF-- +*** Testing array_sum() : with associative array *** +-- with numeric keys -- +float(32.56) +-- with string keys -- +int(140) +Done diff --git a/ext/standard/tests/array/array_sum_variation7.phpt b/ext/standard/tests/array/array_sum_variation7.phpt new file mode 100644 index 0000000000..03915e6e34 --- /dev/null +++ b/ext/standard/tests/array/array_sum_variation7.phpt @@ -0,0 +1,103 @@ +--TEST-- +Test array_sum() function : usage variations - 'input' array with unexpected values as array element +--FILE-- +<?php +/* Prototype : mixed array_sum(array $input) + * Description: Returns the sum of the array entries + * Source code: ext/standard/array.c +*/ + +/* +* Testing array_sum() with array having other than numeric entries +* strings, bool, null, subarrays, objects +*/ + +echo "*** Testing array_sum() : array with unexpected entries ***\n"; + +// empty array +$input = array(); +echo "-- empty array --\n"; +var_dump( array_sum($input) ); + +// string array +$input = array('Apple', 'Banana', 'Carrot', 'Mango', 'Orange'); +echo "-- array with string values --\n"; +var_dump( array_sum($input) ); + +// bool array +$input = array( true, true, false, true, false); +echo "-- array with bool values --\n"; +var_dump( array_sum($input) ); + +// array with null entry +$input = array(null, NULL); +echo "-- array with null values --\n"; +var_dump( array_sum($input) ); + +// array with subarray +$input = array( + array(1, 2), + array(), + array(0) +); +echo "-- array with subarrays --\n"; +var_dump( array_sum($input) ); + +class MyClass +{ + public $value; + public function __construct($value) + { + $this->value = $value; + } +} +// array of objects +$input = array( + new MyClass(2), + new MyClass(5), + new MyClass(10), + new MyClass(0) +); +echo "-- array with object values --\n"; +var_dump( array_sum($input) ); + +// Mixed values +$input = array( 5, -8, 7.2, -1.2, "10", "apple", 'Mango', true, false, null, NULL, array( array(1,2), array(0), array())); +echo "-- array with mixed values --\n"; +var_dump( array_sum($input) ); +echo "Done" +?> +--EXPECTF-- +*** Testing array_sum() : array with unexpected entries *** +-- empty array -- +int(0) +-- array with string values -- +int(0) +-- array with bool values -- +int(3) +-- array with null values -- +int(0) +-- array with subarrays -- +int(0) +-- array with object values -- +int(0) +-- array with mixed values -- +float(14) +Done +--UEXPECTF-- +*** Testing array_sum() : array with unexpected entries *** +-- empty array -- +int(0) +-- array with string values -- +int(0) +-- array with bool values -- +int(3) +-- array with null values -- +int(0) +-- array with subarrays -- +int(0) +-- array with object values -- +int(0) +-- array with mixed values -- +float(14) +Done |