Skip to content

Commit 7752925

Browse files
author
Raghubansh Kumar
committed
new testcases for array_unique() function
1 parent 6c3a0de commit 7752925

10 files changed

+1451
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
--TEST--
2+
Test array_unique() function : basic functionality
3+
--FILE--
4+
<?php
5+
/* Prototype : array array_unique(array $input)
6+
* Description: Removes duplicate values from array
7+
* Source code: ext/standard/array.c
8+
*/
9+
10+
echo "*** Testing array_unique() : basic functionality ***\n";
11+
12+
// array with default keys
13+
$input = array(1, 2, "1", '2');
14+
var_dump( array_unique($input) );
15+
16+
// associative array
17+
$input = array("1" => "one", 1 => "one", 2 => "two", '2' => "two");
18+
var_dump( array_unique($input) );
19+
20+
// mixed array
21+
$input = array("1" => "one", "two", "one", 2 => "two", "three");
22+
var_dump( array_unique($input) );
23+
24+
echo "Done";
25+
?>
26+
--EXPECTF--
27+
*** Testing array_unique() : basic functionality ***
28+
array(2) {
29+
[0]=>
30+
int(1)
31+
[1]=>
32+
int(2)
33+
}
34+
array(2) {
35+
[1]=>
36+
string(3) "one"
37+
[2]=>
38+
string(3) "two"
39+
}
40+
array(3) {
41+
[1]=>
42+
string(3) "one"
43+
[2]=>
44+
string(3) "two"
45+
[4]=>
46+
string(5) "three"
47+
}
48+
Done
49+
--UEXPECTF--
50+
*** Testing array_unique() : basic functionality ***
51+
array(2) {
52+
[0]=>
53+
int(1)
54+
[1]=>
55+
int(2)
56+
}
57+
array(2) {
58+
[1]=>
59+
unicode(3) "one"
60+
[2]=>
61+
unicode(3) "two"
62+
}
63+
array(3) {
64+
[1]=>
65+
unicode(3) "one"
66+
[2]=>
67+
unicode(3) "two"
68+
[4]=>
69+
unicode(5) "three"
70+
}
71+
Done
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
--TEST--
2+
Test array_unique() function : error conditions
3+
--FILE--
4+
<?php
5+
/* Prototype : array array_unique(array $input)
6+
* Description: Removes duplicate values from array
7+
* Source code: ext/standard/array.c
8+
*/
9+
10+
echo "*** Testing array_unique() : error conditions ***\n";
11+
12+
// Zero arguments
13+
echo "\n-- Testing array_unique() function with zero arguments --\n";
14+
var_dump( array_unique() );
15+
16+
//Test array_unique with one more than the expected number of arguments
17+
echo "\n-- Testing array_unique() function with more than expected no. of arguments --\n";
18+
$input = array(1, 2);
19+
$extra_arg = 10;
20+
var_dump( array_unique($input, $extra_arg) );
21+
22+
echo "Done";
23+
?>
24+
--EXPECTF--
25+
*** Testing array_unique() : error conditions ***
26+
27+
-- Testing array_unique() function with zero arguments --
28+
29+
Warning: array_unique() expects exactly 1 parameter, 0 given in %s on line %d
30+
NULL
31+
32+
-- Testing array_unique() function with more than expected no. of arguments --
33+
34+
Warning: array_unique() expects exactly 1 parameter, 2 given in %s on line %d
35+
NULL
36+
Done
37+
--UEXPECTF--
38+
*** Testing array_unique() : error conditions ***
39+
40+
-- Testing array_unique() function with zero arguments --
41+
42+
Warning: array_unique() expects exactly 1 parameter, 0 given in %s on line %d
43+
NULL
44+
45+
-- Testing array_unique() function with more than expected no. of arguments --
46+
47+
Warning: array_unique() expects exactly 1 parameter, 2 given in %s on line %d
48+
NULL
49+
Done

0 commit comments

Comments
 (0)