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

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.

主站蜘蛛池模板: 建始县| 津南区| 平武县| 高邑县| 康马县| 仙桃市| 涞水县| 惠东县| 本溪市| 毕节市| 荃湾区| 凌源市| 郑州市| 普安县| 九龙城区| 卓资县| 衢州市| 正安县| 剑阁县| 通海县| 兴海县| 黎城县| 静海县| 繁峙县| 隆德县| 陕西省| 延川县| 绍兴市| 建瓯市| 华安县| 三门县| 洛浦县| 双牌县| 应城市| 安庆市| 女性| 堆龙德庆县| 沾益县| 灵璧县| 潞城市| 新余市|