September 2018
Intermediate to advanced
398 pages
9h 43m
English
We are not quite done yet because our function might loop indefinitely. Imagine that you always spend more than what you earn. You will never be able to save enough to retire, even if you live a million years! Here is a unit test highlighting this:
"RetCalc.nbOfMonthsSaving" should { "calculate how long I need to save before I can retire" in {...} "not crash if the resulting nbOfMonths is very high" in {...} "not loop forever if I enter bad parameters" in { val actual = RetCalc.nbOfMonthsSavingV2( interestRate = 0.04 / 12, nbOfMonthsInRetirement = 40 * 12, netIncome = 1000, currentExpenses = 2000, initialCapital = 10000) actual should === (Int.MaxValue) }}
We decided to use a special value Int.MaxValue to indicate that ...
Read now
Unlock full access