diff --git a/.gitignore b/.gitignore index 51dfc6b..f80d13b 100644 --- a/.gitignore +++ b/.gitignore @@ -24,8 +24,10 @@ yarn-error.log /build/ +buildSrc/build/ /.idea/ /.gradle/ +buildSrc/.gradle/ credentials.properties gradlew.bat local.properties diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c4bc7e..2729b4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +- Updated KMP version and cleaned up gradle scripts. ## [0.6.0] - 2021-04-07 - Changed to Github packages for artefact storage. diff --git a/build.gradle.kts b/build.gradle.kts index e58496a..302e183 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,6 @@ import java.text.SimpleDateFormat import java.util.Date +import uk.gov.hmrc.Dependencies buildscript{ repositories { @@ -12,7 +13,7 @@ buildscript{ } } dependencies { - classpath("uk.gov.hmrc.gradle:spotless:1.0.0") + classpath("uk.gov.hmrc.gradle:spotless:1.1.1") } } @@ -24,7 +25,7 @@ version = System.getenv("BITRISE_GIT_TAG") ?: ("SNAPSHOT-" + getDate()) plugins { `maven-publish` - kotlin("multiplatform").version("1.6.0") + kotlin("multiplatform").version("1.7.20") java id("io.gitlab.arturbosch.detekt").version("1.6.0") id("com.chromaticnoise.multiplatform-swiftpackage").version("2.0.3") @@ -33,15 +34,10 @@ plugins { repositories { mavenCentral() - jcenter() maven { url = uri("https://plugins.gradle.org/m2/") } } - -val artifactId = "help-to-save-kalculator" -val frameworkName = "HelpToSaveKalculator" - // Configure source sets kotlin { @@ -53,7 +49,7 @@ kotlin { targets{ configure(listOf(iosX64, iosArm32, iosArm64)) { binaries.framework { - baseName = frameworkName + baseName = Config.frameworkName embedBitcode("disable") } } @@ -64,39 +60,48 @@ kotlin { } sourceSets { - val klockVersion = "2.0.1" val commonMain by getting { dependencies { - implementation(kotlin("stdlib-common")) - implementation("com.soywiz.korlibs.klock:klock:$klockVersion") + with(Dependencies.Common.Main) { + implementation(kotlin(stdlib)) + implementation(klock) + implementation(kermit) + } } } val commonTest by getting { dependencies { - implementation(kotlin("test-common")) - implementation(kotlin("test-annotations-common")) - implementation("io.kotlintest:kotlintest-runner-junit5:3.4.2") - runtimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.1") + with(Dependencies.Common.Test) { + implementation(kotlin(uk.gov.hmrc.Dependencies.Common.Test.common)) + implementation(kotlin(uk.gov.hmrc.Dependencies.Common.Test.annotations)) + implementation(uk.gov.hmrc.Dependencies.Common.Test.junit) + runtimeOnly(uk.gov.hmrc.Dependencies.Common.Test.jupiter) + } } } val jvmMain by getting { dependencies { - implementation("com.soywiz.korlibs.klock:klock-jvm:$klockVersion") - implementation(kotlin("stdlib")) + with(Dependencies.JVM.Main) { + implementation(kotlin(uk.gov.hmrc.Dependencies.JVM.Main.stdlib)) + } } } val jvmTest by getting { dependencies { - implementation(kotlin("test")) - implementation(kotlin("test-junit5")) - implementation("org.junit.jupiter:junit-jupiter-params:5.7.1") + with(Dependencies.JVM.Test) { + implementation(kotlin(uk.gov.hmrc.Dependencies.JVM.Test.test)) + implementation(kotlin(uk.gov.hmrc.Dependencies.JVM.Test.junit)) + implementation(uk.gov.hmrc.Dependencies.JVM.Test.jupiter) + } } } val iosMain by getting { dependencies { - implementation(kotlin("stdlib")) + with(Dependencies.IOS.Main) { + implementation(kotlin(uk.gov.hmrc.Dependencies.IOS.Main.stdlib)) + } } } @@ -121,7 +126,7 @@ kotlin { multiplatformSwiftPackage { swiftToolsVersion("5.3") targetPlatforms { - iOS { v("11") } + iOS { v("13") } } outputDirectory(File(projectDir, "build/xcframework")) } @@ -182,8 +187,21 @@ tasks.named("jvmTest") { } } +tasks.named("jvmJar") { + archiveFileName.set("${Config.artifactId}-$version.jar") +} + +tasks.getByName("iosTest") { + deviceId = "iPhone 14" +} + fun getDate(): String { val date = Date() val format = "yyyyMMddHHmm" return SimpleDateFormat(format).format(date).toString() } + +object Config { + const val artifactId = "help-to-save-kalculator" + const val frameworkName = "HelpToSaveKalculator" +} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..b22ed73 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,7 @@ +plugins { + `kotlin-dsl` +} + +repositories { + mavenCentral() +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/uk/gov/hmrc/Dependencies.kt b/buildSrc/src/main/kotlin/uk/gov/hmrc/Dependencies.kt new file mode 100644 index 0000000..1e49113 --- /dev/null +++ b/buildSrc/src/main/kotlin/uk/gov/hmrc/Dependencies.kt @@ -0,0 +1,56 @@ +/* + * Copyright 2022 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 + +object Dependencies { + object Common { + object Main { + const val stdlib = "stdlib-common" + const val klock = "com.soywiz.korlibs.klock:klock:${Versions.klockVersion}" + const val kermit = "co.touchlab:kermit:${Versions.kermitVersion}" + } + object Test { + const val common = "test-common" + const val annotations = "test-annotations-common" + const val junit = "io.kotlintest:kotlintest-runner-junit5:${Versions.junit5Version}" + const val jupiter = "org.junit.jupiter:junit-jupiter-engine:${Versions.jupiterEngineVersion}" + } + } + + object JVM { + object Main { + const val stdlib = "stdlib" + } + object Test { + const val test = "test" + const val junit = "test-junit5" + const val jupiter = "org.junit.jupiter:junit-jupiter-params:${Versions.jupiterEngineVersion}" + } + } + + object IOS { + object Main { + const val stdlib = "stdlib" + } + } +} + +object Versions { + const val klockVersion = "2.0.7" + const val kermitVersion = "1.2.2" + const val junit5Version = "3.4.2" + const val jupiterEngineVersion = "5.7.1" +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c..41d9927 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 41dfb87..ae04661 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/Calculator.kt b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/Calculator.kt index 6f855f9..fe90384 100644 --- a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/Calculator.kt +++ b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/Calculator.kt @@ -37,7 +37,8 @@ object Calculator : HtSSchemeConfig() { accountStartDate: DateTime ): CalculatorResponse { return calculate( - regularPayment, currentBalance, currentFirstPeriodBonus, currentSecondPeriodBonus, accountStartDate) + regularPayment, currentBalance, currentFirstPeriodBonus, currentSecondPeriodBonus, accountStartDate + ) } private fun calculate( @@ -79,7 +80,9 @@ object Calculator : HtSSchemeConfig() { monthNumber = currentMonth, savingsToDate = endOfSchemeSavings, period1Bonus = endOfPeriod1Bonus, - period2Bonus = endOfPeriod2Bonus)) + period2Bonus = endOfPeriod2Bonus + ) + ) currentMonth++ } return CalculatorResponse( @@ -89,7 +92,8 @@ object Calculator : HtSSchemeConfig() { endOfPeriod1Bonus = endOfPeriod1Bonus, endOfPeriod1Savings = endOfPeriod1Savings, endOfPeriod2Bonus = endOfPeriod2Bonus, - endOfPeriod2Savings = endOfPeriod2Savings) + endOfPeriod2Savings = endOfPeriod2Savings + ) } private fun validateUserInput(regularPayment: Double) { diff --git a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FinalBonusTermCalculation.kt b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FinalBonusTermCalculation.kt index acb4312..036b50e 100644 --- a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FinalBonusTermCalculation.kt +++ b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FinalBonusTermCalculation.kt @@ -41,11 +41,11 @@ internal class FinalBonusTermCalculation { highestBalanceFinalBonusPeriod: Double, input: FinalBonusInput ) = if (highestBalanceFinalBonusPeriod > input.balanceMustBeMoreThanForBonus) { - (highestBalanceFinalBonusPeriod - input.balanceMustBeMoreThanForBonus) / 2 - } else 0.0 + (highestBalanceFinalBonusPeriod - input.balanceMustBeMoreThanForBonus) / 2 + } else 0.0 fun calculateMaybeHighestBalanceSoFar(input: FinalBonusInput) = - input.balanceMustBeMoreThanForBonus + (input.secondTermBonusEstimate * 2) + input.balanceMustBeMoreThanForBonus + (input.secondTermBonusEstimate * 2) fun calculateHighestBalanceFinalBonusPeriod( highestBalanceSoFar: Double, diff --git a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FinalBonusTermCalculator.kt b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FinalBonusTermCalculator.kt index d8db0e2..a188b03 100644 --- a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FinalBonusTermCalculator.kt +++ b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FinalBonusTermCalculator.kt @@ -31,26 +31,31 @@ object FinalBonusTermCalculator { val monthLeftInScheme = calculation.calculateMonthsLeftInScheme(input) val additionalSavingsThisMonth = calculation.calculateAdditionalSavingsThisMonth(input) - val totalProjectedSavings = calculation.calculateTotalProjectedSavings(input, - additionalSavingsThisMonth, - monthLeftInScheme) + val totalProjectedSavings = calculation.calculateTotalProjectedSavings( + input, + additionalSavingsThisMonth, + monthLeftInScheme + ) val maybeHighestBalanceSoFar = calculation.calculateMaybeHighestBalanceSoFar(input) val highestBalanceFinalBonusPeriod = calculation.calculateHighestBalanceFinalBonusPeriod( - maybeHighestBalanceSoFar, - totalProjectedSavings) + maybeHighestBalanceSoFar, + totalProjectedSavings + ) val totalProjectedBonuses = calculation.calculateTotalProjectedBonuses( - highestBalanceFinalBonusPeriod, - input) + highestBalanceFinalBonusPeriod, + input + ) val totalProjectedSavingsIncludingBonuses = calculation.calculateTotalProjectedSavingsIncludeBonuses( - totalProjectedSavings, - totalProjectedBonuses) + totalProjectedSavings, + totalProjectedBonuses + ) val finalBonusStatus = calculation.finalBonusStatus(input, monthLeftInScheme) return FinalBonusCalculatorResponse( - totalProjectedSavingsIncludingBonuses, - totalProjectedSavings, - totalProjectedBonuses, - finalBonusStatus + totalProjectedSavingsIncludingBonuses, + totalProjectedSavings, + totalProjectedBonuses, + finalBonusStatus ) } diff --git a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FirstBonusTermCalculation.kt b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FirstBonusTermCalculation.kt index 8cccc95..3249a26 100644 --- a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FirstBonusTermCalculation.kt +++ b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FirstBonusTermCalculation.kt @@ -26,7 +26,7 @@ internal class FirstBonusTermCalculation { ) = totalProjectedSavings + totalProjectedBonuses fun calculateAdditionalSavingsThisMonth(input: FirstBonusInput) = - if (input.regularPayment > input.paidInThisMonth) { + if (input.regularPayment > input.paidInThisMonth) { input.regularPayment - input.paidInThisMonth } else 0.0 @@ -55,7 +55,7 @@ internal class FirstBonusTermCalculation { } ?: projectedSavingsFirstBonusPeriod fun calculateProjectedFirstBonus(highestBalanceFirstBonusPeriod: Double) = - highestBalanceFirstBonusPeriod / 2 + highestBalanceFirstBonusPeriod / 2 fun calculateProjectedAdditionalSavingsFinalBonusPeriod(input: FirstBonusInput) = input.regularPayment * TWENTY_FOUR diff --git a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FirstBonusTermCalculator.kt b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FirstBonusTermCalculator.kt index a759a34..0384cb0 100644 --- a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FirstBonusTermCalculator.kt +++ b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/FirstBonusTermCalculator.kt @@ -31,33 +31,45 @@ object FirstBonusTermCalculator { val (monthLeftInScheme, monthLeftInFirstTerm) = calculation.calculateMonthsLeftInScheme(input) val additionalSavingsThisMonth = calculation.calculateAdditionalSavingsThisMonth(input) - val totalProjectedSavings = calculation.calculateTotalProjectedSavings(input, - additionalSavingsThisMonth, - monthLeftInScheme) - val projectedSavingsFirstBonusPeriod = calculation.calculateProjectedSavingsFirstBonusPeriod(input, - additionalSavingsThisMonth, - monthLeftInFirstTerm) - val highestBalanceFirstBonusPeriod = calculation.calculateHighestBalanceFirstBonusPeriod(input, - projectedSavingsFirstBonusPeriod) + val totalProjectedSavings = calculation.calculateTotalProjectedSavings( + input, + additionalSavingsThisMonth, + monthLeftInScheme + ) + val projectedSavingsFirstBonusPeriod = calculation.calculateProjectedSavingsFirstBonusPeriod( + input, + additionalSavingsThisMonth, + monthLeftInFirstTerm + ) + val highestBalanceFirstBonusPeriod = calculation.calculateHighestBalanceFirstBonusPeriod( + input, + projectedSavingsFirstBonusPeriod + ) val projectedFirstBonus = calculation.calculateProjectedFirstBonus(highestBalanceFirstBonusPeriod) val projectedAdditionalSavingsFinalBonusPeriod = - calculation.calculateProjectedAdditionalSavingsFinalBonusPeriod(input) - val projectedFinalBonus = calculation.calculateProjectedFinalBonus(totalProjectedSavings, - highestBalanceFirstBonusPeriod) - val totalProjectedBonuses = calculation.calculateTotalProjectedBonuses(projectedFirstBonus, - projectedFinalBonus) + calculation.calculateProjectedAdditionalSavingsFinalBonusPeriod(input) + val projectedFinalBonus = calculation.calculateProjectedFinalBonus( + totalProjectedSavings, + highestBalanceFirstBonusPeriod + ) + val totalProjectedBonuses = calculation.calculateTotalProjectedBonuses( + projectedFirstBonus, + projectedFinalBonus + ) val totalProjectedSavingsIncludingBonuses = - calculation.calculateTotalProjectedSavingsIncludeBonuses(totalProjectedSavings, - totalProjectedBonuses) + calculation.calculateTotalProjectedSavingsIncludeBonuses( + totalProjectedSavings, + totalProjectedBonuses + ) return FirstBonusCalculatorResponse( - totalProjectedSavingsIncludingBonuses, - totalProjectedSavings, - totalProjectedBonuses, - projectedSavingsFirstBonusPeriod, - projectedFirstBonus, - projectedAdditionalSavingsFinalBonusPeriod, - projectedFinalBonus + totalProjectedSavingsIncludingBonuses, + totalProjectedSavings, + totalProjectedBonuses, + projectedSavingsFirstBonusPeriod, + projectedFirstBonus, + projectedAdditionalSavingsFinalBonusPeriod, + projectedFinalBonus ) } diff --git a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/models/CalculatorResponse.kt b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/models/CalculatorResponse.kt index a183e7a..4f04f08 100644 --- a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/models/CalculatorResponse.kt +++ b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/models/CalculatorResponse.kt @@ -24,11 +24,11 @@ data class CalculatorResponse( val endOfPeriod2Bonus: Double, val endOfPeriod2Savings: Double ) { - val endOfSchemeBonus: Double = endOfPeriod1Bonus + endOfPeriod2Bonus - val endOfSchemeTotal: Double = endOfSchemeSavings + endOfSchemeBonus - val endOfPeriod1Total: Double = endOfPeriod1Savings + endOfPeriod1Bonus - val endOfPeriod2Total: Double = endOfPeriod2Savings + endOfPeriod2Bonus - } + val endOfSchemeBonus: Double = endOfPeriod1Bonus + endOfPeriod2Bonus + val endOfSchemeTotal: Double = endOfSchemeSavings + endOfSchemeBonus + val endOfPeriod1Total: Double = endOfPeriod1Savings + endOfPeriod1Bonus + val endOfPeriod2Total: Double = endOfPeriod2Savings + endOfPeriod2Bonus +} data class MonthlyBreakdown( val monthNumber: Int, diff --git a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/validation/RegularPaymentValidators.kt b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/validation/RegularPaymentValidators.kt index d3081f7..c48fb7d 100644 --- a/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/validation/RegularPaymentValidators.kt +++ b/src/commonMain/kotlin/uk/gov/hmrc/helptosavecalculator/validation/RegularPaymentValidators.kt @@ -20,7 +20,8 @@ object RegularPaymentValidators { fun isValidRegularPayments(payment: Double) = isBelowMaximumRegularPayments(payment) && isAboveMinimumRegularPayments( - payment) + payment + ) fun isAboveMinimumRegularPayments(payment: Double) = payment >= 1.0 diff --git a/src/commonTest/kotlin/uk/gov/hmrc/CalculatorTest.kt b/src/commonTest/kotlin/uk/gov/hmrc/CalculatorTest.kt index 2889fa7..ff09283 100644 --- a/src/commonTest/kotlin/uk/gov/hmrc/CalculatorTest.kt +++ b/src/commonTest/kotlin/uk/gov/hmrc/CalculatorTest.kt @@ -17,46 +17,54 @@ package uk.gov.hmrc import com.soywiz.klock.DateTime import com.soywiz.klock.MonthSpan -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertFailsWith import uk.gov.hmrc.helptosavecalculator.Calculator import uk.gov.hmrc.helptosavecalculator.exceptions.InvalidRegularPaymentException import uk.gov.hmrc.helptosavecalculator.models.MonthlyBreakdown +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFailsWith class CalculatorTest { @Test fun `Gives list of 48 months with breakdown`() { assertEquals( MonthlyBreakdown(monthNumber = 1, savingsToDate = 50.0, period1Bonus = 25.0, period2Bonus = 0.0), - Calculator.run(regularPayment = 50.0).monthlyBreakdown[0]) + Calculator.run(regularPayment = 50.0).monthlyBreakdown[0] + ) assertEquals(25.0, Calculator.run(regularPayment = 50.0).monthlyBreakdown[0].bonusToDate) assertEquals( MonthlyBreakdown(monthNumber = 2, savingsToDate = 100.0, period1Bonus = 50.0, period2Bonus = 0.0), - Calculator.run(regularPayment = 50.0).monthlyBreakdown[1]) + Calculator.run(regularPayment = 50.0).monthlyBreakdown[1] + ) assertEquals(50.0, Calculator.run(regularPayment = 50.0).monthlyBreakdown[1].bonusToDate) assertEquals( MonthlyBreakdown(monthNumber = 3, savingsToDate = 150.0, period1Bonus = 75.0, period2Bonus = 0.0), - Calculator.run(regularPayment = 50.0).monthlyBreakdown[2]) + Calculator.run(regularPayment = 50.0).monthlyBreakdown[2] + ) assertEquals(50.0, Calculator.run(regularPayment = 50.0).monthlyBreakdown[1].bonusToDate) assertEquals( MonthlyBreakdown(monthNumber = 24, savingsToDate = 1200.0, period1Bonus = 600.0, period2Bonus = 0.0), - Calculator.run(regularPayment = 50.0).monthlyBreakdown[23]) + Calculator.run(regularPayment = 50.0).monthlyBreakdown[23] + ) assertEquals(600.0, Calculator.run(regularPayment = 50.0).monthlyBreakdown[23].bonusToDate) assertEquals( MonthlyBreakdown( - monthNumber = 25, savingsToDate = 1250.0, period1Bonus = 600.0, period2Bonus = 25.0), - Calculator.run(regularPayment = 50.0).monthlyBreakdown[24]) + monthNumber = 25, savingsToDate = 1250.0, period1Bonus = 600.0, period2Bonus = 25.0 + ), + Calculator.run(regularPayment = 50.0).monthlyBreakdown[24] + ) assertEquals(625.0, Calculator.run(regularPayment = 50.0).monthlyBreakdown[24].bonusToDate) assertEquals( MonthlyBreakdown( - monthNumber = 48, savingsToDate = 2400.0, period1Bonus = 600.0, period2Bonus = 600.0), - Calculator.run(regularPayment = 50.0).monthlyBreakdown[47]) + monthNumber = 48, savingsToDate = 2400.0, period1Bonus = 600.0, period2Bonus = 600.0 + ), + Calculator.run(regularPayment = 50.0).monthlyBreakdown[47] + ) assertEquals(1200.0, Calculator.run(regularPayment = 50.0).monthlyBreakdown[47].bonusToDate) } @@ -82,7 +90,9 @@ class CalculatorTest { currentFirstPeriodBonus = 50.0, currentSecondPeriodBonus = 0.0, accountStartDate = DateTime.now().minus( - MonthSpan(2))) + MonthSpan(2) + ) + ) assertEquals(2400.0, calculator.endOfSchemeSavings) assertEquals(1200.0, calculator.endOfSchemeBonus) @@ -105,7 +115,9 @@ class CalculatorTest { currentFirstPeriodBonus = 0.0, currentSecondPeriodBonus = 0.0, accountStartDate = DateTime.now().minus( - MonthSpan(2))) + MonthSpan(2) + ) + ) assertEquals(2300.0, calculator.endOfSchemeSavings) assertEquals(1150.0, calculator.endOfSchemeBonus) assertEquals(3450.0, calculator.endOfSchemeTotal) @@ -126,7 +138,9 @@ class CalculatorTest { currentFirstPeriodBonus = 0.0, currentSecondPeriodBonus = 0.0, accountStartDate = DateTime.now().minus( - MonthSpan(24))) + MonthSpan(24) + ) + ) assertEquals(1800.0, calculator.endOfSchemeTotal) assertEquals(1200.0, calculator.endOfSchemeSavings) assertEquals(600.0, calculator.endOfSchemeBonus) diff --git a/src/commonTest/kotlin/uk/gov/hmrc/FinalBonusTermCalculationTest.kt b/src/commonTest/kotlin/uk/gov/hmrc/FinalBonusTermCalculationTest.kt index b150aae..66ae565 100644 --- a/src/commonTest/kotlin/uk/gov/hmrc/FinalBonusTermCalculationTest.kt +++ b/src/commonTest/kotlin/uk/gov/hmrc/FinalBonusTermCalculationTest.kt @@ -15,25 +15,27 @@ */ package uk.gov.hmrc -import kotlin.test.Test -import kotlin.test.assertEquals import uk.gov.hmrc.helptosavecalculator.FinalBonusTermCalculation import uk.gov.hmrc.helptosavecalculator.models.FinalBonusInput import uk.gov.hmrc.helptosavecalculator.models.FinalBonusStatus import uk.gov.hmrc.helptosavecalculator.models.YearMonthDayInput +import kotlin.test.Test +import kotlin.test.assertEquals class FinalBonusTermCalculationTest { @Test fun `GIVEN regular payment is above paid in this month WHEN calculateAdditionalSavingsThisMonth called THEN return the total`() { - val input = FinalBonusInput(25.0, - 0.0, - 10.0, - 40.0, - YearMonthDayInput(2022, 3), - YearMonthDayInput(2024, 2, 28), - 0.0, - 0.0) + val input = FinalBonusInput( + 25.0, + 0.0, + 10.0, + 40.0, + YearMonthDayInput(2022, 3), + YearMonthDayInput(2024, 2, 28), + 0.0, + 0.0 + ) val calculation = FinalBonusTermCalculation() val result = calculation.calculateAdditionalSavingsThisMonth(input) @@ -42,14 +44,16 @@ class FinalBonusTermCalculationTest { @Test fun `GIVEN regular payment is below paid in this month WHEN calculateAdditionalSavingsThisMonth called THEN return zero`() { - val input = FinalBonusInput(10.0, - 0.0, - 25.0, - 25.0, - YearMonthDayInput(2022, 3), - YearMonthDayInput(2024, 2, 28), - 0.0, - 0.0) + val input = FinalBonusInput( + 10.0, + 0.0, + 25.0, + 25.0, + YearMonthDayInput(2022, 3), + YearMonthDayInput(2024, 2, 28), + 0.0, + 0.0 + ) val calculation = FinalBonusTermCalculation() val result = calculation.calculateAdditionalSavingsThisMonth(input) @@ -68,14 +72,16 @@ class FinalBonusTermCalculationTest { @Test fun `GIVEN calculateTotalProjectedSavings called THEN return the total`() { - val input = FinalBonusInput(10.0, - 0.0, - 25.0, - 25.0, - YearMonthDayInput(2022, 3), - YearMonthDayInput(2024, 2, 28), - 0.0, - 0.0) + val input = FinalBonusInput( + 10.0, + 0.0, + 25.0, + 25.0, + YearMonthDayInput(2022, 3), + YearMonthDayInput(2024, 2, 28), + 0.0, + 0.0 + ) val calculation = FinalBonusTermCalculation() val result = calculation.calculateTotalProjectedSavings(input, 2.0, 10) @@ -84,14 +90,16 @@ class FinalBonusTermCalculationTest { @Test fun `GIVEN highest balance in final term is above highest balance in first term WHEN calculateTotalProjectedBonuses called THEN return the total`() { - val input = FinalBonusInput(10.0, - 0.0, - 25.0, - 25.0, - YearMonthDayInput(2022, 3), - YearMonthDayInput(2024, 2, 28), - 2.0, - 0.0) + val input = FinalBonusInput( + 10.0, + 0.0, + 25.0, + 25.0, + YearMonthDayInput(2022, 3), + YearMonthDayInput(2024, 2, 28), + 2.0, + 0.0 + ) val calculation = FinalBonusTermCalculation() val result = calculation.calculateTotalProjectedBonuses(10.0, input) @@ -100,14 +108,16 @@ class FinalBonusTermCalculationTest { @Test fun `GIVEN highest balance in final term is below highest balance in first term WHEN calculateTotalProjectedBonuses called THEN return zero`() { - val input = FinalBonusInput(10.0, - 0.0, - 25.0, - 25.0, - YearMonthDayInput(2022, 3), - YearMonthDayInput(2024, 2, 28), - 10.0, - 0.0) + val input = FinalBonusInput( + 10.0, + 0.0, + 25.0, + 25.0, + YearMonthDayInput(2022, 3), + YearMonthDayInput(2024, 2, 28), + 10.0, + 0.0 + ) val calculation = FinalBonusTermCalculation() val result = calculation.calculateTotalProjectedBonuses(2.0, input) @@ -116,14 +126,16 @@ class FinalBonusTermCalculationTest { @Test fun `GIVEN calculateMaybeHighestBalanceSoFar called THEN return the total`() { - val input = FinalBonusInput(10.0, - 0.0, - 25.0, - 25.0, - YearMonthDayInput(2022, 3), - YearMonthDayInput(2024, 2, 28), - 10.0, - 5.0) + val input = FinalBonusInput( + 10.0, + 0.0, + 25.0, + 25.0, + YearMonthDayInput(2022, 3), + YearMonthDayInput(2024, 2, 28), + 10.0, + 5.0 + ) val calculation = FinalBonusTermCalculation() val result = calculation.calculateMaybeHighestBalanceSoFar(input) @@ -148,14 +160,16 @@ class FinalBonusTermCalculationTest { @Test fun `GIVEN calculateMonthsLeftInScheme called THEN return the remaining months left in scheme`() { - val input = FinalBonusInput(10.0, - 0.0, - 25.0, - 25.0, - YearMonthDayInput(2023, 3), - YearMonthDayInput(2024, 2, 28), - 10.0, - 5.0) + 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.calculateMonthsLeftInScheme(input) @@ -164,14 +178,16 @@ class FinalBonusTermCalculationTest { @Test fun `GIVEN customer already earned final bonus WHEN finalBonusStatus called THEN return earned`() { - val input = FinalBonusInput(10.0, - 0.0, - 25.0, - 25.0, - YearMonthDayInput(2023, 3), - YearMonthDayInput(2024, 2, 28), - 10.0, - 5.0) + 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) @@ -180,14 +196,16 @@ class FinalBonusTermCalculationTest { @Test fun `GIVEN customer can possibly earn a final bonus WHEN finalBonusStatus called THEN return possibleToEarn`() { - val input = FinalBonusInput(10.0, - 0.0, - 25.0, - 25.0, - YearMonthDayInput(2023, 3), - YearMonthDayInput(2024, 2, 28), - 10.0, - 0.0) + 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) @@ -196,14 +214,16 @@ class FinalBonusTermCalculationTest { @Test fun `GIVEN customer can not earn final bonus WHEN finalBonusStatus called THEN return cannotEarn`() { - val input = FinalBonusInput(50.0, - 0.0, - 0.0, - 25.0, - YearMonthDayInput(2023, 3), - YearMonthDayInput(2024, 2, 28), - 1200.0, - 0.0) + 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) diff --git a/src/commonTest/kotlin/uk/gov/hmrc/FinalBonusTermCalculatorTest.kt b/src/commonTest/kotlin/uk/gov/hmrc/FinalBonusTermCalculatorTest.kt index 9c83334..10b1bc4 100644 --- a/src/commonTest/kotlin/uk/gov/hmrc/FinalBonusTermCalculatorTest.kt +++ b/src/commonTest/kotlin/uk/gov/hmrc/FinalBonusTermCalculatorTest.kt @@ -15,27 +15,29 @@ */ package uk.gov.hmrc -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertFailsWith import uk.gov.hmrc.helptosavecalculator.FinalBonusTermCalculator.runFinalBonusCalculator import uk.gov.hmrc.helptosavecalculator.exceptions.InvalidRegularPaymentException import uk.gov.hmrc.helptosavecalculator.models.FinalBonusInput import uk.gov.hmrc.helptosavecalculator.models.FinalBonusStatus import uk.gov.hmrc.helptosavecalculator.models.YearMonthDayInput +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFailsWith class FinalBonusTermCalculatorTest { @Test fun `GIVEN regular payment is below 1 THEN InvalidRegularPaymentException thrown`() { - val input = FinalBonusInput(0.0, - 0.0, - 10.0, - 40.0, - YearMonthDayInput(2022, 3), - YearMonthDayInput(2024, 2, 28), - 0.0, - 0.0) + val input = FinalBonusInput( + 0.0, + 0.0, + 10.0, + 40.0, + YearMonthDayInput(2022, 3), + YearMonthDayInput(2024, 2, 28), + 0.0, + 0.0 + ) assertFailsWith { runFinalBonusCalculator(input) } @@ -43,14 +45,16 @@ class FinalBonusTermCalculatorTest { @Test fun `GIVEN regular payment is above 50 THEN InvalidRegularPaymentException thrown`() { - val input = FinalBonusInput(51.0, - 0.0, - 10.0, - 40.0, - YearMonthDayInput(2022, 3), - YearMonthDayInput(2024, 2, 28), - 0.0, - 0.0) + val input = FinalBonusInput( + 51.0, + 0.0, + 10.0, + 40.0, + YearMonthDayInput(2022, 3), + YearMonthDayInput(2024, 2, 28), + 0.0, + 0.0 + ) assertFailsWith { runFinalBonusCalculator(input) } @@ -58,14 +62,16 @@ class FinalBonusTermCalculatorTest { @Test fun `GIVEN account just reached final term with no payment WHEN 1 pound regular payment added THEN correct calculation displayed`() { - val input = FinalBonusInput(1.0, - 0.0, - 0.0, - 50.0, - YearMonthDayInput(2022, 3), - YearMonthDayInput(2024, 2, 28), - 0.0, - 0.0) + val input = FinalBonusInput( + 1.0, + 0.0, + 0.0, + 50.0, + YearMonthDayInput(2022, 3), + YearMonthDayInput(2024, 2, 28), + 0.0, + 0.0 + ) val calculator = runFinalBonusCalculator(input) assertEquals(36.0, calculator.totalProjectedSavingsIncludingBonuses) @@ -76,14 +82,16 @@ class FinalBonusTermCalculatorTest { @Test fun `GIVEN account just reached final term with no payment WHEN 25 pound regular payment added THEN correct calculation displayed`() { - val input = FinalBonusInput(25.0, - 0.0, - 0.0, - 50.0, - YearMonthDayInput(2022, 3), - YearMonthDayInput(2024, 2, 28), - 0.0, - 0.0) + val input = FinalBonusInput( + 25.0, + 0.0, + 0.0, + 50.0, + YearMonthDayInput(2022, 3), + YearMonthDayInput(2024, 2, 28), + 0.0, + 0.0 + ) val calculator = runFinalBonusCalculator(input) assertEquals(900.0, calculator.totalProjectedSavingsIncludingBonuses) @@ -94,14 +102,16 @@ class FinalBonusTermCalculatorTest { @Test fun `GIVEN account just reached final term with no payment WHEN 50 pound regular payment added THEN correct calculation displayed`() { - val input = FinalBonusInput(50.0, - 0.0, - 0.0, - 50.0, - YearMonthDayInput(2022, 3), - YearMonthDayInput(2024, 2, 28), - 0.0, - 0.0) + val input = FinalBonusInput( + 50.0, + 0.0, + 0.0, + 50.0, + YearMonthDayInput(2022, 3), + YearMonthDayInput(2024, 2, 28), + 0.0, + 0.0 + ) val calculator = runFinalBonusCalculator(input) assertEquals(1800.0, calculator.totalProjectedSavingsIncludingBonuses) @@ -112,14 +122,16 @@ class FinalBonusTermCalculatorTest { @Test fun `GIVEN account just reached final term with 50 pound paid current month AND withdrawn 25 WHEN 25 pound regular payment added THEN correct calculation displayed`() { - val input = FinalBonusInput(25.0, - 25.0, - 50.0, - 50.0, - YearMonthDayInput(2022, 3), - YearMonthDayInput(2024, 2, 28), - 0.0, - 25.0) + val input = FinalBonusInput( + 25.0, + 25.0, + 50.0, + 50.0, + YearMonthDayInput(2022, 3), + YearMonthDayInput(2024, 2, 28), + 0.0, + 25.0 + ) val calculator = runFinalBonusCalculator(input) assertEquals(900.0, calculator.totalProjectedSavingsIncludingBonuses) @@ -130,14 +142,16 @@ class FinalBonusTermCalculatorTest { @Test fun `GIVEN account can not longer earn final bonus WHEN calculator called THEN can earn final bonus return false`() { - val input = FinalBonusInput(25.0, - 0.0, - 0.0, - 50.0, - YearMonthDayInput(2024, 2), - YearMonthDayInput(2024, 2, 28), - 1200.0, - 0.0) + val input = FinalBonusInput( + 25.0, + 0.0, + 0.0, + 50.0, + YearMonthDayInput(2024, 2), + YearMonthDayInput(2024, 2, 28), + 1200.0, + 0.0 + ) val calculator = runFinalBonusCalculator(input) assertEquals(25.0, calculator.totalProjectedSavingsIncludingBonuses) diff --git a/src/commonTest/kotlin/uk/gov/hmrc/FirstBonusTermCalculationTest.kt b/src/commonTest/kotlin/uk/gov/hmrc/FirstBonusTermCalculationTest.kt index e1e1cb7..7c65886 100644 --- a/src/commonTest/kotlin/uk/gov/hmrc/FirstBonusTermCalculationTest.kt +++ b/src/commonTest/kotlin/uk/gov/hmrc/FirstBonusTermCalculationTest.kt @@ -15,11 +15,11 @@ */ 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 +import kotlin.test.Test +import kotlin.test.assertEquals class FirstBonusTermCalculationTest { @@ -35,13 +35,15 @@ class FirstBonusTermCalculationTest { @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 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) @@ -50,13 +52,15 @@ class FirstBonusTermCalculationTest { @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 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) @@ -65,13 +69,15 @@ class FirstBonusTermCalculationTest { @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 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) @@ -90,13 +96,15 @@ class FirstBonusTermCalculationTest { @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 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) @@ -105,13 +113,15 @@ class FirstBonusTermCalculationTest { @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 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) @@ -120,13 +130,15 @@ class FirstBonusTermCalculationTest { @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 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) @@ -143,13 +155,15 @@ class FirstBonusTermCalculationTest { @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 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) @@ -174,13 +188,15 @@ class FirstBonusTermCalculationTest { @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 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) diff --git a/src/commonTest/kotlin/uk/gov/hmrc/FirstBonusTermCalculatorTest.kt b/src/commonTest/kotlin/uk/gov/hmrc/FirstBonusTermCalculatorTest.kt index fc99ad0..82b3a9d 100644 --- a/src/commonTest/kotlin/uk/gov/hmrc/FirstBonusTermCalculatorTest.kt +++ b/src/commonTest/kotlin/uk/gov/hmrc/FirstBonusTermCalculatorTest.kt @@ -15,24 +15,26 @@ */ package uk.gov.hmrc -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertFailsWith import uk.gov.hmrc.helptosavecalculator.FirstBonusTermCalculator.runFirstBonusCalculator import uk.gov.hmrc.helptosavecalculator.exceptions.InvalidRegularPaymentException import uk.gov.hmrc.helptosavecalculator.models.FirstBonusInput import uk.gov.hmrc.helptosavecalculator.models.YearMonthDayInput +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFailsWith class FirstBonusTermCalculatorTest { @Test 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) + val input = FirstBonusInput( + 0.0, + 0.0, + 0.0, + YearMonthDayInput(2020, 3), + YearMonthDayInput(2022, 2, 28), + YearMonthDayInput(2024, 2, 28), + 0.0 + ) assertFailsWith { runFirstBonusCalculator(input) } @@ -40,13 +42,15 @@ class FirstBonusTermCalculatorTest { @Test 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) + val input = FirstBonusInput( + 51.0, + 0.0, + 0.0, + YearMonthDayInput(2020, 3), + YearMonthDayInput(2022, 2, 28), + YearMonthDayInput(2024, 2, 28), + 0.0 + ) assertFailsWith { runFirstBonusCalculator(input) } @@ -54,13 +58,15 @@ class FirstBonusTermCalculatorTest { @Test 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, - YearMonthDayInput(2020, 3), - YearMonthDayInput(2022, 2, 28), - YearMonthDayInput(2024, 2, 28), - 0.0) + val input = FirstBonusInput( + 1.0, + 0.0, + 0.0, + YearMonthDayInput(2020, 3), + YearMonthDayInput(2022, 2, 28), + YearMonthDayInput(2024, 2, 28), + 0.0 + ) val calculator = runFirstBonusCalculator(input) assertEquals(72.00, calculator.totalProjectedSavingsIncludingBonuses) @@ -74,13 +80,15 @@ class FirstBonusTermCalculatorTest { @Test 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, - YearMonthDayInput(2020, 3), - YearMonthDayInput(2022, 2, 28), - YearMonthDayInput(2024, 2, 28), - 0.0) + val input = FirstBonusInput( + 25.0, + 0.0, + 0.0, + YearMonthDayInput(2020, 3), + YearMonthDayInput(2022, 2, 28), + YearMonthDayInput(2024, 2, 28), + 0.0 + ) val calculator = runFirstBonusCalculator(input) assertEquals(1800.00, calculator.totalProjectedSavingsIncludingBonuses) @@ -94,13 +102,15 @@ class FirstBonusTermCalculatorTest { @Test 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, - YearMonthDayInput(2020, 3), - YearMonthDayInput(2022, 2, 28), - YearMonthDayInput(2024, 2, 28), - 0.0) + val input = FirstBonusInput( + 50.0, + 0.0, + 0.0, + YearMonthDayInput(2020, 3), + YearMonthDayInput(2022, 2, 28), + YearMonthDayInput(2024, 2, 28), + 0.0 + ) val calculator = runFirstBonusCalculator(input) assertEquals(3600.00, calculator.totalProjectedSavingsIncludingBonuses) @@ -114,13 +124,15 @@ class FirstBonusTermCalculatorTest { @Test 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, - YearMonthDayInput(2020, 3), - YearMonthDayInput(2022, 2, 28), - YearMonthDayInput(2024, 2, 28), - 50.0) + val input = FirstBonusInput( + 25.0, + 25.0, + 50.0, + YearMonthDayInput(2020, 3), + YearMonthDayInput(2022, 2, 28), + YearMonthDayInput(2024, 2, 28), + 50.0 + ) val calculator = runFirstBonusCalculator(input) assertEquals(1800.00, calculator.totalProjectedSavingsIncludingBonuses) diff --git a/src/commonTest/kotlin/uk/gov/hmrc/helptosavecalculator/models/CalculatorResponseTest.kt b/src/commonTest/kotlin/uk/gov/hmrc/helptosavecalculator/models/CalculatorResponseTest.kt index 3f2f71a..f22b3b3 100644 --- a/src/commonTest/kotlin/uk/gov/hmrc/helptosavecalculator/models/CalculatorResponseTest.kt +++ b/src/commonTest/kotlin/uk/gov/hmrc/helptosavecalculator/models/CalculatorResponseTest.kt @@ -29,7 +29,8 @@ class CalculatorResponseTest { endOfPeriod1Bonus = 600.0, endOfPeriod1Savings = 1200.0, endOfPeriod2Bonus = 600.0, - endOfPeriod2Savings = 1200.0) + endOfPeriod2Savings = 1200.0 + ) assertEquals(calculatorResponse.endOfSchemeBonus, 1200.0) assertEquals(calculatorResponse.monthlyPayments, 50.0) @@ -49,7 +50,8 @@ class CalculatorResponseTest { @Test fun `Check getters on MonthlyBreakdown`() { val monthlyBreakdown = MonthlyBreakdown( - monthNumber = 1, savingsToDate = 50.0, period1Bonus = 25.0, period2Bonus = 0.0) + monthNumber = 1, savingsToDate = 50.0, period1Bonus = 25.0, period2Bonus = 0.0 + ) // val balance: Int, val secondYearBonus: Double, val fourthYearBonus: Double diff --git a/src/commonTest/kotlin/uk/gov/hmrc/helptosavecalculator/utils/DateTime+MonthsTest.kt b/src/commonTest/kotlin/uk/gov/hmrc/helptosavecalculator/utils/DateTimeMonthsTest.kt similarity index 60% rename from src/commonTest/kotlin/uk/gov/hmrc/helptosavecalculator/utils/DateTime+MonthsTest.kt rename to src/commonTest/kotlin/uk/gov/hmrc/helptosavecalculator/utils/DateTimeMonthsTest.kt index af9db12..975565e 100644 --- a/src/commonTest/kotlin/uk/gov/hmrc/helptosavecalculator/utils/DateTime+MonthsTest.kt +++ b/src/commonTest/kotlin/uk/gov/hmrc/helptosavecalculator/utils/DateTimeMonthsTest.kt @@ -28,36 +28,50 @@ class DateTimeMonthsTest { } @Test - fun `Get Months when comparing 1st Jan, 1st December (previous year)`() { + fun `Get Months when comparing 1st Jan to 1st December of the previous year`() { assertEquals( - 1, DateTime(year = DateTime.now().year.minus(1).year, month = 12, day = 1) // 1st December last year + 1, + DateTime(year = DateTime.now().year.minus(1).year, month = 12, day = 1) // 1st December last year .monthsSince( DateTime( - year = DateTime.now().year.year, month = 1, day = 1))) // 1st Jan this year + year = DateTime.now().year.year, month = 1, day = 1 + ) + ) + ) // 1st Jan this year } @Test - fun `Get Months when comparing 1st Jan, 31st Jan`() { + fun `Get Months when comparing 1st Jan to 31st Jan`() { assertEquals( - 0, DateTime(year = DateTime.now().year.year, month = 1, day = 1) // 1st Jan this year + 0, + DateTime(year = DateTime.now().year.year, month = 1, day = 1) // 1st Jan this year .monthsSince( DateTime( - year = DateTime.now().year.year, month = 1, day = 31))) + year = DateTime.now().year.year, month = 1, day = 31 + ) + ) + ) } @Test - fun `Get Months when comparing 1st Jan, 1st Jan 4 Years later`() { + fun `Get Months when comparing 1st Jan to 1st Jan 4 Years later`() { assertEquals( - 48, DateTime(year = DateTime.now().year.year, month = 1, day = 1) // 1st Jan this year + 48, + DateTime(year = DateTime.now().year.year, month = 1, day = 1) // 1st Jan this year .monthsSince( DateTime( - year = DateTime.now().year.plus(4).year, month = 1, day = 1))) + year = DateTime.now().year.plus(4).year, month = 1, day = 1 + ) + ) + ) } @Test - fun `Get Months when comparing 1st of last month, with now`() { + fun `Get Months when comparing 1st of last month with now`() { assertEquals( - 1, DateTime.now().minus(MonthSpan(1)).startOfMonth - .monthsSince()) + 1, + DateTime.now().minus(MonthSpan(1)).startOfMonth + .monthsSince() + ) } } diff --git a/src/commonTest/kotlin/uk/gov/hmrc/helptosavecalculator/utils/validators/RegularPaymentValidatorsTest.kt b/src/commonTest/kotlin/uk/gov/hmrc/helptosavecalculator/utils/validators/RegularPaymentValidatorsTest.kt index bbf9c9f..88d0b9b 100644 --- a/src/commonTest/kotlin/uk/gov/hmrc/helptosavecalculator/utils/validators/RegularPaymentValidatorsTest.kt +++ b/src/commonTest/kotlin/uk/gov/hmrc/helptosavecalculator/utils/validators/RegularPaymentValidatorsTest.kt @@ -15,12 +15,12 @@ */ package uk.gov.hmrc.helptosavecalculator.utils.validators +import uk.gov.hmrc.helptosavecalculator.validation.RegularPaymentValidators import kotlin.test.Test import kotlin.test.assertFalse import kotlin.test.assertTrue -import uk.gov.hmrc.helptosavecalculator.validation.RegularPaymentValidators -class RegularPaymentValidatorsTests { +class RegularPaymentValidatorsTest { @Test fun `Validate RegularPayments below minimum`() {