Skip to content

Commit 00926c8

Browse files
author
Raghubansh Kumar
committed
New testcases for array_pad() function
1 parent e54f020 commit 00926c8

9 files changed

+4521
-0
lines changed
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
--TEST--
2+
Test array_pad() function : basic functionality
3+
--FILE--
4+
<?php
5+
/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value)
6+
* Description: Returns a copy of input array padded with pad_value to size pad_size
7+
* Source code: ext/standard/array.c
8+
*/
9+
10+
echo "*** Testing array_pad() : basic functionality ***\n";
11+
12+
// Initialise $input and $pad_value arguments
13+
$input = array(1, 2, 3);
14+
$pad_value = -3;
15+
16+
// positive $pad_size
17+
echo "-- Positive pad_size --\n";
18+
var_dump( array_pad($input, 8, $pad_value) );
19+
20+
// negative $pad_size
21+
echo "-- Negative pad_size --\n";
22+
var_dump( array_pad($input, -8, $pad_value) );
23+
24+
// $pad_size less than array size, no padding expected
25+
echo "-- Pad_size lesser than array_size --\n";
26+
var_dump( array_pad($input, 2, $pad_value) );
27+
28+
// $pad_size equal to array size, no padding expected
29+
echo "-- Pad_size equal to array_size --\n";
30+
var_dump( array_pad($input, 3, $pad_value) );
31+
32+
echo "Done";
33+
?>
34+
--EXPECTF--
35+
*** Testing array_pad() : basic functionality ***
36+
-- Positive pad_size --
37+
array(8) {
38+
[0]=>
39+
int(1)
40+
[1]=>
41+
int(2)
42+
[2]=>
43+
int(3)
44+
[3]=>
45+
int(-3)
46+
[4]=>
47+
int(-3)
48+
[5]=>
49+
int(-3)
50+
[6]=>
51+
int(-3)
52+
[7]=>
53+
int(-3)
54+
}
55+
-- Negative pad_size --
56+
array(8) {
57+
[0]=>
58+
int(-3)
59+
[1]=>
60+
int(-3)
61+
[2]=>
62+
int(-3)
63+
[3]=>
64+
int(-3)
65+
[4]=>
66+
int(-3)
67+
[5]=>
68+
int(1)
69+
[6]=>
70+
int(2)
71+
[7]=>
72+
int(3)
73+
}
74+
-- Pad_size lesser than array_size --
75+
array(3) {
76+
[0]=>
77+
int(1)
78+
[1]=>
79+
int(2)
80+
[2]=>
81+
int(3)
82+
}
83+
-- Pad_size equal to array_size --
84+
array(3) {
85+
[0]=>
86+
int(1)
87+
[1]=>
88+
int(2)
89+
[2]=>
90+
int(3)
91+
}
92+
Done
93+
--UEXPECTF--
94+
*** Testing array_pad() : basic functionality ***
95+
-- Positive pad_size --
96+
array(8) {
97+
[0]=>
98+
int(1)
99+
[1]=>
100+
int(2)
101+
[2]=>
102+
int(3)
103+
[3]=>
104+
int(-3)
105+
[4]=>
106+
int(-3)
107+
[5]=>
108+
int(-3)
109+
[6]=>
110+
int(-3)
111+
[7]=>
112+
int(-3)
113+
}
114+
-- Negative pad_size --
115+
array(8) {
116+
[0]=>
117+
int(-3)
118+
[1]=>
119+
int(-3)
120+
[2]=>
121+
int(-3)
122+
[3]=>
123+
int(-3)
124+
[4]=>
125+
int(-3)
126+
[5]=>
127+
int(1)
128+
[6]=>
129+
int(2)
130+
[7]=>
131+
int(3)
132+
}
133+
-- Pad_size lesser than array_size --
134+
array(3) {
135+
[0]=>
136+
int(1)
137+
[1]=>
138+
int(2)
139+
[2]=>
140+
int(3)
141+
}
142+
-- Pad_size equal to array_size --
143+
array(3) {
144+
[0]=>
145+
int(1)
146+
[1]=>
147+
int(2)
148+
[2]=>
149+
int(3)
150+
}
151+
Done
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
--TEST--
2+
Test array_pad() function : error conditions
3+
--FILE--
4+
<?php
5+
/* Prototype : array array_pad(array $input, int $pad_size, mixed $pad_value)
6+
* Description: Returns a copy of input array padded with pad_value to size pad_size
7+
* Source code: ext/standard/array.c
8+
*/
9+
10+
echo "*** Testing array_pad() : error conditions ***\n";
11+
12+
// Zero arguments
13+
echo "\n-- Testing array_pad() function with Zero arguments --\n";
14+
var_dump( array_pad() );
15+
16+
//Test array_pad with one more than the expected number of arguments
17+
echo "\n-- Testing array_pad() function with more than expected no. of arguments --\n";
18+
$input = array(1, 2);
19+
$pad_size = 10;
20+
$pad_value = 1;
21+
$extra_arg = 10;
22+
var_dump( array_pad($input, $pad_size, $pad_value, $extra_arg) );
23+
24+
// Testing array_pad with less than the expected number of arguments
25+
echo "\n-- Testing array_pad() function with less than expected no. of arguments --\n";
26+
$input = array(1, 2);
27+
$pad_size = 10;
28+
var_dump( array_pad($input, $pad_size) );
29+
var_dump( array_pad($input) );
30+
31+
echo "Done";
32+
?>
33+
--EXPECTF--
34+
*** Testing array_pad() : error conditions ***
35+
36+
-- Testing array_pad() function with Zero arguments --
37+
38+
Warning: array_pad() expects exactly 3 parameters, 0 given in %s on line %d
39+
NULL
40+
41+
-- Testing array_pad() function with more than expected no. of arguments --
42+
43+
Warning: array_pad() expects exactly 3 parameters, 4 given in %s on line %d
44+
NULL
45+
46+
-- Testing array_pad() function with less than expected no. of arguments --
47+
48+
Warning: array_pad() expects exactly 3 parameters, 2 given in %s on line %d
49+
NULL
50+
51+
Warning: array_pad() expects exactly 3 parameters, 1 given in %s on line %d
52+
NULL
53+
Done
54+
--UEXPECTF--
55+
*** Testing array_pad() : error conditions ***
56+
57+
-- Testing array_pad() function with Zero arguments --
58+
59+
Warning: array_pad() expects exactly 3 parameters, 0 given in %s on line %d
60+
NULL
61+
62+
-- Testing array_pad() function with more than expected no. of arguments --
63+
64+
Warning: array_pad() expects exactly 3 parameters, 4 given in %s on line %d
65+
NULL
66+
67+
-- Testing array_pad() function with less than expected no. of arguments --
68+
69+
Warning: array_pad() expects exactly 3 parameters, 2 given in %s on line %d
70+
NULL
71+
72+
Warning: array_pad() expects exactly 3 parameters, 1 given in %s on line %d
73+
NULL
74+
Done

0 commit comments

Comments
 (0)