Skip to content

Commit

Permalink
new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simontreanor committed Nov 15, 2024
1 parent ccdb53d commit e42a470
Showing 1 changed file with 93 additions and 28 deletions.
121 changes: 93 additions & 28 deletions tests/ComplianceTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -225,17 +225,17 @@ module ComplianceTests =
MaxDuration = Duration.Unlimited
}
Parameters.PaymentConfig.PaymentRounding = RoundUp
InterestConfig.StandardRate = Interest.Rate.Daily <| Percent 2m
InterestConfig.StandardRate = Interest.Rate.Daily <| Percent 1.2m
InterestConfig.Cap = Interest.Cap.zero
}

[<Fact>]
let ``Example 3.1) Repayments made on time - no interest cap`` () =
let actualPayments = Map [
17<OffsetDay>, [| ActualPayment.quickConfirmed 372_78L<Cent> |]
48<OffsetDay>, [| ActualPayment.quickConfirmed 372_78L<Cent> |]
76<OffsetDay>, [| ActualPayment.quickConfirmed 372_78L<Cent> |]
107<OffsetDay>, [| ActualPayment.quickConfirmed 372_78L<Cent> |]
17<OffsetDay>, [| ActualPayment.quickConfirmed 263_51L<Cent> |]
48<OffsetDay>, [| ActualPayment.quickConfirmed 263_51L<Cent> |]
76<OffsetDay>, [| ActualPayment.quickConfirmed 263_51L<Cent> |]
107<OffsetDay>, [| ActualPayment.quickConfirmed 263_48L<Cent> |]
]

let schedule =
Expand All @@ -250,10 +250,10 @@ module ComplianceTests =
[<Fact>]
let ``Example 3.2) Early repayment - no interest cap`` () =
let actualPayments = Map [
17<OffsetDay>, [| ActualPayment.quickConfirmed 372_78L<Cent> |]
48<OffsetDay>, [| ActualPayment.quickConfirmed 372_78L<Cent> |]
63<OffsetDay>, [| ActualPayment.quickConfirmed 372_78L<Cent> |]
91<OffsetDay>, [| ActualPayment.quickConfirmed 220_41L<Cent> |]
17<OffsetDay>, [| ActualPayment.quickConfirmed 263_51L<Cent> |]
48<OffsetDay>, [| ActualPayment.quickConfirmed 263_51L<Cent> |]
63<OffsetDay>, [| ActualPayment.quickConfirmed 263_51L<Cent> |]
91<OffsetDay>, [| ActualPayment.quickConfirmed 175_99L<Cent> |]
]

let schedule =
Expand All @@ -268,10 +268,10 @@ module ComplianceTests =
[<Fact>]
let ``Example 3.3) Late repayment - no interest cap`` () =
let actualPayments = Map [
17<OffsetDay>, [| ActualPayment.quickConfirmed 372_78L<Cent> |]
48<OffsetDay>, [| ActualPayment.quickConfirmed 372_78L<Cent> |]
76<OffsetDay>, [| ActualPayment.quickConfirmed 372_78L<Cent> |]
122<OffsetDay>, [| ActualPayment.quickConfirmed 484_61L<Cent> |]
17<OffsetDay>, [| ActualPayment.quickConfirmed 263_51L<Cent> |]
48<OffsetDay>, [| ActualPayment.quickConfirmed 263_51L<Cent> |]
76<OffsetDay>, [| ActualPayment.quickConfirmed 263_51L<Cent> |]
122<OffsetDay>, [| ActualPayment.quickConfirmed 310_90L<Cent> |]
]

let schedule =
Expand Down Expand Up @@ -348,12 +348,12 @@ module ComplianceTests =
}

[<Fact>]
let ``Example 5.1) Repayments made on time - 100% total interest cap`` () =
let ``Example 5.1) Repayments made on time - 100% total interest cap - autogenerated schedule`` () =
let actualPayments = Map [
17<OffsetDay>, [| ActualPayment.quickConfirmed 245_00L<Cent> |]
48<OffsetDay>, [| ActualPayment.quickConfirmed 245_00L<Cent> |]
76<OffsetDay>, [| ActualPayment.quickConfirmed 245_00L<Cent> |]
107<OffsetDay>, [| ActualPayment.quickConfirmed 245_00L<Cent> |]
17<OffsetDay>, [| ActualPayment.quickConfirmed 243_99L<Cent> |]
48<OffsetDay>, [| ActualPayment.quickConfirmed 243_99L<Cent> |]
76<OffsetDay>, [| ActualPayment.quickConfirmed 243_99L<Cent> |]
107<OffsetDay>, [| ActualPayment.quickConfirmed 243_99L<Cent> |]
]

let schedule =
Expand All @@ -366,12 +366,12 @@ module ComplianceTests =
principalBalance |> should equal 0L<Cent>

[<Fact>]
let ``Example 5.2) Early repayment - 100% total interest cap`` () =
let ``Example 5.2) Early repayment - 100% total interest cap - autogenerated schedule`` () =
let actualPayments = Map [
17<OffsetDay>, [| ActualPayment.quickConfirmed 245_00L<Cent> |]
48<OffsetDay>, [| ActualPayment.quickConfirmed 245_00L<Cent> |]
63<OffsetDay>, [| ActualPayment.quickConfirmed 245_00L<Cent> |]
91<OffsetDay>, [| ActualPayment.quickConfirmed 245_00L<Cent> |]
17<OffsetDay>, [| ActualPayment.quickConfirmed 243_99L<Cent> |]
48<OffsetDay>, [| ActualPayment.quickConfirmed 243_99L<Cent> |]
63<OffsetDay>, [| ActualPayment.quickConfirmed 243_99L<Cent> |]
91<OffsetDay>, [| ActualPayment.quickConfirmed 243_99L<Cent> |]
]

let schedule =
Expand All @@ -384,12 +384,12 @@ module ComplianceTests =
principalBalance |> should equal 0L<Cent>

[<Fact>]
let ``Example 5.3) Late repayment - 100% total interest cap`` () =
let ``Example 5.3) Late repayment - 100% total interest cap - autogenerated schedule`` () =
let actualPayments = Map [
17<OffsetDay>, [| ActualPayment.quickConfirmed 245_00L<Cent> |]
48<OffsetDay>, [| ActualPayment.quickConfirmed 245_00L<Cent> |]
76<OffsetDay>, [| ActualPayment.quickConfirmed 245_00L<Cent> |]
122<OffsetDay>, [| ActualPayment.quickConfirmed 245_00L<Cent> |]
17<OffsetDay>, [| ActualPayment.quickConfirmed 243_99L<Cent> |]
48<OffsetDay>, [| ActualPayment.quickConfirmed 243_99L<Cent> |]
76<OffsetDay>, [| ActualPayment.quickConfirmed 243_99L<Cent> |]
122<OffsetDay>, [| ActualPayment.quickConfirmed 243_99L<Cent> |]
]

let schedule =
Expand All @@ -401,3 +401,68 @@ module ComplianceTests =
let principalBalance = schedule.ScheduleItems |> Map.maxKeyValue |> snd |> _.PrincipalBalance
principalBalance |> should equal 0L<Cent>

let scheduleParameters6 =
{ scheduleParameters5 with
ScheduleConfig =
CustomSchedule <| Map [
17<OffsetDay>, ScheduledPayment.quick (ValueSome 250_00L<Cent>) ValueNone
48<OffsetDay>, ScheduledPayment.quick (ValueSome 250_00L<Cent>) ValueNone
76<OffsetDay>, ScheduledPayment.quick (ValueSome 250_00L<Cent>) ValueNone
107<OffsetDay>, ScheduledPayment.quick (ValueSome 250_00L<Cent>) ValueNone
]
}

[<Fact>]
let ``Example 6.1) Repayments made on time - 100% total interest cap - custom schedule`` () =
let actualPayments = Map [
17<OffsetDay>, [| ActualPayment.quickConfirmed 250_00L<Cent> |]
48<OffsetDay>, [| ActualPayment.quickConfirmed 250_00L<Cent> |]
76<OffsetDay>, [| ActualPayment.quickConfirmed 250_00L<Cent> |]
107<OffsetDay>, [| ActualPayment.quickConfirmed 250_00L<Cent> |]
]

let schedule =
actualPayments
|> Amortisation.generate scheduleParameters6 ValueNone false

schedule.ScheduleItems |> outputMapToHtml "out/ComplianceTest6.1.md" false

let principalBalance = schedule.ScheduleItems |> Map.maxKeyValue |> snd |> _.PrincipalBalance
principalBalance |> should equal 0L<Cent>

[<Fact>]
let ``Example 6.2) Early repayment - 100% total interest cap - custom schedule`` () =
let actualPayments = Map [
17<OffsetDay>, [| ActualPayment.quickConfirmed 250_00L<Cent> |]
48<OffsetDay>, [| ActualPayment.quickConfirmed 250_00L<Cent> |]
63<OffsetDay>, [| ActualPayment.quickConfirmed 250_00L<Cent> |]
91<OffsetDay>, [| ActualPayment.quickConfirmed 198_34L<Cent> |]
]

let schedule =
actualPayments
|> Amortisation.generate scheduleParameters6 ValueNone false

schedule.ScheduleItems |> outputMapToHtml "out/ComplianceTest6.2.md" false

let principalBalance = schedule.ScheduleItems |> Map.maxKeyValue |> snd |> _.PrincipalBalance
principalBalance |> should equal 0L<Cent>

[<Fact>]
let ``Example 6.3) Late repayment - 100% total interest cap - custom schedule`` () =
let actualPayments = Map [
17<OffsetDay>, [| ActualPayment.quickConfirmed 250_00L<Cent> |]
48<OffsetDay>, [| ActualPayment.quickConfirmed 250_00L<Cent> |]
76<OffsetDay>, [| ActualPayment.quickConfirmed 250_00L<Cent> |]
122<OffsetDay>, [| ActualPayment.quickConfirmed 250_00L<Cent> |]
]

let schedule =
actualPayments
|> Amortisation.generate scheduleParameters6 ValueNone false

schedule.ScheduleItems |> outputMapToHtml "out/ComplianceTest6.3.md" false

let principalBalance = schedule.ScheduleItems |> Map.maxKeyValue |> snd |> _.PrincipalBalance
principalBalance |> should equal 0L<Cent>

0 comments on commit e42a470

Please sign in to comment.