DecimalModTest::testFiniteFiniteMod()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 7
nc 1
nop 4
1
<?php
2
3
use Litipk\BigNumbers\Decimal as Decimal;
4
use PHPUnit\Framework\TestCase;
5
6
/**
7
 * @group mod
8
 */
9
class DecimalModTest extends TestCase
10
{
11
    public function modProvider() {
12
        return [
13
            ['10', '3', '1'],
14
            ['34', '3.4', '0'],
15
            ['15.1615', '3.156156', '2.536876'],
16
            ['15.1615', '3.156156', '2.5369', 4],
17
            ['-3.4', '-2', '-1.4'],
18
            ['3.4', '-2', '-0.6'],
19
            ['-3.4', '2', '0.6']
20
        ];
21
    }
22
    /**
23
     * @dataProvider modProvider
24
     */
25
    public function testFiniteFiniteMod($number, $mod, $answer, $scale = null) {
26
        $numberDec = Decimal::fromString($number);
27
        $modDec = Decimal::fromString($mod);
28
        $decimalAnswer = $numberDec->mod($modDec, $scale);
29
30
        $this->assertTrue(
31
            Decimal::fromString($answer)->equals($decimalAnswer),
32
            $decimalAnswer . ' % ' . $mod . ' must be equal to ' . $answer . ', but was ' . $decimalAnswer
33
        );
34
    }
35
}
36