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

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.

主站蜘蛛池模板: 辽源市| 克拉玛依市| 开平市| 若尔盖县| 纳雍县| 白河县| 清水县| 子洲县| 邹城市| 通城县| 梅河口市| 峨山| 伊金霍洛旗| 武强县| 射洪县| 黑河市| 深圳市| 车致| 平南县| 梨树县| 驻马店市| 石河子市| 铁岭县| 曲阳县| 姚安县| 翁牛特旗| 新密市| 金沙县| 临洮县| 宝山区| 定兴县| 满城县| 西藏| 沧州市| 太白县| 棋牌| 巴楚县| 岳普湖县| 潞城市| 图木舒克市| 开平市|