Add interest calculation tests from go-luca #2

Open
opened 2026-08-07 14:22:45 +00:00 by hum3 · 0 comments
Owner

Context

As part of the go-luca decomposition, interest computation is moving from go-luca to gobank-products. go-luca will retain the schema (account interest fields, balances_live table) but all interest calculation logic and tests now belong here.

What was removed from go-luca

Code (interest.go)

  • defaultInterest — simple daily: balance * rate / 365
  • InterestResult type
  • EnsureInterestAccounts — create Expense:Interest / Income:Interest accounts
  • computeInterest — dispatch to InterestFunc or default
  • CalculateDailyInterest — one day, one account
  • postInterest — record interest as movement
  • RunDailyInterest — all accounts for one day
  • RunInterestForPeriod — date range

Tests (interest_test.go)

  • TestDailyInterestCalculation — 3.65% on £1000 = 10p/day
  • TestInterestCompounding — 30 days at 10%, verify compound > simple
  • TestZeroRateNoInterest — zero rate returns nil
  • TestRunDailyInterestMultipleAccounts — two accounts, different rates
  • TestSetInterestMethod — set/get method on account
  • TestMethodBackwardCompat — empty method falls back to default
  • TestCustomInterestFunc — pluggable interest function (doubles default)
  • TestInterestFuncWithAccumulator — discrete method with extended-precision accumulator
  • TestRunDailyInterestNoInterestBearingAccounts — no interest accounts = empty results
  • TestIssue1_InterestCrossTimezone — cross-timezone interest regression (issue #1)

Benchmarks

  • BenchmarkInterestNAccounts — N=10/100/1000/10000 accounts
  • BenchmarkCompoundMovementWithProjections — movement + interest + live balance

What gobank-products already has

  • interest.go with InterestAccrual event handler and computeDailyInterest
  • interest_test.go with TestInterestAccrual_SingleDay and TestInterestAccrual_TenDays

TODO

  • Port missing test cases (compounding, zero rate, multi-account, accumulator, backward compat)
  • Port cross-timezone regression test (issue #1)
  • Ensure InterestAccrual covers all go-luca scenarios
  • Add benchmarks for interest at scale

Migrated from Codeberg: originally #2, opened 2026-03-27.

## Context As part of the go-luca decomposition, interest computation is moving from go-luca to gobank-products. go-luca will retain the schema (account interest fields, balances_live table) but all interest calculation logic and tests now belong here. ## What was removed from go-luca ### Code (`interest.go`) - `defaultInterest` — simple daily: balance * rate / 365 - `InterestResult` type - `EnsureInterestAccounts` — create Expense:Interest / Income:Interest accounts - `computeInterest` — dispatch to InterestFunc or default - `CalculateDailyInterest` — one day, one account - `postInterest` — record interest as movement - `RunDailyInterest` — all accounts for one day - `RunInterestForPeriod` — date range ### Tests (`interest_test.go`) - `TestDailyInterestCalculation` — 3.65% on £1000 = 10p/day - `TestInterestCompounding` — 30 days at 10%, verify compound > simple - `TestZeroRateNoInterest` — zero rate returns nil - `TestRunDailyInterestMultipleAccounts` — two accounts, different rates - `TestSetInterestMethod` — set/get method on account - `TestMethodBackwardCompat` — empty method falls back to default - `TestCustomInterestFunc` — pluggable interest function (doubles default) - `TestInterestFuncWithAccumulator` — discrete method with extended-precision accumulator - `TestRunDailyInterestNoInterestBearingAccounts` — no interest accounts = empty results - `TestIssue1_InterestCrossTimezone` — cross-timezone interest regression (issue #1) ### Benchmarks - `BenchmarkInterestNAccounts` — N=10/100/1000/10000 accounts - `BenchmarkCompoundMovementWithProjections` — movement + interest + live balance ## What gobank-products already has - `interest.go` with `InterestAccrual` event handler and `computeDailyInterest` - `interest_test.go` with `TestInterestAccrual_SingleDay` and `TestInterestAccrual_TenDays` ## TODO - [ ] Port missing test cases (compounding, zero rate, multi-account, accumulator, backward compat) - [ ] Port cross-timezone regression test (issue #1) - [ ] Ensure `InterestAccrual` covers all go-luca scenarios - [ ] Add benchmarks for interest at scale --- *Migrated from Codeberg: originally [#2](https://codeberg.org/hum3/gobank-products/issues/2), opened 2026-03-27.*
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
hum3/gobank-products#2
No description provided.