-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Extend tests of bcmath extension #11563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering the 3 nested foreach loops are repeated in every test, I would rather have an included file that defines a function that takes the required arguments + function to execute + symbol to display.
Lot of missing EOLs before EOF.
Those tests are generate a lot of output, that I only skimmed through the actual results.
ext/bcmath/tests/bcadd_zero.phpt
Outdated
$firstSummands = ["0", "0.00", "-0", "-0.00"]; | ||
$secondSummands = array_merge($firstSummands, ["15", "-15", "1", "-9", "14.14", "-16.60", "0.15", "-0.01", "15151324141414.412312232141241", "-132132245132134.1515123765412", "141241241241241248267654747412", "-149143276547656984948124912", "0.1322135476547459213732911312", "-0.123912932193769965476541321"]); | ||
$scales = [0,10]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please split that second array into multiple lines or have it as a constant at the beginning of the file.
As this line is just huge.
ext/bcmath/tests/bcadd_zero.phpt
Outdated
foreach($firstSummands as $firstSummand) { | ||
echo "Number \"$firstSummand\" (scale $scale)\n"; | ||
foreach($secondSummands as $secondSummand) { | ||
echo str_pad($firstSummand, 6, ' ', STR_PAD_LEFT), " + ", str_pad($secondSummand, 30), ' = ', bcadd($firstSummand, $secondSummand, $scale),"\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use constants for the padded length.
ext/bcmath/tests/bccomp.phpt
Outdated
?> | ||
--EXPECT-- | ||
-1 | ||
-1 | ||
0 | ||
1 | ||
-1 | ||
1 | ||
0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EOL before EOF
?> | ||
--EXPECT-- | ||
0 | ||
1 | ||
-1 | ||
1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EOL before EOF
@@ -20,3 +21,4 @@ echo bccomp("-2.29", "-2.3", "1"); | |||
-1 | |||
1 | |||
1 | |||
-1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EOL before EOF
ext/bcmath/tests/bcmul.phpt
Outdated
$firstFactors = ["15", "-15", "1", "-9", "14.14", "-16.60", "0.15", "-0.01"]; | ||
$secondFactors = array_merge($firstFactors, ["0", "0.00", "-0", "-0.00", "15151324141414.412312232141241", "-132132245132134.1515123765412", "141241241241241248267654747412", "-149143276547656984948124912", "0.1322135476547459213732911312", "-0.123912932193769965476541321"]); | ||
$scales = [0,10]; | ||
|
||
foreach($scales as $scale) { | ||
foreach($firstFactors as $firstFactor) { | ||
echo "Number \"$firstFactor\" (scale $scale)\n"; | ||
foreach($secondFactors as $secondFactor) { | ||
echo str_pad($firstFactor, 6, ' ', STR_PAD_LEFT), " × " , str_pad($secondFactor, 30), ' = ', bcmul($firstFactor, $secondFactor, $scale),"\n"; | ||
} | ||
echo "\n"; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Format
ext/bcmath/tests/bcmul.phpt
Outdated
-0.01 × 141241241241241248267654747412 = -1412412412412412482676547474.1200000000 | ||
-0.01 × -149143276547656984948124912 = 1491432765476569849481249.1200000000 | ||
-0.01 × 0.1322135476547459213732911312 = -0.0013221354 | ||
-0.01 × -0.123912932193769965476541321 = 0.0012391293 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EOL
$firstSummands = ["15151324141414.412312232141241", "-132132245132134.1515123765412", "141241241241241248267654747412", "-149143276547656984948124912", "0.1322135476547459213732911312", "-0.123912932193769965476541321"]; | ||
$secondSummands = array_merge($firstSummands, ["0", "0.00", "-0", "-0.00", "15", "-15", "1", "-9", "14.14", "-16.60", "0.15", "-0.01"]); | ||
$scales = [0,10]; | ||
|
||
foreach($scales as $scale) { | ||
foreach($firstSummands as $firstSummand) { | ||
echo "Number \"$firstSummand\" (scale $scale)\n"; | ||
foreach($secondSummands as $secondSummand) { | ||
echo $firstSummand, " + ", str_pad($secondSummand, 30), ' = ', bcadd($firstSummand, $secondSummand, $scale),"\n"; | ||
} | ||
echo "\n"; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Format
ext/bcmath/tests/bcadd.phpt
Outdated
$firstSummands = ["15", "-15", "1", "-9", "14.14", "-16.60", "0.15", "-0.01"]; | ||
$secondSummands = array_merge($firstSummands, ["0", "0.00", "-0", "-0.00", "15151324141414.412312232141241", "-132132245132134.1515123765412", "141241241241241248267654747412", "-149143276547656984948124912", "0.1322135476547459213732911312", "-0.123912932193769965476541321"]); | ||
$scales = [0,10]; | ||
|
||
foreach($scales as $scale) { | ||
foreach($firstSummands as $firstSummand) { | ||
echo "Number \"$firstSummand\" (scale $scale)\n"; | ||
foreach($secondSummands as $secondSummand) { | ||
echo str_pad($firstSummand, 6, ' ', STR_PAD_LEFT), " + ", str_pad($secondSummand, 30), ' = ', bcadd($firstSummand, $secondSummand, $scale),"\n"; | ||
} | ||
echo "\n"; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Format
ext/bcmath/tests/bcadd.phpt
Outdated
-0.01 + 141241241241241248267654747412 = 141241241241241248267654747411.9900000000 | ||
-0.01 + -149143276547656984948124912 = -149143276547656984948124912.0100000000 | ||
-0.01 + 0.1322135476547459213732911312 = 0.1222135476 | ||
-0.01 + -0.123912932193769965476541321 = -0.1339129321 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EOL
} | ||
} | ||
|
||
?> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To prevent output happening
?> |
ext/bcmath/tests/bcpow.phpt
Outdated
echo bcpow("2", "64"),"\n"; | ||
echo bcpow("-2.555", "5", 2),"\n"; | ||
|
||
$exponents = ["15", "-15", "1", "-9", "0", "-0", "252", "-112"]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems the large exponents where moved to another test but not dropped here?
"0", | ||
"0.00", | ||
"-0", | ||
"-0.00", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As multiplying with 0 is already done in another test those should be removed IMHO
"0", | ||
"0.00", | ||
"-0", | ||
"-0.00", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
ext/bcmath/tests/bcdiv_zero.phpt
Outdated
-0.00 / 141241241241241248267654747412 = 0.0000000000 | ||
-0.00 / -149143276547656984948124912 = 0.0000000000 | ||
-0.00 / 0.1322135476547459213732911312 = 0.0000000000 | ||
-0.00 / -0.123912932193769965476541321 = 0.0000000000 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EOL before EOF
echo bccomp("-2.29", "-2.3", "1")."\n"; | ||
echo bccomp("-2.29", "0", "1"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo bccomp("-2.29", "-2.3", "1")."\n"; | |
echo bccomp("-2.29", "0", "1"); | |
echo bccomp("-2.29", "-2.3", "1")."\n"; | |
echo bccomp("-2.29", "0", "1")."\n"; |
Just to be consistent.
echo bccomp("2.29", "2.3", "2")."\n"; | ||
echo bccomp("2.29", "0", "2"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo bccomp("2.29", "2.3", "2")."\n"; | |
echo bccomp("2.29", "0", "2"); | |
echo bccomp("2.29", "2.3", "2")."\n"; | |
echo bccomp("2.29", "0", "2")."\n"; |
Just to be consistent
ext/bcmath/tests/bccomp.phpt
Outdated
echo bccomp("1", "0"), "\n"; | ||
echo bccomp("0.000", "0", 3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
echo bccomp("1", "0"), "\n"; | |
echo bccomp("0.000", "0", 3); | |
echo bccomp("1", "0"), "\n"; | |
echo bccomp("0.000", "0", 3), "\n"; |
Consistency
"0", | ||
"0.00", | ||
"-0", | ||
"-0.00", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're already testing 0 in another test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We test it, but as a first arguments of the function. In this test we pass zeroes only as second argument of the function. The same with other tests. Do you think it's too much coverage and should be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, should be fine then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you forget to push the changes while asking for a rereview?
@Girgias, thank you for the review. I pushed another small set of improvements. Found some duplicated values in tests. I'm not sure about removing zeroes from other tests, but if you think it's not needed then I can remove it. |
Thank you! |
I wanted to extend the BC library, but before that I thought about strengthening the test suite for the existing functionalities.
During those test I found some things which can be improved later.
I covered all of the possible types of numbers (accordingly to the functions):
0
,0.0
)