1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Refactor tests for pow() function (#13005)

This commit is contained in:
Jorg Adam Sowa
2023-12-27 00:43:52 +01:00
committed by GitHub
parent 2ab1c3d5ad
commit f5f44bb22d
3 changed files with 112 additions and 359 deletions

View File

@@ -8,164 +8,83 @@ if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
?>
--FILE--
<?php
echo "*** Testing pow() : usage variations ***\n";
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// heredoc string
$heredoc = <<<EOT
abc
xyz
EOT;
// get a class
class classA
{
}
// get a resource variable
//resource variable
$fp = fopen(__FILE__, "r");
$inputs = array(
// int data
/*1*/ 0,
1,
12345,
-2345,
PHP_INT_MAX,
$inputs = [
// int data
0,
1,
12345,
-2345,
PHP_INT_MAX,
// float data
/*6*/ 10.5,
-10.5,
12.3456789000e10,
12.3456789000E-10,
.5,
// float data
10.5,
-10.5,
12.3456789e10,
12.3456789e-10,
0.5,
// null data
/*11*/ NULL,
null,
// null data
null,
// boolean data
/*13*/ true,
false,
TRUE,
FALSE,
// boolean data
true,
false,
// empty data
/*17*/ "",
'',
array(),
// empty data
"",
[],
// string data
/*20*/ "abcxyz",
'abcxyz',
$heredoc,
// string data
"abcxyz",
"5.5",
"2",
"6.3e-2",
// object data
/*23*/ new classA(),
// object data
new classA(),
// undefined data
/*24*/ @$undefined_var,
// unset data
/*25*/ @$unset_var,
// resource variable
/*26*/ $fp
);
// resource variable
$fp,
];
// loop through each element of $inputs to check the behaviour of pow()
$iterator = 1;
foreach($inputs as $input) {
echo "\n-- Iteration $iterator --\n";
foreach ($inputs as $input) {
try {
var_dump(pow($input, 3));
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
$iterator++;
};
}
fclose($fp);
?>
--EXPECTF--
*** Testing pow() : usage variations ***
-- Iteration 1 --
int(0)
-- Iteration 2 --
int(1)
-- Iteration 3 --
float(1881365963625)
-- Iteration 4 --
float(-12895213625)
-- Iteration 5 --
float(9.903520300448E+27)
-- Iteration 6 --
float(1157.625)
-- Iteration 7 --
float(-1157.625)
-- Iteration 8 --
float(1.881676371789%dE+33)
-- Iteration 9 --
float(1.881676371789%dE-27)
-- Iteration 10 --
float(0.125)
-- Iteration 11 --
int(0)
-- Iteration 12 --
int(0)
-- Iteration 13 --
int(1)
-- Iteration 14 --
int(0)
-- Iteration 15 --
int(1)
-- Iteration 16 --
int(0)
-- Iteration 17 --
Unsupported operand types: string ** int
-- Iteration 18 --
Unsupported operand types: string ** int
-- Iteration 19 --
Unsupported operand types: array ** int
-- Iteration 20 --
Unsupported operand types: string ** int
-- Iteration 21 --
Unsupported operand types: string ** int
-- Iteration 22 --
Unsupported operand types: string ** int
-- Iteration 23 --
float(166.375)
int(8)
float(0.000250047)
Unsupported operand types: classA ** int
-- Iteration 24 --
int(0)
-- Iteration 25 --
int(0)
-- Iteration 26 --
Unsupported operand types: resource ** int

View File

@@ -8,164 +8,81 @@ if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
?>
--FILE--
<?php
echo "*** Testing pow() : usage variations ***\n";
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// heredoc string
$heredoc = <<<EOT
abc
xyz
EOT;
// get a class
class classA
{
}
// get a resource variable
// resource variable
$fp = fopen(__FILE__, "r");
$inputs = array(
// int data
/*1*/ 0,
1,
12345,
-2345,
PHP_INT_MAX,
$inputs = [
// int data
0,
1,
12345,
-2345,
PHP_INT_MAX,
// float data
/*6*/ 10.5,
-10.5,
12.3456789000e10,
12.3456789000E-10,
.5,
// float data
10.5,
-10.5,
12.3456789e10,
12.3456789e-10,
0.5,
// null data
/*11*/ NULL,
null,
// null data
null,
// boolean data
/*13*/ true,
false,
TRUE,
FALSE,
// boolean data
true,
false,
// empty data
/*17*/ "",
'',
array(),
// empty data
"",
[],
// string data
/*20*/ "abcxyz",
'abcxyz',
$heredoc,
// string data
"abcxyz",
"10.5",
"2",
"6.3e-2",
// object data
/*23*/ new classA(),
// object data
new classA(),
// undefined data
/*24*/ @$undefined_var,
// unset data
/*25*/ @$unset_var,
// resource variable
/*26*/ $fp
);
// resource variable
$fp,
];
// loop through each element of $inputs to check the behaviour of pow()
$iterator = 1;
foreach($inputs as $input) {
echo "\n-- Iteration $iterator --\n";
foreach ($inputs as $input) {
try {
var_dump(pow($input, 3));
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
$iterator++;
};
}
fclose($fp);
?>
--EXPECT--
*** Testing pow() : usage variations ***
-- Iteration 1 --
int(0)
-- Iteration 2 --
int(1)
-- Iteration 3 --
int(1881365963625)
-- Iteration 4 --
int(-12895213625)
-- Iteration 5 --
float(7.846377169233351E+56)
-- Iteration 6 --
float(1157.625)
-- Iteration 7 --
float(-1157.625)
-- Iteration 8 --
float(1.8816763717891549E+33)
-- Iteration 9 --
float(1.8816763717891545E-27)
-- Iteration 10 --
float(0.125)
-- Iteration 11 --
int(0)
-- Iteration 12 --
int(0)
-- Iteration 13 --
int(1)
-- Iteration 14 --
int(0)
-- Iteration 15 --
int(1)
-- Iteration 16 --
int(0)
-- Iteration 17 --
Unsupported operand types: string ** int
-- Iteration 18 --
Unsupported operand types: string ** int
-- Iteration 19 --
Unsupported operand types: array ** int
-- Iteration 20 --
Unsupported operand types: string ** int
-- Iteration 21 --
Unsupported operand types: string ** int
-- Iteration 22 --
Unsupported operand types: string ** int
-- Iteration 23 --
float(1157.625)
int(8)
float(0.000250047)
Unsupported operand types: classA ** int
-- Iteration 24 --
int(0)
-- Iteration 25 --
int(0)
-- Iteration 26 --
Unsupported operand types: resource ** int

View File

@@ -4,164 +4,81 @@ Test pow() function : usage variations - different data types as $exp argument
serialize_precision = 14
--FILE--
<?php
echo "*** Testing pow() : usage variations ***\n";
//get an unset variable
$unset_var = 10;
unset ($unset_var);
// heredoc string
$heredoc = <<<EOT
abc
xyz
EOT;
// get a class
class classA
{
}
// get a resource variable
// resource variable
$fp = fopen(__FILE__, "r");
$inputs = array(
// int data
/*1*/ 0,
1,
12345,
-2345,
2147483647,
$inputs = [
// int data
0,
1,
12345,
-2345,
PHP_INT_MAX,
// float data
/*6*/ 2.5,
-2.5,
12.3456789000e10,
12.3456789000E-10,
.5,
// float data
2.5,
-2.5,
12.3456789e10,
12.3456789e-10,
0.5,
// null data
/*11*/ NULL,
null,
// null data
null,
// boolean data
/*13*/ true,
false,
TRUE,
FALSE,
// boolean data
true,
false,
// empty data
/*17*/ "",
'',
array(),
// empty data
"",
[],
// string data
/*20*/ "abcxyz",
'abcxyz',
$heredoc,
// string data
"abcxyz",
"5.5",
"2",
"6.3e-2",
// object data
/*23*/ new classA(),
// object data
new classA(),
// undefined data
/*24*/ @$undefined_var,
// unset data
/*25*/ @$unset_var,
// resource variable
/*26*/ $fp
);
// resource variable
$fp,
];
// loop through each element of $inputs to check the behaviour of pow()
$iterator = 1;
foreach($inputs as $input) {
echo "\n-- Iteration $iterator --\n";
foreach ($inputs as $input) {
try {
var_dump(pow(20.3, $input));
} catch (Error $e) {
echo $e->getMessage(), "\n";
}
$iterator++;
};
}
fclose($fp);
?>
--EXPECT--
*** Testing pow() : usage variations ***
-- Iteration 1 --
float(1)
-- Iteration 2 --
float(20.3)
-- Iteration 3 --
float(INF)
-- Iteration 4 --
float(0)
-- Iteration 5 --
float(INF)
-- Iteration 6 --
float(1856.6929774279)
-- Iteration 7 --
float(0.00053859200856424)
-- Iteration 8 --
float(INF)
-- Iteration 9 --
float(1.0000000037168)
-- Iteration 10 --
float(4.5055521304275)
-- Iteration 11 --
float(1)
-- Iteration 12 --
float(1)
-- Iteration 13 --
float(20.3)
-- Iteration 14 --
float(1)
-- Iteration 15 --
float(20.3)
-- Iteration 16 --
float(1)
-- Iteration 17 --
Unsupported operand types: float ** string
-- Iteration 18 --
Unsupported operand types: float ** string
-- Iteration 19 --
Unsupported operand types: float ** array
-- Iteration 20 --
Unsupported operand types: float ** string
-- Iteration 21 --
Unsupported operand types: float ** string
-- Iteration 22 --
Unsupported operand types: float ** string
-- Iteration 23 --
float(15532029.564086)
float(412.09)
float(1.2088495422866)
Unsupported operand types: float ** classA
-- Iteration 24 --
float(1)
-- Iteration 25 --
float(1)
-- Iteration 26 --
Unsupported operand types: float ** resource