1<?php
2
3function printResult (array $cases, RoundingMode $mode)
4{
5    foreach ($cases as [$num, $precision]) {
6        echo str_pad("[{$num}, {$precision}]", 17, ' ', STR_PAD_LEFT), " => ", bcround($num, $precision, $mode), "\n";
7    }
8    echo "\n";
9}
10
11function run_round_test(RoundingMode $mode)
12{
13    $non_boundary_value_cases = [
14        ['1.1', 0],
15        ['1.2', 0],
16        ['1.3', 0],
17        ['1.4', 0],
18        ['1.6', 0],
19        ['1.7', 0],
20        ['1.8', 0],
21        ['1.9', 0],
22        ['-1.1', 0],
23        ['-1.2', 0],
24        ['-1.3', 0],
25        ['-1.4', 0],
26        ['-1.6', 0],
27        ['-1.7', 0],
28        ['-1.8', 0],
29        ['-1.9', 0],
30    ];
31
32    $minus_precision_cases = [
33        ['50', -2],
34        ['-50', -2],
35        ['1230', -1],
36        ['1235', -1],
37        ['-1230', -1],
38        ['-1235', -1],
39        ['3400.0000', -2],
40        ['3400.0001', -2],
41        ['3450.0000', -2],
42        ['3450.0001', -2],
43        ['-3400.0000', -2],
44        ['-3400.0001', -2],
45        ['-3450.0000', -2],
46        ['-3450.0001', -2],
47    ];
48
49    $zero_precision_cases = [
50        ['1235', 0],
51        ['1235.0', 0],
52        ['1235.000001', 0],
53        ['1235.5', 0],
54        ['1235.500001', 0],
55        ['-1235', 0],
56        ['-1235.0', 0],
57        ['-1235.000001', 0],
58        ['-1235.5', 0],
59        ['-1235.500001', 0],
60        ['0.0001', 0],
61        ['0.5', 0],
62        ['0.5000', 0],
63        ['0.5001', 0],
64        ['-0.0001', 0],
65        ['-0.5', 0],
66        ['-0.5000', 0],
67        ['-0.5001', 0],
68    ];
69
70    $plus_precision_cases = [
71        ['28.40', 1],
72        ['28.4000001', 1],
73        ['28.45', 1],
74        ['28.4500001', 1],
75        ['-28.40', 1],
76        ['-28.4000001', 1],
77        ['-28.45', 1],
78        ['-28.4500001', 1],
79        ['153.90', 1],
80        ['153.9000001', 1],
81        ['153.95', 1],
82        ['153.9500001', 1],
83        ['-153.90', 1],
84        ['-153.9000001', 1],
85        ['-153.95', 1],
86        ['-153.9500001', 1],
87        ['0.000001', 3],
88        ['0.0005', 3],
89        ['0.000500', 3],
90        ['0.000501', 3],
91        ['-0.000001', 3],
92        ['-0.0005', 3],
93        ['-0.000500', 3],
94        ['-0.000501', 3],
95    ];
96
97    echo "========== non-boundary value ==========\n";
98    printResult($non_boundary_value_cases, $mode);
99
100    echo "========== minus precision ==========\n";
101    printResult($minus_precision_cases, $mode);
102
103    echo "========== zero precision ==========\n";
104    printResult($zero_precision_cases, $mode);
105
106    echo "========== plus precision ==========\n";
107    printResult($plus_precision_cases, $mode);
108}
109