官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 错那县| 金乡县| 阳西县| 左贡县| 宁波市| 廊坊市| 信阳市| 兰州市| 灌云县| 钦州市| 轮台县| 汽车| 巢湖市| 河间市| 藁城市| 罗平县| 永平县| 邵阳县| 商河县| 凤山县| 微山县| 邹平县| 南陵县| 徐汇区| 耿马| 子长县| 长宁县| 唐河县| 肃宁县| 大竹县| 海南省| 汝州市| 湟中县| 湘潭县| 聊城市| 精河县| 澜沧| 安福县| 中宁县| 涡阳县| 东丽区|