這是我到目前爲止已經試過:如何比較使用Scalatest相等類型的Double列表?
implicit val doubleEq = TolerantNumerics.tolerantDoubleEquality(0.1)
implicit val listEq = new Equivalence[List[Double]] {
override def areEquivalent(a: List[Double], b: List[Double]): Boolean = {
(a, b) match {
case (Nil, Nil) => true
case (x :: xs, y :: ys) => x === y && areEquivalent(xs, ys)
case _ => false
}
}
}
第一斷言成功,但第二個失敗:
assert(1.0 === 1.01)
assert(List(1.0) === List(1.01))
有沒有辦法有收藏使用我爲定義的implicits他們的元素呢?