DecimalModTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 27
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A modProvider() 0 11 1
A testFiniteFiniteMod() 0 10 1
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