Skip to content

Commit 7963507

Browse files
committed
Added a div test
1 parent df6d85a commit 7963507

File tree

1 file changed

+107
-0
lines changed

1 file changed

+107
-0
lines changed

ext/bcmath/tests/bcdiv_by_pow_10.phpt

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
--TEST--
2+
bcdiv() function with numbers pow 10
3+
--EXTENSIONS--
4+
bcmath
5+
--INI--
6+
bcmath.scale=0
7+
--FILE--
8+
<?php
9+
$dividend_cases = ['0.012345', '0.12345', '1.2345', '12.345', '123.45'];
10+
$divisor_cases = ['0.01', '0.1', '1', '10', '100'];
11+
$scale_cases = [0, 3, 5];
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, 8, ' ', STR_PAD_LEFT);
18+
$divisor_label = str_pad($divisor, 4, ' ', STR_PAD_LEFT);
19+
$quot = bcdiv($dividend, $divisor, $scale);
20+
$quot_label = str_pad($quot, $scale + 5 + ($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+
0.012345 / 0.01 = 1
30+
0.12345 / 0.01 = 12
31+
1.2345 / 0.01 = 123
32+
12.345 / 0.01 = 1234
33+
123.45 / 0.01 = 12345
34+
0.012345 / 0.1 = 0
35+
0.12345 / 0.1 = 1
36+
1.2345 / 0.1 = 12
37+
12.345 / 0.1 = 123
38+
123.45 / 0.1 = 1234
39+
0.012345 / 1 = 0
40+
0.12345 / 1 = 0
41+
1.2345 / 1 = 1
42+
12.345 / 1 = 12
43+
123.45 / 1 = 123
44+
0.012345 / 10 = 0
45+
0.12345 / 10 = 0
46+
1.2345 / 10 = 0
47+
12.345 / 10 = 1
48+
123.45 / 10 = 12
49+
0.012345 / 100 = 0
50+
0.12345 / 100 = 0
51+
1.2345 / 100 = 0
52+
12.345 / 100 = 0
53+
123.45 / 100 = 1
54+
55+
scale: 3
56+
0.012345 / 0.01 = 1.234
57+
0.12345 / 0.01 = 12.345
58+
1.2345 / 0.01 = 123.450
59+
12.345 / 0.01 = 1234.500
60+
123.45 / 0.01 = 12345.000
61+
0.012345 / 0.1 = 0.123
62+
0.12345 / 0.1 = 1.234
63+
1.2345 / 0.1 = 12.345
64+
12.345 / 0.1 = 123.450
65+
123.45 / 0.1 = 1234.500
66+
0.012345 / 1 = 0.012
67+
0.12345 / 1 = 0.123
68+
1.2345 / 1 = 1.234
69+
12.345 / 1 = 12.345
70+
123.45 / 1 = 123.450
71+
0.012345 / 10 = 0.001
72+
0.12345 / 10 = 0.012
73+
1.2345 / 10 = 0.123
74+
12.345 / 10 = 1.234
75+
123.45 / 10 = 12.345
76+
0.012345 / 100 = 0.000
77+
0.12345 / 100 = 0.001
78+
1.2345 / 100 = 0.012
79+
12.345 / 100 = 0.123
80+
123.45 / 100 = 1.234
81+
82+
scale: 5
83+
0.012345 / 0.01 = 1.23450
84+
0.12345 / 0.01 = 12.34500
85+
1.2345 / 0.01 = 123.45000
86+
12.345 / 0.01 = 1234.50000
87+
123.45 / 0.01 = 12345.00000
88+
0.012345 / 0.1 = 0.12345
89+
0.12345 / 0.1 = 1.23450
90+
1.2345 / 0.1 = 12.34500
91+
12.345 / 0.1 = 123.45000
92+
123.45 / 0.1 = 1234.50000
93+
0.012345 / 1 = 0.01234
94+
0.12345 / 1 = 0.12345
95+
1.2345 / 1 = 1.23450
96+
12.345 / 1 = 12.34500
97+
123.45 / 1 = 123.45000
98+
0.012345 / 10 = 0.00123
99+
0.12345 / 10 = 0.01234
100+
1.2345 / 10 = 0.12345
101+
12.345 / 10 = 1.23450
102+
123.45 / 10 = 12.34500
103+
0.012345 / 100 = 0.00012
104+
0.12345 / 100 = 0.00123
105+
1.2345 / 100 = 0.01234
106+
12.345 / 100 = 0.12345
107+
123.45 / 100 = 1.23450

0 commit comments

Comments
 (0)