From: Raghubansh Kumar Date: Sun, 9 Dec 2007 14:41:10 +0000 (+0000) Subject: new testcases for array_unique() function X-Git-Tag: RELEASE_1_3_1~533 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ccb0f19d1cb88031eb1524125f35cebf2a1f0972;p=php new testcases for array_unique() function --- diff --git a/ext/standard/tests/array/array_unique_basic.phpt b/ext/standard/tests/array/array_unique_basic.phpt new file mode 100644 index 0000000000..58d3acf1be --- /dev/null +++ b/ext/standard/tests/array/array_unique_basic.phpt @@ -0,0 +1,48 @@ +--TEST-- +Test array_unique() function : basic functionality +--FILE-- + "one", 1 => "one", 2 => "two", '2' => "two"); +var_dump( array_unique($input) ); + +// mixed array +$input = array("1" => "one", "two", "one", 2 => "two", "three"); +var_dump( array_unique($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : basic functionality *** +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +array(3) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" + [4]=> + string(5) "three" +} +Done diff --git a/ext/standard/tests/array/array_unique_error.phpt b/ext/standard/tests/array/array_unique_error.phpt new file mode 100644 index 0000000000..05c10ac765 --- /dev/null +++ b/ext/standard/tests/array/array_unique_error.phpt @@ -0,0 +1,36 @@ +--TEST-- +Test array_unique() function : error conditions +--FILE-- + +--EXPECTF-- +*** Testing array_unique() : error conditions *** + +-- Testing array_unique() function with zero arguments -- + +Warning: array_unique() expects exactly 1 parameter, 0 given in %s on line %d +NULL + +-- Testing array_unique() function with more than expected no. of arguments -- + +Warning: array_unique() expects exactly 1 parameter, 2 given in %s on line %d +NULL +Done diff --git a/ext/standard/tests/array/array_unique_variation1.phpt b/ext/standard/tests/array/array_unique_variation1.phpt new file mode 100644 index 0000000000..8029807bb6 --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation1.phpt @@ -0,0 +1,194 @@ +--TEST-- +Test array_unique() function : usage variations - unexpected values for 'input' argument +--FILE-- + +--EXPECTF-- +*** Testing array_unique() : Passing non array values to $input argument *** +-- Iteration 1 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 2 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 3 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 4 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 5 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 6 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 7 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 8 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 9 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 10 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 11 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 12 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 13 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 14 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 15 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 16 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 17 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 18 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 19 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 20 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 21 -- +array(0) { +} +-- Iteration 22 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 23 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +-- Iteration 24 -- + +Warning: array_unique(): The argument should be an array in %s on line %d +bool(false) +Done diff --git a/ext/standard/tests/array/array_unique_variation2.phpt b/ext/standard/tests/array/array_unique_variation2.phpt new file mode 100644 index 0000000000..b821861bb3 --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation2.phpt @@ -0,0 +1,234 @@ +--TEST-- +Test array_unique() function : usage variations - different arrays for 'input' argument +--FILE-- +22 +'single quoted string' +"double quoted string" +2222 != 1111.\t 0000 = 0000\n +EOT; + +// arrays passed to $input argument +$inputs = array ( +/*1*/ array(1, 2, 2, 1), // with default keys and numeric values + array(1.1, 2.2, 1.1), // with default keys & float values + array(false, true, false), // with default keys and boolean values + array(), // empty array +/*5*/ array(NULL, null), // with NULL + array("a\v\f", "aaaa\r", "b", "aaaa\r", "\[\]\!\@\#\$\%\^\&\*\(\)\{\}"), // with double quoted strings + array('a\v\f', 'aaaa\r', 'b', 'aaaa\r', '\[\]\!\@\#\$\%\^\&\*\(\)\{\}'), // with single quoted strings + array("h1" => $blank_line, "h2" => $multiline_string, "h3" => $diff_whitespaces, $blank_line), // with heredocs + + // associative arrays +/*9*/ array(1 => "one", 2 => "two", 2 => "two"), // explicit numeric keys, string values + array("one" => 1, "two" => 2, "1" => 1 ), // string keys & numeric values + array( 1 => 10, 2 => 20, 4 => 40, 5 => 10), // explicit numeric keys and numeric values + array( "one" => "ten", "two" => "twenty", "10" => "ten"), // string key/value + array("one" => 1, 2 => "two", 4 => "four"), //mixed + + // associative array, containing null/empty/boolean values as key/value +/*14*/ array(NULL => "NULL", null => "null", "NULL" => NULL, "null" => null), + array(true => "true", false => "false", "false" => false, "true" => true), + array("" => "emptyd", '' => 'emptys', "emptyd" => "", 'emptys' => ''), + array(1 => '', 2 => "", 3 => NULL, 4 => null, 5 => false, 6 => true), +/*18*/ array('' => 1, "" => 2, NULL => 3, null => 4, false => 5, true => 6), +); + +// loop through each sub-array of $inputs to check the behavior of array_unique() +$iterator = 1; +foreach($inputs as $input) { + echo "-- Iteration $iterator --\n"; + var_dump( array_unique($input) ); + $iterator++; +} + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : Passing different arrays to $input argument *** +-- Iteration 1 -- +array(2) { + [0]=> + int(1) + [1]=> + int(2) +} +-- Iteration 2 -- +array(2) { + [0]=> + float(1.1) + [1]=> + float(2.2) +} +-- Iteration 3 -- +array(2) { + [0]=> + bool(false) + [1]=> + bool(true) +} +-- Iteration 4 -- +array(0) { +} +-- Iteration 5 -- +array(1) { + [0]=> + NULL +} +-- Iteration 6 -- +array(4) { + [0]=> + string(3) "a " + [1]=> + string(5) "aaaa +" + [2]=> + string(1) "b" + [4]=> + string(27) "\[\]\!\@\#$\%\^\&\*\(\)\{\}" +} +-- Iteration 7 -- +array(4) { + [0]=> + string(5) "a\v\f" + [1]=> + string(6) "aaaa\r" + [2]=> + string(1) "b" + [4]=> + string(28) "\[\]\!\@\#\$\%\^\&\*\(\)\{\}" +} +-- Iteration 8 -- +array(3) { + ["h1"]=> + string(1) " +" + ["h2"]=> + string(88) "hello world +The quick brown fox jumped over; +the lazy dog +This is a double quoted string" + ["h3"]=> + string(88) "hello + world +1111 != 2222 +heredoc +double quoted string. with different white spaces" +} +-- Iteration 9 -- +array(2) { + [1]=> + string(3) "one" + [2]=> + string(3) "two" +} +-- Iteration 10 -- +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +-- Iteration 11 -- +array(3) { + [1]=> + int(10) + [2]=> + int(20) + [4]=> + int(40) +} +-- Iteration 12 -- +array(2) { + ["one"]=> + string(3) "ten" + ["two"]=> + string(6) "twenty" +} +-- Iteration 13 -- +array(3) { + ["one"]=> + int(1) + [2]=> + string(3) "two" + [4]=> + string(4) "four" +} +-- Iteration 14 -- +array(2) { + [""]=> + string(4) "null" + ["NULL"]=> + NULL +} +-- Iteration 15 -- +array(4) { + [1]=> + string(4) "true" + [0]=> + string(5) "false" + ["false"]=> + bool(false) + ["true"]=> + bool(true) +} +-- Iteration 16 -- +array(2) { + [""]=> + string(6) "emptys" + ["emptyd"]=> + string(0) "" +} +-- Iteration 17 -- +array(2) { + [1]=> + string(0) "" + [6]=> + bool(true) +} +-- Iteration 18 -- +array(3) { + [""]=> + int(4) + [0]=> + int(5) + [1]=> + int(6) +} +Done diff --git a/ext/standard/tests/array/array_unique_variation3.phpt b/ext/standard/tests/array/array_unique_variation3.phpt new file mode 100644 index 0000000000..49103c8154 --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation3.phpt @@ -0,0 +1,134 @@ +--TEST-- +Test array_unique() function : usage variations - associative array with different keys +--FILE-- + "0", 1 => "0"), + array(1 => "1", 2 => "2", 3 => 1, 4 => "4"), + + // arrays with float keys +/*3*/ array(2.3333 => "float", 44.44 => "float"), + array(1.2 => "f1", 3.33 => "f2", 4.89999922839999 => "f1", 3333333.333333 => "f4"), + + // arrays with string keys +/*5*/ array('\tHello' => 111, 're\td' => "color", '\v\fworld' => 2.2, 'pen\n' => 111), + array("\tHello" => 111, "re\td" => "color", "\v\fworld" => 2.2, "pen\n" => 111), + array("hello", $heredoc => "string", "string"), + + // array with object, unset variable and resource variable +/*8*/ array(new classA() => 11, @$unset_var => "hello", $fp => 'resource', 11, "hello"), +); + +// loop through each sub-array of $inputs to check the behavior of array_unique() +$iterator = 1; +foreach($inputs as $input) { + echo "-- Iteration $iterator --\n"; + var_dump( array_unique($input) ); + $iterator++; +} + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : assoc. array with diff. keys passed to $input argument *** + +Warning: Illegal offset type in %s on line %d + +Warning: Illegal offset type in %s on line %d +-- Iteration 1 -- +array(1) { + [0]=> + string(1) "0" +} +-- Iteration 2 -- +array(3) { + [1]=> + string(1) "1" + [2]=> + string(1) "2" + [4]=> + string(1) "4" +} +-- Iteration 3 -- +array(1) { + [2]=> + string(5) "float" +} +-- Iteration 4 -- +array(3) { + [1]=> + string(2) "f1" + [3]=> + string(2) "f2" + [3333333]=> + string(2) "f4" +} +-- Iteration 5 -- +array(3) { + ["\tHello"]=> + int(111) + ["re\td"]=> + string(5) "color" + ["\v\fworld"]=> + float(2.2) +} +-- Iteration 6 -- +array(3) { + [" Hello"]=> + int(111) + ["re d"]=> + string(5) "color" + [" world"]=> + float(2.2) +} +-- Iteration 7 -- +array(2) { + [0]=> + string(5) "hello" + ["Hello world"]=> + string(6) "string" +} +-- Iteration 8 -- +array(2) { + [""]=> + string(5) "hello" + [0]=> + int(11) +} +Done diff --git a/ext/standard/tests/array/array_unique_variation4.phpt b/ext/standard/tests/array/array_unique_variation4.phpt new file mode 100644 index 0000000000..a1fc13e94d --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation4.phpt @@ -0,0 +1,131 @@ +--TEST-- +Test array_unique() function : usage variations - associative array with different values +--FILE-- + 0, '1' => 0), + array("one" => 1, 'two' => 2, "three" => 1, 4 => 1), + + // arrays with float values +/*3*/ array("float1" => 2.3333, "float2" => 2.3333), + array("f1" => 1.2, 'f2' => 3.33, 3 => 4.89999922839999, 'f4' => 1.2), + + // arrays with string values +/*5*/ array(111 => "\tHello", "red" => "col\tor", 2 => "\v\fworld", 3.3 => "\tHello"), + array(111 => '\tHello', "red" => 'col\tor', 2 => '\v\fworld', 3.3 => '\tHello'), + array(1 => "hello", "heredoc" => $heredoc, $heredoc), + + // array with object, unset variable and resource variable +/*8*/ array(11 => new classA(), "unset" => @$unset_var, "resource" => $fp, new classA(), $fp), +); + +// loop through each sub-array of $inputs to check the behavior of array_unique() +$iterator = 1; +foreach($inputs as $input) { + echo "-- Iteration $iterator --\n"; + var_dump( array_unique($input) ); + $iterator++; +} + +fclose($fp); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : assoc. array with diff. values to $input argument *** +-- Iteration 1 -- +array(1) { + [0]=> + int(0) +} +-- Iteration 2 -- +array(2) { + ["one"]=> + int(1) + ["two"]=> + int(2) +} +-- Iteration 3 -- +array(1) { + ["float1"]=> + float(2.3333) +} +-- Iteration 4 -- +array(3) { + ["f1"]=> + float(1.2) + ["f2"]=> + float(3.33) + [3]=> + float(4.8999992284) +} +-- Iteration 5 -- +array(3) { + [111]=> + string(6) " Hello" + ["red"]=> + string(6) "col or" + [2]=> + string(7) " world" +} +-- Iteration 6 -- +array(3) { + [111]=> + string(7) "\tHello" + ["red"]=> + string(7) "col\tor" + [2]=> + string(9) "\v\fworld" +} +-- Iteration 7 -- +array(2) { + [1]=> + string(5) "hello" + ["heredoc"]=> + string(11) "Hello world" +} +-- Iteration 8 -- +array(3) { + [11]=> + object(classA)#%d (0) { + } + ["unset"]=> + NULL + ["resource"]=> + resource(%d) of type (stream) +} +Done diff --git a/ext/standard/tests/array/array_unique_variation5.phpt b/ext/standard/tests/array/array_unique_variation5.phpt new file mode 100644 index 0000000000..5e3f7c36d0 --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation5.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test array_unique() function : usage variations - array with duplicate keys +--FILE-- + "one", 2 => "two", 2 => "2", 3 => "three", 1 => "1", "1", "2"); +var_dump( array_unique($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : array with duplicate keys for $input argument *** +array(3) { + [1]=> + string(1) "1" + [2]=> + string(1) "2" + [3]=> + string(5) "three" +} +Done diff --git a/ext/standard/tests/array/array_unique_variation6.phpt b/ext/standard/tests/array/array_unique_variation6.phpt new file mode 100644 index 0000000000..fd8b226fab --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation6.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test array_unique() function : usage variations - array with reference variables +--FILE-- + 0, + 1 => &$value4, + 2 => &$value2, + 3 => "hello", + 4 => &$value3, + 5 => $value4 +); + +var_dump( array_unique($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : array with reference variables for $input argument *** +array(2) { + [0]=> + int(0) + [1]=> + &string(5) "hello" +} +Done diff --git a/ext/standard/tests/array/array_unique_variation7.phpt b/ext/standard/tests/array/array_unique_variation7.phpt new file mode 100644 index 0000000000..e998a73c6c --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation7.phpt @@ -0,0 +1,33 @@ +--TEST-- +Test array_unique() function : usage variations - binary safe checking +--FILE-- + "hello", "str2" => "world"); + +var_dump( array_unique($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : array with binary data for $input argument *** +array(3) { + [0]=> + string(1) "1" + [1]=> + string(5) "hello" + [2]=> + string(5) "world" +} +Done diff --git a/ext/standard/tests/array/array_unique_variation8.phpt b/ext/standard/tests/array/array_unique_variation8.phpt new file mode 100644 index 0000000000..ae6e8bb5c1 --- /dev/null +++ b/ext/standard/tests/array/array_unique_variation8.phpt @@ -0,0 +1,44 @@ +--TEST-- +Test array_unique() function : usage variations - two dimensional arrays +--FILE-- + "hello", "str2" => 'world'), + array(1 => "one", 2 => "two", "one", 'two'), + array(1, 2, 3, 1) +); + +var_dump( array_unique($input) ); + +echo "Done"; +?> +--EXPECTF-- +*** Testing array_unique() : two dimensional array for $input argument *** +array(1) { + [0]=> + array(4) { + [0]=> + int(1) + [1]=> + int(2) + [2]=> + int(3) + [3]=> + int(1) + } +} +Done