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

Writing a failing unit test

Here is the unit test you need to add to RetCalcSpec:

"RetCalc.simulatePlan" should {
"calculate the capital at retirement and the capital after death" in {
val (capitalAtRetirement, capitalAfterDeath) =
RetCalc.simulatePlan(
interestRate = 0.04 / 12,
nbOfMonthsSaving = 25 * 12, nbOfMonthsInRetirement = 40 * 12,
netIncome = 3000, currentExpenses = 2000,
initialCapital = 10000)
capitalAtRetirement should === (541267.1990)
capitalAfterDeath should === (309867.5316)
}
}

Select the call to simulatePlan, and hit Alt + Enter to let IntelliJ create the function for you in RetCalc. It should have the following signature:

def simulatePlan(interestRate: Double,
nbOfMonthsSavings: Int, nbOfMonthsInRetirement: Int,
netIncome: Int, currentExpenses: Int, initialCapital:
Double) : (Double, Double) = ???

Now compile the project with cmd + F9, and run RetCalcSpec. It should fail since the simulatePlan function must return two values. The simplest way of modeling the return type is to use Tuple2. In Scala, a tuple is an immutable data structure which holds several objects of different types. The number of objects contained in a tuple is fixed. It is akin to a case class, which does not have specific names for its attributes. In type theory, we say that a tuple or a case class is a product type.

主站蜘蛛池模板: 河间市| 墨竹工卡县| 昌宁县| 横峰县| 湖北省| 南康市| 万年县| 偏关县| 扎赉特旗| 云和县| 浦江县| 准格尔旗| 株洲市| 江山市| 广丰县| 永州市| 大石桥市| 当涂县| 辽源市| 新宾| 三明市| 莎车县| 德保县| 东港市| 门源| 鹿邑县| 天气| 衡东县| 称多县| 潜江市| 伊宁市| 高阳县| 崇左市| 怀仁县| 新蔡县| 镇原县| 夹江县| 廊坊市| 左权县| 灵丘县| 郯城县|