- Scala Programming Projects
- Mikael Valot Nicolas Jorand
- 125字
- 2021-07-23 16:25:20
Writing a failing test for nbOfMonthsSaving
As usual, let's start with a new unit test to clarify what we expect from this function:
"RetCalc.nbOfMonthsSaving" should {
"calculate how long I need to save before I can retire" in {
val actual = RetCalc.nbOfMonthsSaving(
interestRate = 0.04 / 12, nbOfMonthsInRetirement = 40 * 12,
netIncome = 3000, currentExpenses = 2000, initialCapital = 10000)
val expected = 23 * 12 + 1
actual should ===(expected)
}
}
In this test, the expected value can be a bit difficult to figure out. One way would be to use the NPM function in Excel. Alternatively, you could call simulatePlan many times in the Scala Console, and increase nbOfMonthsSaving to gradually find out what the optimal value is.
推薦閱讀
- 物聯(lián)網(wǎng)工程規(guī)劃技術(shù)
- 智能網(wǎng)聯(lián)汽車V2X與智能網(wǎng)聯(lián)設(shè)施I2X
- Hands-On Industrial Internet of Things
- 6G新技術(shù) 新網(wǎng)絡(luò) 新通信
- Mastering Dart
- INSTANT KineticJS Starter
- 光纖通信系統(tǒng)與網(wǎng)絡(luò)(修訂版)
- 網(wǎng)絡(luò)安全應(yīng)急響應(yīng)技術(shù)實(shí)戰(zhàn)指南
- 無(wú)線傳感器網(wǎng)絡(luò)定位技術(shù)
- 物聯(lián)網(wǎng)基礎(chǔ)及應(yīng)用
- 物聯(lián)網(wǎng)
- Hands-On Reactive Programming in Spring 5
- 黑客與反黑工具使用詳解
- 智能物聯(lián)安防視頻技術(shù)基礎(chǔ)與應(yīng)用
- OSPF協(xié)議原理與功能拓展