Passed
Pull Request — master (#4)
by Kauri
08:37
created

loadEqualPrincipalData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace Kauri\Loan\Test;
4
5
6
use Kauri\Loan\PaymentAmountCalculator\AnnuityPaymentAmountCalculator;
7
use Kauri\Loan\PaymentAmountCalculator\EqualPrincipalPaymentAmountCalculator;
8
use PHPUnit\Framework\TestCase;
9
10
class PaymentAmountCalculatorTest extends TestCase
11
{
12
    /**
13
     * @dataProvider loanData
14
     * @param $presentValue
15
     * @param $totalPeriod
16
     * @param $currentPeriod
17
     * @param $yearlyInterestRate
18
     * @param $expected
19
     */
20 View Code Duplication
    public function testGetPaymentAmount(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
        $presentValue,
22
        $totalPeriod,
23
        $currentPeriod,
24
        $yearlyInterestRate,
25
        $expected
26
    ) {
27
        $ratePerPeriod = $yearlyInterestRate / 360 * $currentPeriod;
28
        $numberOfPeriods = $totalPeriod / $currentPeriod;
29
30
        $calculator = new AnnuityPaymentAmountCalculator();
31
        $paymentAmount = $calculator->getPaymentAmount($presentValue, $ratePerPeriod, $numberOfPeriods);
32
33
        $this->assertEquals($expected, round($paymentAmount, 2));
34
    }
35
36
    /**
37
     * @dataProvider loadEqualPrincipalData
38
     * @param $presentValue
39
     * @param $yearlyInterestRate
40
     * @param $totalPeriod
41
     * @param $currentPeriod
42
     * @param $expected
43
     */
44 View Code Duplication
    public function testGetEqualPrincipalPaymentAmount(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
        $presentValue,
46
        $yearlyInterestRate,
47
        $totalPeriod,
48
        $currentPeriod,
49
        $expected
50
    ) {
51
        $ratePerPeriod = $yearlyInterestRate / 360 * $currentPeriod;
52
        $numberOfPeriods = $totalPeriod / $currentPeriod;
53
54
        $calculator = new EqualPrincipalPaymentAmountCalculator();
55
        $paymentAmount = $calculator->getPaymentAmount($presentValue, $ratePerPeriod, $numberOfPeriods);
56
57
        $this->assertEquals($expected, round($paymentAmount, 2));
58
    }
59
60
    /**
61
     * @return array
62
     */
63
    public function loanData(): array
64
    {
65
        return [
66
            // Exact
67
            [900, 90, 60, 0, 600],
68
            [900, 90, 30, 0, 300],
69
            [300, 30, 30, 0, 300],
70
            [900, 90, 60, 360, 1067.42],
71
            [900, 90, 30, 360, 495.56],
72
            [674.43, 60, 30, 360, 495.56],
73
            [381.20, 30, 30, 360, 495.56],
74
            // Regular, 30 day month, 360 days a year
75
            [5630, 1800, 30, 9, 116.87], // 60 payments, monthly, 360 days a year
76
            [1000, 60, 30, 0, 500], // 2 payments, monthly, 360 days a year
77
        ];
78
    }
79
80
    /**
81
     * @return array
82
     */
83
    public function loadEqualPrincipalData(): array
84
    {
85
        return [
86
            [900, 0, 90, 30, 300],
87
            [600, 0, 60, 30, 300],
88
            [900, 360, 90, 30, 570],
89
            [600, 360, 60, 30, 480],
90
            [300, 360, 30, 30, 390]
91
        ];
92
    }
93
}
94