kraghuba                Sun Dec  9 14:44:19 2007 UTC

  Added files:                 (Branch: PHP_5_2)
    /php-src/ext/standard/tests/array   array_unique_variation1.phpt 
                                        array_unique_variation4.phpt 
                                        array_unique_variation7.phpt 
                                        array_unique_basic.phpt 
                                        array_unique_variation3.phpt 
                                        array_unique_variation6.phpt 
                                        array_unique_error.phpt 
                                        array_unique_variation2.phpt 
                                        array_unique_variation5.phpt 
                                        array_unique_variation8.phpt 
  Log:
  new testcases for array_unique() function
  
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_unique_variation1.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/array_unique_variation1.phpt
+++ php-src/ext/standard/tests/array/array_unique_variation1.phpt
--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
--UEXPECTF--
*** 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

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_unique_variation4.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/array_unique_variation4.phpt
+++ php-src/ext/standard/tests/array/array_unique_variation4.phpt
--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
--UEXPECTF--
*** Testing array_unique() : assoc. array with diff. values to $input argument 
***
-- Iteration 1 --
array(1) {
  [0]=>
  int(0)
}
-- Iteration 2 --
array(2) {
  [u"one"]=>
  int(1)
  [u"two"]=>
  int(2)
}
-- Iteration 3 --
array(1) {
  [u"float1"]=>
  float(2.3333)
}
-- Iteration 4 --
array(3) {
  [u"f1"]=>
  float(1.2)
  [u"f2"]=>
  float(3.33)
  [3]=>
  float(4.8999992284)
}
-- Iteration 5 --
array(3) {
  [111]=>
  unicode(6) "  Hello"
  [u"red"]=>
  unicode(6) "col       or"
  [2]=>
  unicode(7) "world"
}
-- Iteration 6 --
array(3) {
  [111]=>
  unicode(7) "\tHello"
  [u"red"]=>
  unicode(7) "col\tor"
  [2]=>
  unicode(9) "\v\fworld"
}
-- Iteration 7 --
array(2) {
  [1]=>
  unicode(5) "hello"
  [u"heredoc"]=>
  unicode(11) "Hello world"
}
-- Iteration 8 --
array(3) {
  [11]=>
  object(classA)#1 (0) {
  }
  [u"unset"]=>
  NULL
  [u"resource"]=>
  resource(5) of type (stream)
}
Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_unique_variation7.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/array_unique_variation7.phpt
+++ php-src/ext/standard/tests/array/array_unique_variation7.phpt
--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
--UEXPECT--
*** Testing array_unique() : array with binary data for $input argument ***
array(3) {
  [0]=>
  string(1) "1"
  [1]=>
  string(5) "hello"
  [2]=>
  unicode(5) "world"
}
Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_unique_basic.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/array_unique_basic.phpt
+++ php-src/ext/standard/tests/array/array_unique_basic.phpt
--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
--UEXPECTF--
*** Testing array_unique() : basic functionality ***
array(2) {
  [0]=>
  int(1)
  [1]=>
  int(2)
}
array(2) {
  [1]=>
  unicode(3) "one"
  [2]=>
  unicode(3) "two"
}
array(3) {
  [1]=>
  unicode(3) "one"
  [2]=>
  unicode(3) "two"
  [4]=>
  unicode(5) "three"
}
Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_unique_variation3.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/array_unique_variation3.phpt
+++ php-src/ext/standard/tests/array/array_unique_variation3.phpt
--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
--UEXPECTF--
*** 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]=>
  unicode(1) "0"
}
-- Iteration 2 --
array(3) {
  [1]=>
  unicode(1) "1"
  [2]=>
  unicode(1) "2"
  [4]=>
  unicode(1) "4"
}
-- Iteration 3 --
array(1) {
  [2]=>
  unicode(5) "float"
}
-- Iteration 4 --
array(3) {
  [1]=>
  unicode(2) "f1"
  [3]=>
  unicode(2) "f2"
  [3333333]=>
  unicode(2) "f4"
}
-- Iteration 5 --
array(3) {
  [u"\tHello"]=>
  int(111)
  [u"re\td"]=>
  unicode(5) "color"
  [u"\v\fworld"]=>
  float(2.2)
}
-- Iteration 6 --
array(3) {
  [u"   Hello"]=>
  int(111)
  [u"re d"]=>
  unicode(5) "color"
  [u"world"]=>
  float(2.2)
}
-- Iteration 7 --
array(2) {
  [0]=>
  unicode(5) "hello"
  [u"Hello world"]=>
  unicode(6) "string"
}
-- Iteration 8 --
array(2) {
  [u""]=>
  unicode(5) "hello"
  [0]=>
  int(11)
}
Done

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_unique_variation6.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/array_unique_variation6.phpt
+++ php-src/ext/standard/tests/array/array_unique_variation6.phpt
--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
--UEXPECT--
*** Testing array_unique() : array with reference variables for $input argument 
***
array(2) {
  [0]=>
  int(0)
  [1]=>
  &unicode(5) "hello"
}
Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_unique_error.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/array_unique_error.phpt
+++ php-src/ext/standard/tests/array/array_unique_error.phpt
--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
--UEXPECTF--
*** 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

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_unique_variation2.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/array_unique_variation2.phpt
+++ php-src/ext/standard/tests/array/array_unique_variation2.phpt
--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", "[EMAIL PROTECTED]&\*\(\)\{\}"), 
 // with double quoted strings
       array('a\v\f', 'aaaa\r', 'b', 'aaaa\r', '[EMAIL PROTECTED]&\*\(\)\{\}'), 
 // 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) "[EMAIL PROTECTED]&\*\(\)\{\}"
}
-- Iteration 7 --
array(4) {
  [0]=>
  string(5) "a\v\f"
  [1]=>
  string(6) "aaaa\r"
  [2]=>
  string(1) "b"
  [4]=>
  string(28) "[EMAIL PROTECTED]&\*\(\)\{\}"
}
-- 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. withdifferentwhitespaces"
}
-- 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
--UEXPECTF--
*** 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]=>
  unicode(3) "a"
  [1]=>
  unicode(5) "aaaa"
  [2]=>
  unicode(1) "b"
  [4]=>
  unicode(27) "[EMAIL PROTECTED]&\*\(\)\{\}"
}
-- Iteration 7 --
array(4) {
  [0]=>
  unicode(5) "a\v\f"
  [1]=>
  unicode(6) "aaaa\r"
  [2]=>
  unicode(1) "b"
  [4]=>
  unicode(28) "[EMAIL PROTECTED]&\*\(\)\{\}"
}
-- Iteration 8 --
array(3) {
  [u"h1"]=>
  unicode(1) "
"
  [u"h2"]=>
  unicode(88) "hello world
The quick brown fox jumped over;
the lazy dog
This is a double quoted string"
  [u"h3"]=>
  unicode(88) "hello world      
1111             != 2222
heredoc
double quoted string. withdifferentwhitespaces"
}
-- Iteration 9 --
array(2) {
  [1]=>
  unicode(3) "one"
  [2]=>
  unicode(3) "two"
}
-- Iteration 10 --
array(2) {
  [u"one"]=>
  int(1)
  [u"two"]=>
  int(2)
}
-- Iteration 11 --
array(3) {
  [1]=>
  int(10)
  [2]=>
  int(20)
  [4]=>
  int(40)
}
-- Iteration 12 --
array(2) {
  [u"one"]=>
  unicode(3) "ten"
  [u"two"]=>
  unicode(6) "twenty"
}
-- Iteration 13 --
array(3) {
  [u"one"]=>
  int(1)
  [2]=>
  unicode(3) "two"
  [4]=>
  unicode(4) "four"
}
-- Iteration 14 --
array(2) {
  [u""]=>
  unicode(4) "null"
  [u"NULL"]=>
  NULL
}
-- Iteration 15 --
array(4) {
  [1]=>
  unicode(4) "true"
  [0]=>
  unicode(5) "false"
  [u"false"]=>
  bool(false)
  [u"true"]=>
  bool(true)
}
-- Iteration 16 --
array(2) {
  [u""]=>
  unicode(6) "emptys"
  [u"emptyd"]=>
  unicode(0) ""
}
-- Iteration 17 --
array(2) {
  [1]=>
  unicode(0) ""
  [6]=>
  bool(true)
}
-- Iteration 18 --
array(3) {
  [u""]=>
  int(4)
  [0]=>
  int(5)
  [1]=>
  int(6)
}
Done

http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_unique_variation5.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/array_unique_variation5.phpt
+++ php-src/ext/standard/tests/array/array_unique_variation5.phpt
--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
--UEXPECTF--
*** Testing array_unique() : array with duplicate keys for $input argument ***
array(3) {
  [1]=>
  unicode(1) "1"
  [2]=>
  unicode(1) "2"
  [3]=>
  unicode(5) "three"
}
Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_unique_variation8.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/array_unique_variation8.phpt
+++ php-src/ext/standard/tests/array/array_unique_variation8.phpt
--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 ***

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d
array(1) {
  [0]=>
  array(4) {
    [0]=>
    int(1)
    [1]=>
    int(2)
    [2]=>
    int(3)
    [3]=>
    int(1)
  }
}
Done
--UEXPECTF--
*** Testing array_unique() : two dimensional array for $input argument ***

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d

Notice: Array to string conversion in %s on line %d
array(1) {
  [0]=>
  array(4) {
    [0]=>
    int(1)
    [1]=>
    int(2)
    [2]=>
    int(3)
    [3]=>
    int(1)
  }
}
Done

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to