Skip to content

Commit

Permalink
Fix calculation for canEarnFinalBonus. (#10)
Browse files Browse the repository at this point in the history
- now calculate `canEarnFinalBonus` with the maximum a user can pay in the current month, previously calculated by user's slider input.
  • Loading branch information
ngoulongkam authored Apr 9, 2020
1 parent f946697 commit e3a756e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ Where `input` is of the type `FinalBonusInput` with the following parameters:
regularPayment: Double, // 25.0
currentBalance: Double, // 25.0
paidInThisMonth: Double, // 50.0
canPayInThisMonth: Double, // 0.0
thisMonthEndDate: YearMonthDayInput, // YearMonthDayInput(2022, 3, 31)
secondTermEndDate: YearMonthDayInput, // YearMonthDayInput(2024, 2, 28)
balanceMustBeMoreThanForBonus: Double, // 50.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ internal class FinalBonusTermCalculation {

fun finalBonusStatus(
input: FinalBonusInput,
monthsLeftInScheme: Int,
additionalSavingsThisMonth: Double
monthsLeftInScheme: Int
): FinalBonusStatus {
val highestPossibleBalance = input.currentBalance + additionalSavingsThisMonth + (monthsLeftInScheme * 50)
val highestPossibleBalance = input.currentBalance + input.canPayInThisMonth + (monthsLeftInScheme * 50)
return if (input.secondTermBonusEstimate > 0.0) FinalBonusStatus.EARNED else {
if (highestPossibleBalance > input.balanceMustBeMoreThanForBonus)
FinalBonusStatus.POSSIBLE_TO_EARN else FinalBonusStatus.CANNOT_EARN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object FinalBonusTermCalculator {
val totalProjectedSavingsIncludingBonuses = calculation.calculateTotalProjectedSavingsIncludeBonuses(
totalProjectedSavings,
totalProjectedBonuses)
val finalBonusStatus = calculation.finalBonusStatus(input, monthLeftInScheme, additionalSavingsThisMonth)
val finalBonusStatus = calculation.finalBonusStatus(input, monthLeftInScheme)

return FinalBonusCalculatorResponse(
totalProjectedSavingsIncludingBonuses,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ data class FinalBonusInput(
val regularPayment: Double,
val currentBalance: Double,
val paidInThisMonth: Double,
val canPayInThisMonth: Double,
val thisMonthEndDate: YearMonthDayInput,
val secondTermEndDate: YearMonthDayInput,
val balanceMustBeMoreThanForBonus: Double,
Expand Down
16 changes: 13 additions & 3 deletions src/commonTest/kotlin/uk/gov/hmrc/FinalBonusTermCalculationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class FinalBonusTermCalculationTest {
val input = FinalBonusInput(25.0,
0.0,
10.0,
40.0,
YearMonthDayInput(2022, 3),
YearMonthDayInput(2024, 2, 28),
0.0,
Expand All @@ -44,6 +45,7 @@ class FinalBonusTermCalculationTest {
val input = FinalBonusInput(10.0,
0.0,
25.0,
25.0,
YearMonthDayInput(2022, 3),
YearMonthDayInput(2024, 2, 28),
0.0,
Expand All @@ -69,6 +71,7 @@ class FinalBonusTermCalculationTest {
val input = FinalBonusInput(10.0,
0.0,
25.0,
25.0,
YearMonthDayInput(2022, 3),
YearMonthDayInput(2024, 2, 28),
0.0,
Expand All @@ -84,6 +87,7 @@ class FinalBonusTermCalculationTest {
val input = FinalBonusInput(10.0,
0.0,
25.0,
25.0,
YearMonthDayInput(2022, 3),
YearMonthDayInput(2024, 2, 28),
2.0,
Expand All @@ -99,6 +103,7 @@ class FinalBonusTermCalculationTest {
val input = FinalBonusInput(10.0,
0.0,
25.0,
25.0,
YearMonthDayInput(2022, 3),
YearMonthDayInput(2024, 2, 28),
10.0,
Expand All @@ -114,6 +119,7 @@ class FinalBonusTermCalculationTest {
val input = FinalBonusInput(10.0,
0.0,
25.0,
25.0,
YearMonthDayInput(2022, 3),
YearMonthDayInput(2024, 2, 28),
10.0,
Expand Down Expand Up @@ -145,6 +151,7 @@ class FinalBonusTermCalculationTest {
val input = FinalBonusInput(10.0,
0.0,
25.0,
25.0,
YearMonthDayInput(2023, 3),
YearMonthDayInput(2024, 2, 28),
10.0,
Expand All @@ -160,12 +167,13 @@ class FinalBonusTermCalculationTest {
val input = FinalBonusInput(10.0,
0.0,
25.0,
25.0,
YearMonthDayInput(2023, 3),
YearMonthDayInput(2024, 2, 28),
10.0,
5.0)
val calculation = FinalBonusTermCalculation()
val result = calculation.finalBonusStatus(input, 23, 0.0)
val result = calculation.finalBonusStatus(input, 23)

assertEquals(FinalBonusStatus.EARNED, result)
}
Expand All @@ -175,12 +183,13 @@ class FinalBonusTermCalculationTest {
val input = FinalBonusInput(10.0,
0.0,
25.0,
25.0,
YearMonthDayInput(2023, 3),
YearMonthDayInput(2024, 2, 28),
10.0,
0.0)
val calculation = FinalBonusTermCalculation()
val result = calculation.finalBonusStatus(input, 23, 0.0)
val result = calculation.finalBonusStatus(input, 23)

assertEquals(FinalBonusStatus.POSSIBLE_TO_EARN, result)
}
Expand All @@ -190,12 +199,13 @@ class FinalBonusTermCalculationTest {
val input = FinalBonusInput(50.0,
0.0,
0.0,
25.0,
YearMonthDayInput(2023, 3),
YearMonthDayInput(2024, 2, 28),
1200.0,
0.0)
val calculation = FinalBonusTermCalculation()
val result = calculation.finalBonusStatus(input, 22, 50.0)
val result = calculation.finalBonusStatus(input, 22)

assertEquals(FinalBonusStatus.CANNOT_EARN, result)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class FinalBonusTermCalculatorTest {
val input = FinalBonusInput(0.0,
0.0,
10.0,
40.0,
YearMonthDayInput(2022, 3),
YearMonthDayInput(2024, 2, 28),
0.0,
Expand All @@ -45,6 +46,7 @@ class FinalBonusTermCalculatorTest {
val input = FinalBonusInput(51.0,
0.0,
10.0,
40.0,
YearMonthDayInput(2022, 3),
YearMonthDayInput(2024, 2, 28),
0.0,
Expand All @@ -59,6 +61,7 @@ class FinalBonusTermCalculatorTest {
val input = FinalBonusInput(1.0,
0.0,
0.0,
50.0,
YearMonthDayInput(2022, 3),
YearMonthDayInput(2024, 2, 28),
0.0,
Expand All @@ -76,6 +79,7 @@ class FinalBonusTermCalculatorTest {
val input = FinalBonusInput(25.0,
0.0,
0.0,
50.0,
YearMonthDayInput(2022, 3),
YearMonthDayInput(2024, 2, 28),
0.0,
Expand All @@ -93,6 +97,7 @@ class FinalBonusTermCalculatorTest {
val input = FinalBonusInput(50.0,
0.0,
0.0,
50.0,
YearMonthDayInput(2022, 3),
YearMonthDayInput(2024, 2, 28),
0.0,
Expand All @@ -110,6 +115,7 @@ class FinalBonusTermCalculatorTest {
val input = FinalBonusInput(25.0,
25.0,
50.0,
50.0,
YearMonthDayInput(2022, 3),
YearMonthDayInput(2024, 2, 28),
0.0,
Expand All @@ -127,6 +133,7 @@ class FinalBonusTermCalculatorTest {
val input = FinalBonusInput(25.0,
0.0,
0.0,
50.0,
YearMonthDayInput(2024, 2),
YearMonthDayInput(2024, 2, 28),
1200.0,
Expand Down

0 comments on commit e3a756e

Please sign in to comment.