From ec46828ea4cf10b4d07b594fa0039ed8c2457fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A1clav=20Uruba?= Date: Tue, 8 Sep 2015 15:56:10 +0200 Subject: [PATCH] =?UTF-8?q?=E2=80=93=20updated=20README=20and=20tests=20fo?= =?UTF-8?q?r=20AnnuityCalculator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- readme.md | 8 ++++---- src/Calculators/AnnuityCalculator.php | 7 +++++++ tests/AnnuityCalculatorTest.php | 14 ++++++++++++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/readme.md b/readme.md index c1a851e..f9cf79a 100644 --- a/readme.md +++ b/readme.md @@ -85,7 +85,7 @@ use FinanCalc\Utils\Time\TimeUtils; $annuityCalculatorDirect = new DebtAmortizator( 40000, 6, - TimeUtils::getDaysFromYears(1), + TimeSpan::asDuration(1), 0.12); ``` @@ -281,16 +281,16 @@ The implicit type of setters'/constructors' arguments as well as getters' return ### AnnuityCalculator namespace `FinanCalc\Calculators` -* **__construct($annuitySinglePaymentAmount, $annuityNoOfCompoundingPeriods, $annuityPeriodLength, $annuityInterest)** +* **__construct($annuitySinglePaymentAmount, $annuityNoOfCompoundingPeriods, TimeSpan $annuityPeriodLength, $annuityInterest)** * *$annuitySinglePaymentAmount* = **'K'** – amount of each individual payment (number greater than zero) * *$annuityNoOfCompoundingPeriods* = **'n'** – number of periods pertaining to the interest compounding; if 'n = 0', the annuity is considered a perpetuity - * *$annuityPeriodLength* = length of a single period in days (number greater than zero) + * *$annuityPeriodLength* = length of a single period as a TimeSpan object * *$annuityInterest* = **'i'** – the interest rate *per a single payment period* by which the unpaid balance is multiplied (i.e., a decimal number typically lower than 1 and greater than 0) ##### Setters * **setAnnuitySinglePaymentAmount($annuitySinglePaymentAmount)** – sets K * **setAnnuityNoOfCompoundingPeriods($annuityNoOfCompoundingPeriods)** – sets n -* **setAnnuityPeriodLength($annuityPeriodLength)** – sets the length of each compounding period in days +* **setAnnuityPeriodLength(TimeSpan $annuityPeriodLength)** – sets the length of each compounding period in days * **setAnnuityInterest($annuityInterest)** – sets i ##### Getters diff --git a/src/Calculators/AnnuityCalculator.php b/src/Calculators/AnnuityCalculator.php index b9e701b..c6e941a 100644 --- a/src/Calculators/AnnuityCalculator.php +++ b/src/Calculators/AnnuityCalculator.php @@ -124,6 +124,13 @@ public function getAnnuityNoOfCompoundingPeriods() { return $this->annuityNoOfCompoundingPeriods; } + /** + * @return TimeSpan + */ + public function getAnnuityPeriodLength() { + return $this->annuityPeriodLength; + } + /** * @return string */ diff --git a/tests/AnnuityCalculatorTest.php b/tests/AnnuityCalculatorTest.php index 3a5e7d5..0970044 100644 --- a/tests/AnnuityCalculatorTest.php +++ b/tests/AnnuityCalculatorTest.php @@ -174,9 +174,14 @@ public function testMonthlyAnnuityFactory() { ); $this->assertEquals( - 1, + TimeSpan::asDuration(0,1,0), $annuityCalculatorFactoryMonthly + ->getAnnuityPeriodLength() + ); + $this->assertEquals( + 1, + $annuityCalculatorFactoryMonthly ->getAnnuityPeriodLengthInMonths() ); } @@ -215,9 +220,14 @@ public function testDailyAnnuityFactory() { ); $this->assertEquals( - 1, + TimeSpan::asDuration(0,0,1), $annuityCalculatorFactoryDaily + ->getAnnuityPeriodLength() + ); + $this->assertEquals( + 1, + $annuityCalculatorFactoryDaily ->getAnnuityPeriodLengthInDays() ); }