I am trying to execute the below code in intellij and getting error. Please help
code
package retcalc
object RetCalc extends App {
def futureCapital(interestRate: Double, nbOfMonths: Int, netIncome: Int, currentExpenses:
Int, initialCapital: Double): Double = {
val monthlySavings = netIncome - currentExpenses
def nextCapital(accumulated: Double, month: Int): Double =
accumulated * (1 + interestRate) + monthlySavings
(0 until nbOfMonths).foldLeft(initialCapital)(nextCapital)
}
}
Test Case
package retcalc
import org.scalactic.{Equality, TolerantNumerics, TypeCheckedTripleEquals}
import org.scalatest.{Matchers, WordSpec}
class RetCalcSpec extends WordSpec with Matchers with TypeCheckedTripleEquals {
implicit val doubleEquality: Equality[Double] =
TolerantNumerics.tolerantDoubleEquality(0.0001)
"RetCalc.futureCapital" should {
"calculate the amount of savings I will have in n months" in {
val actual = RetCalc.futureCapital(
interestRate = 0.04 / 12, nbOfMonths = 25 * 12,
netIncome = 3000, currentExpenses = 2000,
initialCapital = 10000)
val expected = 541267.1990
actual should ===(expected)
}
}
}
Error
overloaded method should with alternatives:
(inv: org.scalautils.TripleEqualsInvocationOnInterval[Double])Unit <and>
[U](inv: org.scalautils.TripleEqualsInvocation[U])(implicit constraint: org.scalautils.EqualityConstraint[Double,U]): Unit <and>
(notWord: RetCalcSpec.this.NotWord)RetCalcSpec.this.ResultOfNotWordForNumeric[Double] <and>
(rightMatcherGen1: RetCalcSpec.this.MatcherGen1[Double,org.scalautils.Equality])(implicit equality: org.scalautils.Equality[Double]): Unit <and>
(rightMatcherX3: org.scalatest.matchers.Matcher[Double])Unit
cannot be applied to (org.scalactic.TripleEqualsSupport.TripleEqualsInvocation[Double])
actual should ===(expected)
----scalaVersion := "2.13.6"----