- Scala Programming Projects
- Mikael Valot Nicolas Jorand
- 279字
- 2021-07-23 16:25:19
Writing a test for the decumulation phase
Now you know how much capital you can expect at your retirement date. It turns out you can reuse the same futureCapital function, to work out how much capital will be left for your heirs.
Add the following test in RetCalcSpec, underneath the previous unit test, and run it. It should pass:
"RetCalc.futureCapital" should {
"calculate how much savings will be left after having taken a pension
for n months" in {
val actual = RetCalc.futureCapital(
interestRate = 0.04/12, nbOfMonths = 40 * 12,
netIncome = 0, currentExpenses = 2000, initialCapital =
541267.1990)
val expected = 309867.53176
actual should ===(expected)
}
}
So, if you live for 40 years after your retirement date, spend the same amount every month, and don't have any other income, you will still have a significant capital left for your heirs. If the remaining capital was negative, that would have meant that you would have run out of money at some point during your retirement and it is an outcome we want to avoid.
Feel free to call the function from the Scala Console and try different values that would match more closely to your personal situation. Try different values for the interest rate and observe how you can end up with a negative capital if the rate is low.
Note that, in a production system, you would certainly add more unit tests to cover some other edge cases and make sure that the function will not crash. As we will cover error handling in Chapter 3, Handling Errors, we can assume that the test coverage of futureCapital is good enough for now.
- 物聯(lián)網(wǎng)+BIM:構(gòu)建數(shù)字孿生的未來
- Go Web Scraping Quick Start Guide
- 互聯(lián)網(wǎng)安全的40個(gè)智慧洞見:2015年中國互聯(lián)網(wǎng)安全大會(huì)文集
- NB-IoT物聯(lián)網(wǎng)技術(shù)解析與案例詳解
- 計(jì)算機(jī)網(wǎng)絡(luò)原理與應(yīng)用技術(shù)
- 物聯(lián)網(wǎng)長距離無線通信技術(shù)應(yīng)用與開發(fā)
- 網(wǎng)絡(luò)基礎(chǔ)與網(wǎng)絡(luò)管理項(xiàng)目化教程
- 夢(mèng)工廠之材質(zhì)N次方:Maya材質(zhì)手冊(cè)
- Learning Windows 8 Game Development
- 網(wǎng)絡(luò)AI+:2030后的未來網(wǎng)絡(luò)
- 一本書讀懂物聯(lián)網(wǎng)
- 移動(dòng)物聯(lián)網(wǎng):商業(yè)模式+案例分析+應(yīng)用實(shí)戰(zhàn)
- 移動(dòng)互聯(lián)網(wǎng)新思維
- 現(xiàn)場(chǎng)綜合化網(wǎng)絡(luò)運(yùn)營與維護(hù):運(yùn)營商數(shù)字化轉(zhuǎn)型技術(shù)與實(shí)踐
- RestKit for iOS