Skip to content

Commit 05f8bc7

Browse files
committed
Added a div by one test
1 parent 674ec02 commit 05f8bc7

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

ext/bcmath/tests/bcdiv_by_one.phpt

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
--TEST--
2+
bcdiv() function div by one
3+
--EXTENSIONS--
4+
bcmath
5+
--INI--
6+
bcmath.scale=0
7+
--FILE--
8+
<?php
9+
$dividend_cases = ['100', '-100'];
10+
$divisor_cases = ['1.010', '1.01', '1.1', '1', '-1.010', '-1.01', '-1.1', '-1'];
11+
$scale_cases = [0, 1, 2, 3];
12+
13+
foreach ($scale_cases as $scale) {
14+
echo "scale: {$scale}\n";
15+
foreach ($divisor_cases as $divisor) {
16+
foreach ($dividend_cases as $dividend) {
17+
$dividend_label = str_pad($dividend, 4, ' ', STR_PAD_LEFT);
18+
$divisor_label = str_pad($divisor, 6, ' ', STR_PAD_LEFT);
19+
$quot = bcdiv($dividend, $divisor, $scale);
20+
$quot_label = str_pad($quot, $scale + 2 + ($scale ? 1 : 0), ' ', STR_PAD_LEFT);
21+
echo $dividend_label, ' / ', $divisor_label, ' = ', $quot_label, "\n";
22+
}
23+
}
24+
echo "\n";
25+
}
26+
?>
27+
--EXPECT--
28+
scale: 0
29+
100 / 1.010 = 99
30+
-100 / 1.010 = -99
31+
100 / 1.01 = 99
32+
-100 / 1.01 = -99
33+
100 / 1.1 = 90
34+
-100 / 1.1 = -90
35+
100 / 1 = 100
36+
-100 / 1 = -100
37+
100 / -1.010 = -99
38+
-100 / -1.010 = 99
39+
100 / -1.01 = -99
40+
-100 / -1.01 = 99
41+
100 / -1.1 = -90
42+
-100 / -1.1 = 90
43+
100 / -1 = -100
44+
-100 / -1 = 100
45+
46+
scale: 1
47+
100 / 1.010 = 99.0
48+
-100 / 1.010 = -99.0
49+
100 / 1.01 = 99.0
50+
-100 / 1.01 = -99.0
51+
100 / 1.1 = 90.9
52+
-100 / 1.1 = -90.9
53+
100 / 1 = 100.0
54+
-100 / 1 = -100.0
55+
100 / -1.010 = -99.0
56+
-100 / -1.010 = 99.0
57+
100 / -1.01 = -99.0
58+
-100 / -1.01 = 99.0
59+
100 / -1.1 = -90.9
60+
-100 / -1.1 = 90.9
61+
100 / -1 = -100.0
62+
-100 / -1 = 100.0
63+
64+
scale: 2
65+
100 / 1.010 = 99.00
66+
-100 / 1.010 = -99.00
67+
100 / 1.01 = 99.00
68+
-100 / 1.01 = -99.00
69+
100 / 1.1 = 90.90
70+
-100 / 1.1 = -90.90
71+
100 / 1 = 100.00
72+
-100 / 1 = -100.00
73+
100 / -1.010 = -99.00
74+
-100 / -1.010 = 99.00
75+
100 / -1.01 = -99.00
76+
-100 / -1.01 = 99.00
77+
100 / -1.1 = -90.90
78+
-100 / -1.1 = 90.90
79+
100 / -1 = -100.00
80+
-100 / -1 = 100.00
81+
82+
scale: 3
83+
100 / 1.010 = 99.009
84+
-100 / 1.010 = -99.009
85+
100 / 1.01 = 99.009
86+
-100 / 1.01 = -99.009
87+
100 / 1.1 = 90.909
88+
-100 / 1.1 = -90.909
89+
100 / 1 = 100.000
90+
-100 / 1 = -100.000
91+
100 / -1.010 = -99.009
92+
-100 / -1.010 = 99.009
93+
100 / -1.01 = -99.009
94+
-100 / -1.01 = 99.009
95+
100 / -1.1 = -90.909
96+
-100 / -1.1 = 90.909
97+
100 / -1 = -100.000
98+
-100 / -1 = 100.000

0 commit comments

Comments
 (0)