New testcases for array_flip() function

This commit is contained in:
Raghubansh Kumar 2007-10-15 06:33:32 +00:00
parent f36aae329a
commit ee89cea00b
7 changed files with 671 additions and 0 deletions

View file

@ -0,0 +1,110 @@
--TEST--
Test array_flip() function : basic functionality
--FILE--
<?php
/* Prototype : array array_flip(array $input)
* Description: Return array with key <-> value flipped
* Source code: ext/standard/array.c
*/
echo "*** Testing array_flip() : basic functionality ***\n";
// array with default keys - numeric values
$input = array(1, 2);
var_dump( array_flip($input) );
// array with default keys - string values
$input = array('value1', "value2");
var_dump( array_flip($input) );
// associative arrays - key as string
$input = array('key1' => 1, "key2" => 2);
var_dump( array_flip($input) );
// associative arrays - key as numeric
$input = array(1 => 'one', 2 => "two");
var_dump( array_flip($input) );
// combination of associative and non-associative array
$input = array(1 => 'one','two', 3 => 'three', 4, "five" => 5);
var_dump( array_flip($input) );
echo "Done"
?>
--EXPECTF--
*** Testing array_flip() : basic functionality ***
array(2) {
[1]=>
int(0)
[2]=>
int(1)
}
array(2) {
["value1"]=>
int(0)
["value2"]=>
int(1)
}
array(2) {
[1]=>
string(4) "key1"
[2]=>
string(4) "key2"
}
array(2) {
["one"]=>
int(1)
["two"]=>
int(2)
}
array(5) {
["one"]=>
int(1)
["two"]=>
int(2)
["three"]=>
int(3)
[4]=>
int(4)
[5]=>
string(4) "five"
}
Done
--UEXPECTF--
*** Testing array_flip() : basic functionality ***
array(2) {
[1]=>
int(0)
[2]=>
int(1)
}
array(2) {
[u"value1"]=>
int(0)
[u"value2"]=>
int(1)
}
array(2) {
[1]=>
unicode(4) "key1"
[2]=>
unicode(4) "key2"
}
array(2) {
[u"one"]=>
int(1)
[u"two"]=>
int(2)
}
array(5) {
[u"one"]=>
int(1)
[u"two"]=>
int(2)
[u"three"]=>
int(3)
[4]=>
int(4)
[5]=>
unicode(4) "five"
}
Done

View file

@ -0,0 +1,45 @@
--TEST--
Test array_flip() function : error conditions
--FILE--
<?php
/* Prototype : array array_flip(array $input)
* Description: Return array with key <-> value flipped
* Source code: ext/standard/array.c
*/
echo "*** Testing array_flip() : error conditions ***\n";
// Zero arguments
echo "-- Testing array_flip() function with Zero arguments --\n";
var_dump( array_flip() );
//one more than the expected number of arguments
echo "-- Testing array_flip() function with more than expected no. of arguments --\n";
$input = array(1 => 'one', 2 => 'two');
$extra_arg = 10;
var_dump( array_flip($input, $extra_arg) );
echo "Done"
?>
--EXPECTF--
*** Testing array_flip() : error conditions ***
-- Testing array_flip() function with Zero arguments --
Warning: array_flip() expects exactly 1 parameter, 0 given in %s on line %d
NULL
-- Testing array_flip() function with more than expected no. of arguments --
Warning: array_flip() expects exactly 1 parameter, 2 given in %s on line %d
NULL
Done
--UEXPECTF--
*** Testing array_flip() : error conditions ***
-- Testing array_flip() function with Zero arguments --
Warning: array_flip() expects exactly 1 parameter, 0 given in %s on line %d
NULL
-- Testing array_flip() function with more than expected no. of arguments --
Warning: array_flip() expects exactly 1 parameter, 2 given in %s on line %d
NULL
Done

View file

@ -0,0 +1,274 @@
--TEST--
Test array_flip() function : usage variations - unexpected values for 'input' argument
--FILE--
<?php
/* Prototype : array array_flip(array $input)
* Description: Return array with key <-> value flipped
* Source code: ext/standard/array.c
*/
echo "*** Testing array_flip() : usage variations - unexpected values for 'input' ***\n";
//get an unset variable
$unset_var = 10;
unset ($unset_var);
//class definition for object variable
class MyClass
{
public function __toString()
{
return 'object';
}
}
//resource variable
$fp = fopen(__FILE__,'r');
//array of values for 'input' argument
$values = array(
// int data
/*1*/ 0,
1,
12345,
-2345,
// float data
/*5*/ 10.5,
-10.5,
10.5e10,
10.6E-10,
.5,
// null data
/*10*/ NULL,
null,
// boolean data
/*12*/ true,
false,
TRUE,
/*15*/ FALSE,
// empty data
"",
'',
// string data
"string",
'string',
// object data
/*20*/ new MyClass(),
// undefined data
@$undefined_var,
// unset data
@$unset_var,
//resource data
/*23*/ $fp
);
// loop through each element of $values for 'input' argument
for($count = 0; $count < count($values); $count++) {
echo "-- Iteration ".($count + 1). " --\n";
var_dump( array_flip($values[$count]) );
};
//closing resource
fclose($fp);
echo "Done"
?>
--EXPECTF--
*** Testing array_flip() : usage variations - unexpected values for 'input' ***
-- Iteration 1 --
Warning: array_flip() expects parameter 1 to be array, integer given in %s on line %d
NULL
-- Iteration 2 --
Warning: array_flip() expects parameter 1 to be array, integer given in %s on line %d
NULL
-- Iteration 3 --
Warning: array_flip() expects parameter 1 to be array, integer given in %s on line %d
NULL
-- Iteration 4 --
Warning: array_flip() expects parameter 1 to be array, integer given in %s on line %d
NULL
-- Iteration 5 --
Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d
NULL
-- Iteration 6 --
Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d
NULL
-- Iteration 7 --
Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d
NULL
-- Iteration 8 --
Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d
NULL
-- Iteration 9 --
Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d
NULL
-- Iteration 10 --
Warning: array_flip() expects parameter 1 to be array, null given in %s on line %d
NULL
-- Iteration 11 --
Warning: array_flip() expects parameter 1 to be array, null given in %s on line %d
NULL
-- Iteration 12 --
Warning: array_flip() expects parameter 1 to be array, boolean given in %s on line %d
NULL
-- Iteration 13 --
Warning: array_flip() expects parameter 1 to be array, boolean given in %s on line %d
NULL
-- Iteration 14 --
Warning: array_flip() expects parameter 1 to be array, boolean given in %s on line %d
NULL
-- Iteration 15 --
Warning: array_flip() expects parameter 1 to be array, boolean given in %s on line %d
NULL
-- Iteration 16 --
Warning: array_flip() expects parameter 1 to be array, string given in %s on line %d
NULL
-- Iteration 17 --
Warning: array_flip() expects parameter 1 to be array, string given in %s on line %d
NULL
-- Iteration 18 --
Warning: array_flip() expects parameter 1 to be array, string given in %s on line %d
NULL
-- Iteration 19 --
Warning: array_flip() expects parameter 1 to be array, string given in %s on line %d
NULL
-- Iteration 20 --
Warning: array_flip() expects parameter 1 to be array, object given in %s on line %d
NULL
-- Iteration 21 --
Warning: array_flip() expects parameter 1 to be array, null given in %s on line %d
NULL
-- Iteration 22 --
Warning: array_flip() expects parameter 1 to be array, null given in %s on line %d
NULL
-- Iteration 23 --
Warning: array_flip() expects parameter 1 to be array, resource given in %s on line %d
NULL
Done
--UEXPECTF--
*** Testing array_flip() : usage variations - unexpected values for 'input' ***
-- Iteration 1 --
Warning: array_flip() expects parameter 1 to be array, integer given in %s on line %d
NULL
-- Iteration 2 --
Warning: array_flip() expects parameter 1 to be array, integer given in %s on line %d
NULL
-- Iteration 3 --
Warning: array_flip() expects parameter 1 to be array, integer given in %s on line %d
NULL
-- Iteration 4 --
Warning: array_flip() expects parameter 1 to be array, integer given in %s on line %d
NULL
-- Iteration 5 --
Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d
NULL
-- Iteration 6 --
Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d
NULL
-- Iteration 7 --
Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d
NULL
-- Iteration 8 --
Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d
NULL
-- Iteration 9 --
Warning: array_flip() expects parameter 1 to be array, double given in %s on line %d
NULL
-- Iteration 10 --
Warning: array_flip() expects parameter 1 to be array, null given in %s on line %d
NULL
-- Iteration 11 --
Warning: array_flip() expects parameter 1 to be array, null given in %s on line %d
NULL
-- Iteration 12 --
Warning: array_flip() expects parameter 1 to be array, boolean given in %s on line %d
NULL
-- Iteration 13 --
Warning: array_flip() expects parameter 1 to be array, boolean given in %s on line %d
NULL
-- Iteration 14 --
Warning: array_flip() expects parameter 1 to be array, boolean given in %s on line %d
NULL
-- Iteration 15 --
Warning: array_flip() expects parameter 1 to be array, boolean given in %s on line %d
NULL
-- Iteration 16 --
Warning: array_flip() expects parameter 1 to be array, Unicode string given in %s on line %d
NULL
-- Iteration 17 --
Warning: array_flip() expects parameter 1 to be array, Unicode string given in %s on line %d
NULL
-- Iteration 18 --
Warning: array_flip() expects parameter 1 to be array, Unicode string given in %s on line %d
NULL
-- Iteration 19 --
Warning: array_flip() expects parameter 1 to be array, Unicode string given in %s on line %d
NULL
-- Iteration 20 --
Warning: array_flip() expects parameter 1 to be array, object given in %s on line %d
NULL
-- Iteration 21 --
Warning: array_flip() expects parameter 1 to be array, null given in %s on line %d
NULL
-- Iteration 22 --
Warning: array_flip() expects parameter 1 to be array, null given in %s on line %d
NULL
-- Iteration 23 --
Warning: array_flip() expects parameter 1 to be array, resource given in %s on line %d
NULL
Done

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,119 @@
--TEST--
Test array_flip() function : usage variations - 'input' argument with different invalid values for keys
--FILE--
<?php
/* Prototype : array array_flip(array $input)
* Description: Return array with key <-> value flipped
* Source code: ext/standard/array.c
*/
/*
* Trying different invalid values for 'input' array argument
*/
echo "*** Testing array_flip() : different invalid values in 'input' array argument ***\n";
// class definition for object data
class MyClass
{
public function __toString()
{
return 'object';
}
}
$obj = new MyClass();
// resource data
$fp = fopen(__FILE__, 'r');
$input = array(
// float values
'float_value1' => 1.2,
'float_value2' => 0.5,
'flaot_value3' => 3.4E3,
'flaot_value4' => 5.6E-6,
// bool values
'bool_value1' => true,
'bool_value2' => false,
'bool_value3' => TRUE,
'bool_value4' => FALSE,
// null values
'null_value1' => null,
// array value
'array_value' => array(1),
// object value
'obj_value' => $obj,
// resource value
'resource_value' => $fp,
);
var_dump( array_flip($input) );
// closing resource
fclose($fp);
echo "Done"
?>
--EXPECTF--
*** Testing array_flip() : different invalid values in 'input' array argument ***
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
array(0) {
}
Done
--UEXPECTF--
*** Testing array_flip() : different invalid values in 'input' array argument ***
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
Warning: array_flip(): Can only flip STRING and INTEGER values! in %s on line %d
array(0) {
}
Done

View file

@ -0,0 +1,123 @@
--TEST--
Test array_flip() function : usage variations - 'input' argument with repeatitive keys and values
--FILE--
<?php
/* Prototype : array array_flip(array $input)
* Description: Return array with key <-> value flipped
* Source code: ext/standard/array.c
*/
/*
* Using different types of repeatitive keys as well as values for 'input' array
*/
echo "*** Testing array_flip() : 'input' array with repeatitive keys/values ***\n";
// array with numeric key repeatition
$input = array(1 => 'value', 2 => 'VALUE', 1 => "VaLuE", 3.4 => 4, 3.4 => 5);
var_dump( array_flip($input) );
// array with string key repeatition
$input = array("key" => 1, "two" => 'TWO', 'three' => 3, 'key' => "FOUR");
var_dump( array_flip($input) );
// array with bool key repeatition
$input = array(true => 1, false => 0, TRUE => -1);
var_dump( array_flip($input) );
// array with null key repeatition
$input = array(null => "Hello", NULL => 0);
var_dump( array_flip($input) );
// array with numeric value repeatition
$input = array('one' => 1, 'two' => 2, 3 => 1, "index" => 1);
var_dump( array_flip($input) );
//array with string value repeatition
$input = array('key1' => "value1", "key2" => '2', 'key3' => 'value1');
var_dump( array_flip($input) );
echo "Done"
?>
--EXPECTF--
*** Testing array_flip() : 'input' array with repeatitive keys/values ***
array(3) {
["VaLuE"]=>
int(1)
["VALUE"]=>
int(2)
[5]=>
int(3)
}
array(3) {
["FOUR"]=>
string(3) "key"
["TWO"]=>
string(3) "two"
[3]=>
string(5) "three"
}
array(2) {
[-1]=>
int(1)
[0]=>
int(0)
}
array(1) {
[0]=>
string(0) ""
}
array(2) {
[1]=>
string(5) "index"
[2]=>
string(3) "two"
}
array(2) {
["value1"]=>
string(4) "key3"
[2]=>
string(4) "key2"
}
Done
--UEXPECTF--
*** Testing array_flip() : 'input' array with repeatitive keys/values ***
array(3) {
[u"VaLuE"]=>
int(1)
[u"VALUE"]=>
int(2)
[5]=>
int(3)
}
array(3) {
[u"FOUR"]=>
unicode(3) "key"
[u"TWO"]=>
unicode(3) "two"
[3]=>
unicode(5) "three"
}
array(2) {
[-1]=>
int(1)
[0]=>
int(0)
}
array(1) {
[0]=>
unicode(0) ""
}
array(2) {
[1]=>
unicode(5) "index"
[2]=>
unicode(3) "two"
}
array(2) {
[u"value1"]=>
unicode(4) "key3"
[2]=>
unicode(4) "key2"
}
Done