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

InterestAmountCalculatorTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetInterestAmount() 0 8 1
A loadData() 0 11 1
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