Passed
Push — master ( f22158...709c4a )
by Kauri
31s
created

testGetInterestAmount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 4
1
<?php
2
3
namespace Kauri\Loan\Test;
4
5
6
use Kauri\Loan\InterestAmountCalculator;
7
use PHPUnit\Framework\TestCase;
8
9
10
class InterestAmountCalculatorTest extends TestCase
11
{
12
    /**
13
     * @dataProvider loadData
14
     * @param $presentValue
15
     * @param $currentPeriod
16
     * @param $yearlyInterestRate
17
     * @param $expectedInterest
18
     */
19
    public function testGetInterestAmount($presentValue, $currentPeriod, $yearlyInterestRate, $expectedInterest)
20
    {
21
        $ratePerPeriod = $yearlyInterestRate / 360 * $currentPeriod;
22
23
        $calculator = new InterestAmountCalculator();
24
        $interestAmount = $calculator->getInterestAmount($presentValue, $ratePerPeriod);
25
        $this->assertEquals($expectedInterest, $interestAmount);
26
    }
27
28
    public function loadData()
29
    {
30
        return [
31
            // Regular annuity
32
            [100, 30, 360, 30],
33
            [100, 30, 180, 15],
34
            // Exact
35
            [100, 10, 360, 10],
36
            [100, 29, 180, 14.5]
37
        ];
38
    }
39
40
}
41