diff --git a/src/commonTest/kotlin/uk/gov/hmrc/FirstBonusTermCalculationTest.kt b/src/commonTest/kotlin/uk/gov/hmrc/FirstBonusTermCalculationTest.kt new file mode 100644 index 0000000..300492c --- /dev/null +++ b/src/commonTest/kotlin/uk/gov/hmrc/FirstBonusTermCalculationTest.kt @@ -0,0 +1,189 @@ +/* + * Copyright 2020 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package uk.gov.hmrc + +import kotlin.test.Test +import kotlin.test.assertEquals +import uk.gov.hmrc.helptosavecalculator.FirstBonusTermCalculation +import uk.gov.hmrc.helptosavecalculator.models.FirstBonusInput +import uk.gov.hmrc.helptosavecalculator.models.YearMonthDayInput + +class FirstBonusTermCalculationTest { + + @Test + fun `GIVEN calculateTotalProjectedSavingsIncludeBonuses called THEN return the total`() { + val valueOne = 1.0 + val valueTwo = 2.0 + val calculation = FirstBonusTermCalculation() + val result = calculation.calculateTotalProjectedSavingsIncludeBonuses(valueOne, valueTwo) + + assertEquals(3.0, result) + } + + @Test + fun `GIVEN regular payment is above paid in this month WHEN calculateAdditionalSavingsThisMonth called THEN return the total`() { + val input = FirstBonusInput(50.0, + 25.0, + 25.0, + YearMonthDayInput(2020, 3), + YearMonthDayInput(2022, 2, 28), + YearMonthDayInput(2024, 2, 28), + 50.0) + val calculation = FirstBonusTermCalculation() + val result = calculation.calculateAdditionalSavingsThisMonth(input) + + assertEquals(25.0, result) + } + + @Test + fun `GIVEN regular payment is below paid in this month WHEN calculateAdditionalSavingsThisMonth called THEN return zero`() { + val input = FirstBonusInput(25.0, + 25.0, + 50.0, + YearMonthDayInput(2020, 3), + YearMonthDayInput(2022, 2, 28), + YearMonthDayInput(2024, 2, 28), + 50.0) + val calculation = FirstBonusTermCalculation() + val result = calculation.calculateAdditionalSavingsThisMonth(input) + + assertEquals(0.0, result) + } + + @Test + fun `GIVEN calculateTotalProjectedSavings called THEN return the total`() { + val input = FirstBonusInput(25.0, + 25.0, + 50.0, + YearMonthDayInput(2020, 3), + YearMonthDayInput(2022, 2, 28), + YearMonthDayInput(2024, 2, 28), + 50.0) + val calculation = FirstBonusTermCalculation() + val result = calculation.calculateTotalProjectedSavings(input, 2.0, 10) + + assertEquals(277.0, result) + } + + @Test + fun `GIVEN calculateTotalProjectedBonuses called THEN return the total`() { + val valueOne = 1.0 + val valueTwo = 2.0 + val calculation = FirstBonusTermCalculation() + val result = calculation.calculateTotalProjectedBonuses(valueOne, valueTwo) + + assertEquals(3.0, result) + } + + @Test + fun `GIVEN calculateProjectedSavingsFirstBonusPeriod called THEN return the total`() { + val input = FirstBonusInput(25.0, + 25.0, + 50.0, + YearMonthDayInput(2020, 3), + YearMonthDayInput(2022, 2, 28), + YearMonthDayInput(2024, 2, 28), + 50.0) + val calculation = FirstBonusTermCalculation() + val result = calculation.calculateProjectedSavingsFirstBonusPeriod(input, 2.0, 10) + + assertEquals(277.0, result) + } + + @Test + fun `GIVEN balanceMustBeMoreThanForBonus is above projectedSavingsFirstBonusPeriod WHEN calculateHighestBalanceFirstBonusPeriod called THEN return balanceMustBeMoreThanForBonus`() { + val input = FirstBonusInput(25.0, + 25.0, + 50.0, + YearMonthDayInput(2020, 3), + YearMonthDayInput(2022, 2, 28), + YearMonthDayInput(2024, 2, 28), + 50.0) + val calculation = FirstBonusTermCalculation() + val result = calculation.calculateHighestBalanceFirstBonusPeriod(input, 2.0) + + assertEquals(50.0, result) + } + + @Test + fun `GIVEN balanceMustBeMoreThanForBonus is below projectedSavingsFirstBonusPeriod WHEN calculateHighestBalanceFirstBonusPeriod called THEN return projectedSavingsFirstBonusPeriod`() { + val input = FirstBonusInput(25.0, + 25.0, + 50.0, + YearMonthDayInput(2020, 3), + YearMonthDayInput(2022, 2, 28), + YearMonthDayInput(2024, 2, 28), + 1.0) + val calculation = FirstBonusTermCalculation() + val result = calculation.calculateHighestBalanceFirstBonusPeriod(input, 2.0) + + assertEquals(2.0, result) + } + + @Test + fun `GIVEN calculateProjectedFirstBonus called THEN return the total`() { + val calculation = FirstBonusTermCalculation() + val result = calculation.calculateProjectedFirstBonus(10.0) + + assertEquals(5.0, result) + } + + @Test + fun `GIVEN calculateProjectedAdditionalSavingsFinalBonusPeriod called THEN return the total`() { + val input = FirstBonusInput(10.0, + 25.0, + 50.0, + YearMonthDayInput(2020, 3), + YearMonthDayInput(2022, 2, 28), + YearMonthDayInput(2024, 2, 28), + 1.0) + val calculation = FirstBonusTermCalculation() + val result = calculation.calculateProjectedAdditionalSavingsFinalBonusPeriod(input) + + assertEquals(240.0, result) + } + + @Test + fun `GIVEN highestBalanceFinalBonusPeriod is above highestBalanceFirstBonusPeriod WHEN calculateProjectedFinalBonus called THEN return the total`() { + val calculation = FirstBonusTermCalculation() + val result = calculation.calculateProjectedFinalBonus(10.0, 5.0) + + assertEquals(2.5, result) + } + + @Test + fun `GIVEN highestBalanceFinalBonusPeriod is below highestBalanceFirstBonusPeriod WHEN calculateProjectedFinalBonus called THEN return zero`() { + val calculation = FirstBonusTermCalculation() + val result = calculation.calculateProjectedFinalBonus(5.0, 10.0) + + assertEquals(0.0, result) + } + + @Test + fun `GIVEN calculateMonthsLeftInScheme called THEN return the remaining months left in scheme`() { + val input = FirstBonusInput(10.0, + 25.0, + 50.0, + YearMonthDayInput(2020, 3), + YearMonthDayInput(2022, 2, 28), + YearMonthDayInput(2024, 2, 28), + 1.0) + val calculation = FirstBonusTermCalculation() + val result = calculation.calculateMonthsLeftInScheme(input) + + assertEquals(Pair(47, 23), result) + } +} diff --git a/src/commonTest/kotlin/uk/gov/hmrc/FirstBonusTermCalculatorTest.kt b/src/commonTest/kotlin/uk/gov/hmrc/FirstBonusTermCalculatorTest.kt index 2701d94..1dc47b2 100644 --- a/src/commonTest/kotlin/uk/gov/hmrc/FirstBonusTermCalculatorTest.kt +++ b/src/commonTest/kotlin/uk/gov/hmrc/FirstBonusTermCalculatorTest.kt @@ -18,7 +18,6 @@ package uk.gov.hmrc import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFailsWith -import uk.gov.hmrc.helptosavecalculator.Calculator import uk.gov.hmrc.helptosavecalculator.FirstBonusTermCalculator.runFirstBonusCalculator import uk.gov.hmrc.helptosavecalculator.exceptions.InvalidRegularPaymentException import uk.gov.hmrc.helptosavecalculator.models.FirstBonusInput @@ -26,21 +25,35 @@ import uk.gov.hmrc.helptosavecalculator.models.YearMonthDayInput class FirstBonusTermCalculatorTest { @Test - fun `Throw Exception when regular payment is below 1`() { + fun `GIVEN regular payment is below 1 THEN InvalidRegularPaymentException thrown`() { + val input = FirstBonusInput(0.0, + 0.0, + 0.0, + YearMonthDayInput(2020, 3), + YearMonthDayInput(2022, 2, 28), + YearMonthDayInput(2024, 2, 28), + 0.0) assertFailsWith { - Calculator.run(regularPayment = 0.0) + runFirstBonusCalculator(input) } } @Test - fun `Throw Exception when regular payment is above 50`() { + fun `GIVEN regular payment is above 50 THEN InvalidRegularPaymentException thrown`() { + val input = FirstBonusInput(51.0, + 0.0, + 0.0, + YearMonthDayInput(2020, 3), + YearMonthDayInput(2022, 2, 28), + YearMonthDayInput(2024, 2, 28), + 0.0) assertFailsWith { - Calculator.run(regularPayment = 51.0) + runFirstBonusCalculator(input) } } @Test - fun `A new account with no payment AND 1 pound regular payment`() { + fun `GIVEN new account with no payment WHEN 1 pound regular payment added THEN correct calculation displayed`() { val input = FirstBonusInput(1.0, 0.0, 0.0, @@ -60,7 +73,7 @@ class FirstBonusTermCalculatorTest { } @Test - fun `A new account with no payment AND 25 pound regular payment`() { + fun `GIVEN new account with no payment WHEN 25 pound regular payment added THEN correct calculation displayed`() { val input = FirstBonusInput(25.0, 0.0, 0.0, @@ -80,7 +93,7 @@ class FirstBonusTermCalculatorTest { } @Test - fun `A new account with no payment AND 50 pound regular payment`() { + fun `GIVEN new account with no payment WHEN 50 pound regular payment added THEN correct calculation displayed`() { val input = FirstBonusInput(50.0, 0.0, 0.0, @@ -100,7 +113,7 @@ class FirstBonusTermCalculatorTest { } @Test - fun `A new account paid in 50 first month, withdrawn 256 AND 25 pounds regular payment`() { + fun `GIVEN new account with 50 pounds first month AND withdrawn 25 WHEN 25 pound regular payment added THEN correct calculation displayed`() { val input = FirstBonusInput(25.0, 25.0, 50.0,