DEV Community

Cover image for I Found 23 Edge Cases in Personal Debt Tracking — Here's Every Single One
DEVANSHU PATIL
DEVANSHU PATIL

Posted on

I Found 23 Edge Cases in Personal Debt Tracking — Here's Every Single One

I Found 23 Edge Cases in Personal Debt Tracking — Here's Every Single One

If you want to know whether a developer understands financial software, don't look at their user interface.

Look at their test suite.

In personal finance applications, edge cases are not rare anomalies; they are daily realities. People borrow money, repay half of it in cash, transfer the rest via UPI two weeks later, borrow more money before the first loan is settled, or ask you to lend them money by swiping your credit card.

If your code only handles the happy path—one person borrowing once and paying back in full once—your app will crash or corrupt balances within forty-eight hours of hitting the Google Play Store.

In FinLedger, the debt subsystem is guarded by a comprehensive, 436-line test specification: LendingPersonLifecycleTest.kt.

This test suite codifies 23 distinct real-world edge cases (Cases A through X) covering every lifecycle transition, floating-point boundary, and multi-loan aggregation scenario.

Here is a walkthrough of the most critical edge cases in that suite and how they guarantee mathematical truth in FinLedger.

The Edge-Case Matrix (Cases A through X)

flowchart TD
    subgraph TestMatrix["FinLedger Debt Lifecycle Test Matrix"]
        direction TB
        Group1["1. Single Loan Baseline (Cases A - C):
        Principal immutability, outstanding derivation,
        single partial repayment verification."]

        Group2["2. Multi-Loan Aggregation (Cases D - F):
        Multiple active loans per contact, sequential repayment
        allocation, cross-account bank deposits."]

        Group3["3. Boundary Safeguards (Cases G - J):
        Zero-amount rejection, negative input blocking,
        upper-bound ceiling, floating-point half-paisa precision."]

        Group4["4. Bi-Directional Netting (Cases K - N):
        Simultaneous Lent and Borrowed balances, net position
        derivation, multi-cycle 'Lend Again' reactivation."]

        Group5["5. Atomic Sync & Cascades (Cases O - X):
        Companion transaction updates, reverse deletions,
        person directory archival, zero orphaned entities."]

        Group1 --> Group2
        Group2 --> Group3
        Group3 --> Group4
        Group4 --> Group5
    end

Let's dissect four of the most challenging test cases from the suite:

Edge Case 1: Floating-Point Settlement Precision (Case F)

In binary floating-point arithmetic, adding and subtracting fractional currency amounts introduces microscopic rounding artifacts:
950.0 - 100.0 - 200.0 - 650.0 can evaluate to 0.0000000000000001 or -0.0000000000000002 instead of exact zero.

If your settlement check uses exact zero equality:

// The Broken Settlement Check
val isSettled = (outstanding == 0.0) // Evaluates to FALSE due to floating-point drift!
Enter fullscreen mode Exit fullscreen mode

The loan will never mark as settled! The contact remains stuck in the Active view with a phantom balance of Rs. 0.00.

In LendingPersonLifecycleTest.kt, Case F asserts against floating-point boundary tolerances:

  • A balance is classified as fully settled if: abs(lentOutstanding) < 0.001 (less than a tenth of a paisa).
  • This guarantees that micro-precision rounding quirks never prevent a loan from achieving the SETTLED state.

Edge Case 2: Multi-Loan Sequential Repayment (Case D)

Suppose you lend Rahul Rs. 1,000 on June 1, and another Rs. 500 on June 10. Rahul sends you a UPI transfer of Rs. 1,200 labeled "loan repayment".

How should the engine allocate the payment?

  • Does it reduce the first loan to zero and apply the remaining Rs. 200 to the second loan?
  • Or does it reject the payment because Rs. 1,200 is greater than both individual loans?

Case D tests the sequential debt allocation algorithm:

  1. The engine sorts Rahul's active loans chronologically by creation timestamp (FIFO: First-In, First-Out).
  2. The Rs. 1,200 payment applies Rs. 1,000 to settle Loan #1 in full (status = SETTLED).
  3. The remaining Rs. 200 applies automatically to Loan #2, reducing its outstanding balance from Rs. 500 to Rs. 300 (status = PARTIALLY_PAID).
  4. Both loan records preserve their individual repayment receipts with zero ambiguity.

Edge Case 3: Bi-Directional Netting (Case K)

Real life gets messy: you might lend Rahul Rs. 2,000 for groceries, but later that month, Rahul pays for your concert ticket worth Rs. 800.

You now have two concurrent relationships with the same human being:

  • Lent Asset: Rahul owes you Rs. 2,000.
  • Borrowed Liability: You owe Rahul Rs. 800.

What should the UI display?

  • If an app only tracks single-direction numbers, it forces you to calculate the net difference in your head.

Case K asserts the behavior of LendingPersonSummary:

  • It tracks both balances distinctly: totalLentOutstanding = 2,000.0 and totalBorrowedOutstanding = 800.0.
  • It derives the net position: netOutstanding = +1,200.0 (Rahul owes you Rs. 1,200 net).
  • It allows a single one-tap action: "Net Settle", which cancels the mutual Rs. 800 liability atomically, leaving a single clean Rs. 1,200 asset.

Edge Case 4: Companion Transaction Deletion Rollback (Case P)

If you delete a companion repayment deposit from your main checking account transaction feed, what happens to the debt record?

Case P asserts that deleting the bank transaction:

  1. Reverses the bank balance.
  2. Removes the linked LendingRepaymentEntity.
  3. Recalculates the loan's outstanding balance, restoring the borrower's debt to its pre-repayment state.
  4. Asserts that zero orphaned records remain in either table.

Key Takeaway

Writing 23 exhaustive test cases before shipping a feature is not an academic exercise; it is the only way to build trustworthy financial software.

By proving that our domain models handle floating-point precision, sequential repayments, bi-directional netting, and cascading rollbacks with mathematical perfection, LendingPersonLifecycleTest.kt ensures that FinLedger never lets you down when managing real-world money.


FinLedger is a privacy-first, offline-first personal finance application for Android that models bank accounts, credit cards, and cash without double-counting.

Explore FinLedger on Google Play: https://play.google.com/store/apps/details?id=com.devanshufinance.app

Top comments (1)

Collapse
 
marcusykim profile image
Marcus Kim •

In Case F, 950.0 - 100.0 - 200.0 - 650.0 comes out to exactly zero, so even outstanding == 0.0 would pass. Try a 30-paise loan with two repayments: 10 paise, then 20. With Double, 0.30 - 0.10 - 0.20 leaves a tiny remainder. Make the same two repayments on a 31-paise loan. The first loan should close; the second should still show one paisa owed.