Completed
Push — master ( b9f967...7a222d )
by Andreu
9s
created

DecimalModTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 4
Bugs 1 Features 2
Metric Value
wmc 2
c 4
b 1
f 2
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
5
/**
6
 * @group mod
7
 */
8
class DecimalModTest extends PHPUnit_Framework_TestCase
9
{
10
    public function modProvider() {
11
        return [
12
            ['10', '3', '1'],
13
            ['34', '3.4', '0'],
14
            ['15.1615', '3.156156', '2.536876'],
15
            ['15.1615', '3.156156', '2.5369', 4],
16
            ['-3.4', '-2', '-1.4'],
17
            ['3.4', '-2', '-0.6'],
18
            ['-3.4', '2', '0.6']
19
        ];
20
    }
21
    /**
22
     * @dataProvider modProvider
23
     */
24
    public function testFiniteFiniteMod($number, $mod, $answer, $scale = null) {
25
        $numberDec = Decimal::fromString($number);
26
        $modDec = Decimal::fromString($mod);
27
        $decimalAnswer = $numberDec->mod($modDec, $scale);
28
29
        $this->assertTrue(
30
            Decimal::fromString($answer)->equals($decimalAnswer),
31
            $decimalAnswer . ' % ' . $mod . ' must be equal to ' . $answer . ', but was ' . $decimalAnswer
32
        );
33
    }
34
}
35