mirror of
https://github.com/php/php-src.git
synced 2025-01-08 20:17:28 +08:00
new testcases for array_unique() function
This commit is contained in:
parent
6484b3c458
commit
ccb0f19d1c
48
ext/standard/tests/array/array_unique_basic.phpt
Normal file
48
ext/standard/tests/array/array_unique_basic.phpt
Normal file
@ -0,0 +1,48 @@
|
||||
--TEST--
|
||||
Test array_unique() function : basic functionality
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_unique(array $input)
|
||||
* Description: Removes duplicate values from array
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
echo "*** Testing array_unique() : basic functionality ***\n";
|
||||
|
||||
// array with default keys
|
||||
$input = array(1, 2, "1", '2');
|
||||
var_dump( array_unique($input) );
|
||||
|
||||
// associative array
|
||||
$input = array("1" => "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
|
36
ext/standard/tests/array/array_unique_error.phpt
Normal file
36
ext/standard/tests/array/array_unique_error.phpt
Normal file
@ -0,0 +1,36 @@
|
||||
--TEST--
|
||||
Test array_unique() function : error conditions
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_unique(array $input)
|
||||
* Description: Removes duplicate values from array
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
echo "*** Testing array_unique() : error conditions ***\n";
|
||||
|
||||
// Zero arguments
|
||||
echo "\n-- Testing array_unique() function with zero arguments --\n";
|
||||
var_dump( array_unique() );
|
||||
|
||||
//Test array_unique with one more than the expected number of arguments
|
||||
echo "\n-- Testing array_unique() function with more than expected no. of arguments --\n";
|
||||
$input = array(1, 2);
|
||||
$extra_arg = 10;
|
||||
var_dump( array_unique($input, $extra_arg) );
|
||||
|
||||
echo "Done";
|
||||
?>
|
||||
--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
|
194
ext/standard/tests/array/array_unique_variation1.phpt
Normal file
194
ext/standard/tests/array/array_unique_variation1.phpt
Normal file
@ -0,0 +1,194 @@
|
||||
--TEST--
|
||||
Test array_unique() function : usage variations - unexpected values for 'input' argument
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_unique(array $input)
|
||||
* Description: Removes duplicate values from array
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* Passing non array values to 'input' argument of array_unique() and see
|
||||
* that the function outputs proper warning messages wherever expected.
|
||||
*/
|
||||
|
||||
echo "*** Testing array_unique() : Passing non array values to \$input argument ***\n";
|
||||
|
||||
//get an unset variable
|
||||
$unset_var = 10;
|
||||
unset($unset_var);
|
||||
|
||||
// get a class
|
||||
class classA
|
||||
{
|
||||
public function __toString() {
|
||||
return "Class A object";
|
||||
}
|
||||
}
|
||||
|
||||
// heredoc string
|
||||
$heredoc = <<<EOT
|
||||
hello world
|
||||
EOT;
|
||||
|
||||
// get a resource variable
|
||||
$fp = fopen(__FILE__, "r");
|
||||
|
||||
// unexpected values to be passed to $input argument
|
||||
$inputs = array (
|
||||
|
||||
// int data
|
||||
/*1*/ 0,
|
||||
1,
|
||||
12345,
|
||||
-2345,
|
||||
|
||||
// float data
|
||||
/*5*/ 10.5,
|
||||
-10.5,
|
||||
12.3456789000e10,
|
||||
12.3456789000E-10,
|
||||
.5,
|
||||
|
||||
// null data
|
||||
/*10*/ NULL,
|
||||
null,
|
||||
|
||||
// boolean data
|
||||
/*12*/ true,
|
||||
false,
|
||||
TRUE,
|
||||
FALSE,
|
||||
|
||||
// empty data
|
||||
/*16*/ "",
|
||||
'',
|
||||
|
||||
// string data
|
||||
/*18*/ "string",
|
||||
'string',
|
||||
$heredoc,
|
||||
|
||||
// object data
|
||||
/*21*/ new classA(),
|
||||
|
||||
// undefined data
|
||||
/*22*/ @$undefined_var,
|
||||
|
||||
// unset data
|
||||
/*23*/ @$unset_var,
|
||||
|
||||
// resource variable
|
||||
/*24*/ $fp
|
||||
);
|
||||
|
||||
// loop through each element of $inputs and 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() : 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
|
234
ext/standard/tests/array/array_unique_variation2.phpt
Normal file
234
ext/standard/tests/array/array_unique_variation2.phpt
Normal file
@ -0,0 +1,234 @@
|
||||
--TEST--
|
||||
Test array_unique() function : usage variations - different arrays for 'input' argument
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_unique(array $input)
|
||||
* Description: Removes duplicate values from array
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* Passing different arrays to $input argument and testing whether
|
||||
* array_unique() behaves in an expected way.
|
||||
*/
|
||||
|
||||
echo "*** Testing array_unique() : Passing different arrays to \$input argument ***\n";
|
||||
|
||||
/* Different heredoc strings passed as argument to arrays */
|
||||
// heredoc with blank line
|
||||
$blank_line = <<<EOT
|
||||
|
||||
|
||||
EOT;
|
||||
|
||||
// heredoc with multiline string
|
||||
$multiline_string = <<<EOT
|
||||
hello world
|
||||
The quick brown fox jumped over;
|
||||
the lazy dog
|
||||
This is a double quoted string
|
||||
EOT;
|
||||
|
||||
// heredoc with diferent whitespaces
|
||||
$diff_whitespaces = <<<EOT
|
||||
hello\r world\t
|
||||
1111\t\t != 2222\v\v
|
||||
heredoc\ndouble quoted string. with\vdifferent\fwhite\vspaces
|
||||
EOT;
|
||||
|
||||
// heredoc with quoted strings and numeric values
|
||||
$numeric_string = <<<EOT
|
||||
11 < 12. 123 >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. withdifferentwhitespaces"
|
||||
}
|
||||
-- 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
|
134
ext/standard/tests/array/array_unique_variation3.phpt
Normal file
134
ext/standard/tests/array/array_unique_variation3.phpt
Normal file
@ -0,0 +1,134 @@
|
||||
--TEST--
|
||||
Test array_unique() function : usage variations - associative array with different keys
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_unique(array $input)
|
||||
* Description: Removes duplicate values from array
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* Testing the functionality of array_unique() by passing different
|
||||
* associative arrays having different keys to $input argument.
|
||||
*/
|
||||
|
||||
echo "*** Testing array_unique() : assoc. array with diff. keys passed to \$input argument ***\n";
|
||||
|
||||
// get an unset variable
|
||||
$unset_var = 10;
|
||||
unset ($unset_var);
|
||||
|
||||
// get a resource variable
|
||||
$fp = fopen(__FILE__, "r");
|
||||
|
||||
// get a class
|
||||
class classA
|
||||
{
|
||||
public function __toString(){
|
||||
return "Class A object";
|
||||
}
|
||||
}
|
||||
|
||||
// get a heredoc string
|
||||
$heredoc = <<<EOT
|
||||
Hello world
|
||||
EOT;
|
||||
|
||||
// different associative arrays to be passed to $input argument
|
||||
$inputs = array (
|
||||
/*1*/ // arrays with integer keys
|
||||
array(0 => "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
|
131
ext/standard/tests/array/array_unique_variation4.phpt
Normal file
131
ext/standard/tests/array/array_unique_variation4.phpt
Normal file
@ -0,0 +1,131 @@
|
||||
--TEST--
|
||||
Test array_unique() function : usage variations - associative array with different values
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_unique(array $input)
|
||||
* Description: Removes duplicate values from array
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* Testing the functionality of array_unique() by passing different
|
||||
* associative arrays having different values to $input argument.
|
||||
*/
|
||||
|
||||
echo "*** Testing array_unique() : assoc. array with diff. values to \$input argument ***\n";
|
||||
|
||||
// get an unset variable
|
||||
$unset_var = 10;
|
||||
unset ($unset_var);
|
||||
|
||||
// get a resource variable
|
||||
$fp = fopen(__FILE__, "r");
|
||||
|
||||
// get a class
|
||||
class classA
|
||||
{
|
||||
public function __toString() {
|
||||
return "Class A object";
|
||||
}
|
||||
}
|
||||
|
||||
// get a heredoc string
|
||||
$heredoc = <<<EOT
|
||||
Hello world
|
||||
EOT;
|
||||
|
||||
// associative arrays with different values
|
||||
$inputs = array (
|
||||
// arrays with integer values
|
||||
/*1*/ array('0' => 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
|
33
ext/standard/tests/array/array_unique_variation5.phpt
Normal file
33
ext/standard/tests/array/array_unique_variation5.phpt
Normal file
@ -0,0 +1,33 @@
|
||||
--TEST--
|
||||
Test array_unique() function : usage variations - array with duplicate keys
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_unique(array $input)
|
||||
* Description: Removes duplicate values from array
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* Testing the functionality of array_unique() by passing
|
||||
* array having duplicate keys as values.
|
||||
*/
|
||||
|
||||
echo "*** Testing array_unique() : array with duplicate keys for \$input argument ***\n";
|
||||
|
||||
// initialize the array having duplicate keys
|
||||
$input = array( 1 => "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
|
44
ext/standard/tests/array/array_unique_variation6.phpt
Normal file
44
ext/standard/tests/array/array_unique_variation6.phpt
Normal file
@ -0,0 +1,44 @@
|
||||
--TEST--
|
||||
Test array_unique() function : usage variations - array with reference variables
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_unique(array $input)
|
||||
* Description: Removes duplicate values from array
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* Testing the functionality of array_unique() by passing
|
||||
* array having reference variables as values.
|
||||
*/
|
||||
|
||||
echo "*** Testing array_unique() : array with reference variables for \$input argument ***\n";
|
||||
|
||||
$value1 = 10;
|
||||
$value2 = "hello";
|
||||
$value3 = 0;
|
||||
$value4 = &$value2;
|
||||
|
||||
// input array containing elements as reference variables
|
||||
$input = array(
|
||||
0 => 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
|
33
ext/standard/tests/array/array_unique_variation7.phpt
Normal file
33
ext/standard/tests/array/array_unique_variation7.phpt
Normal file
@ -0,0 +1,33 @@
|
||||
--TEST--
|
||||
Test array_unique() function : usage variations - binary safe checking
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_unique(array $input)
|
||||
* Description: Removes duplicate values from array
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* Testing the functionality of array_unique() by passing an array having binary values.
|
||||
*/
|
||||
|
||||
echo "*** Testing array_unique() : array with binary data for \$input argument ***\n";
|
||||
|
||||
// array with binary values
|
||||
$input = array( b"1", b"hello", "world", "str1" => "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
|
44
ext/standard/tests/array/array_unique_variation8.phpt
Normal file
44
ext/standard/tests/array/array_unique_variation8.phpt
Normal file
@ -0,0 +1,44 @@
|
||||
--TEST--
|
||||
Test array_unique() function : usage variations - two dimensional arrays
|
||||
--FILE--
|
||||
<?php
|
||||
/* Prototype : array array_unique(array $input)
|
||||
* Description: Removes duplicate values from array
|
||||
* Source code: ext/standard/array.c
|
||||
*/
|
||||
|
||||
/*
|
||||
* Testing the functionality of array_unique() by passing
|
||||
* two dimensional arrays for $input argument.
|
||||
*/
|
||||
|
||||
echo "*** Testing array_unique() : two dimensional array for \$input argument ***\n";
|
||||
|
||||
// initialize the 2-d array
|
||||
$input = array(
|
||||
array(1, 2, 3, 1),
|
||||
array("hello", "world", "str1" => "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
|
Loading…
Reference in New Issue
Block a user