Skip to content

Commit f5f44bb

Browse files
authored
Refactor tests for pow() function (#13005)
1 parent 2ab1c3d commit f5f44bb

File tree

3 files changed

+133
-380
lines changed

3 files changed

+133
-380
lines changed

ext/standard/tests/math/pow_variation1.phpt

Lines changed: 45 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -8,164 +8,83 @@ if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
88
?>
99
--FILE--
1010
<?php
11-
echo "*** Testing pow() : usage variations ***\n";
1211

13-
//get an unset variable
14-
$unset_var = 10;
15-
unset ($unset_var);
16-
17-
// heredoc string
18-
$heredoc = <<<EOT
19-
abc
20-
xyz
21-
EOT;
22-
23-
// get a class
2412
class classA
2513
{
2614
}
2715

28-
// get a resource variable
16+
//resource variable
2917
$fp = fopen(__FILE__, "r");
3018

31-
$inputs = array(
32-
// int data
33-
/*1*/ 0,
34-
1,
35-
12345,
36-
-2345,
37-
PHP_INT_MAX,
38-
39-
// float data
40-
/*6*/ 10.5,
41-
-10.5,
42-
12.3456789000e10,
43-
12.3456789000E-10,
44-
.5,
45-
46-
// null data
47-
/*11*/ NULL,
48-
null,
49-
50-
// boolean data
51-
/*13*/ true,
52-
false,
53-
TRUE,
54-
FALSE,
55-
56-
// empty data
57-
/*17*/ "",
58-
'',
59-
array(),
60-
61-
// string data
62-
/*20*/ "abcxyz",
63-
'abcxyz',
64-
$heredoc,
65-
66-
// object data
67-
/*23*/ new classA(),
68-
69-
// undefined data
70-
/*24*/ @$undefined_var,
71-
72-
// unset data
73-
/*25*/ @$unset_var,
74-
75-
// resource variable
76-
/*26*/ $fp
77-
);
19+
$inputs = [
20+
// int data
21+
0,
22+
1,
23+
12345,
24+
-2345,
25+
PHP_INT_MAX,
26+
27+
// float data
28+
10.5,
29+
-10.5,
30+
12.3456789e10,
31+
12.3456789e-10,
32+
0.5,
33+
34+
// null data
35+
null,
36+
37+
// boolean data
38+
true,
39+
false,
40+
41+
// empty data
42+
"",
43+
[],
44+
45+
// string data
46+
"abcxyz",
47+
"5.5",
48+
"2",
49+
"6.3e-2",
50+
51+
// object data
52+
new classA(),
53+
54+
// resource variable
55+
$fp,
56+
];
7857

7958
// loop through each element of $inputs to check the behaviour of pow()
80-
$iterator = 1;
81-
foreach($inputs as $input) {
82-
echo "\n-- Iteration $iterator --\n";
59+
foreach ($inputs as $input) {
8360
try {
8461
var_dump(pow($input, 3));
8562
} catch (Error $e) {
8663
echo $e->getMessage(), "\n";
8764
}
88-
$iterator++;
89-
};
65+
}
9066
fclose($fp);
67+
9168
?>
9269
--EXPECTF--
93-
*** Testing pow() : usage variations ***
94-
95-
-- Iteration 1 --
9670
int(0)
97-
98-
-- Iteration 2 --
9971
int(1)
100-
101-
-- Iteration 3 --
10272
float(1881365963625)
103-
104-
-- Iteration 4 --
10573
float(-12895213625)
106-
107-
-- Iteration 5 --
10874
float(9.903520300448E+27)
109-
110-
-- Iteration 6 --
11175
float(1157.625)
112-
113-
-- Iteration 7 --
11476
float(-1157.625)
115-
116-
-- Iteration 8 --
11777
float(1.881676371789%dE+33)
118-
119-
-- Iteration 9 --
12078
float(1.881676371789%dE-27)
121-
122-
-- Iteration 10 --
12379
float(0.125)
124-
125-
-- Iteration 11 --
12680
int(0)
127-
128-
-- Iteration 12 --
129-
int(0)
130-
131-
-- Iteration 13 --
132-
int(1)
133-
134-
-- Iteration 14 --
135-
int(0)
136-
137-
-- Iteration 15 --
13881
int(1)
139-
140-
-- Iteration 16 --
14182
int(0)
142-
143-
-- Iteration 17 --
14483
Unsupported operand types: string ** int
145-
146-
-- Iteration 18 --
147-
Unsupported operand types: string ** int
148-
149-
-- Iteration 19 --
15084
Unsupported operand types: array ** int
151-
152-
-- Iteration 20 --
153-
Unsupported operand types: string ** int
154-
155-
-- Iteration 21 --
15685
Unsupported operand types: string ** int
157-
158-
-- Iteration 22 --
159-
Unsupported operand types: string ** int
160-
161-
-- Iteration 23 --
86+
float(166.375)
87+
int(8)
88+
float(0.000250047)
16289
Unsupported operand types: classA ** int
163-
164-
-- Iteration 24 --
165-
int(0)
166-
167-
-- Iteration 25 --
168-
int(0)
169-
170-
-- Iteration 26 --
17190
Unsupported operand types: resource ** int

0 commit comments

Comments
 (0)