ScalaTest - testing equality between two floating point arrays with error margin

Well as I feared there is no nice syntax in ScalaTest for this, and I will accept my own answer with a very basic solution.

val Eps = 1e-3 // Our epsilon

val res = testObject.test // Result you want to test.
val expected = Array(...) // Expected returning value.

res.size should be (expected.size)

for (i <- 0 until res.size) res(i) should be (expected(i) +- Eps)

As seen, this works. Then you can make it nicer by perhaps defining an implicit method.


How about:

 import Inspectors._
 import scala.math._

 forExactly(max(a1.size, a2.size), a1.zip(a2)){case (x, y) => x shouldBe (y +- eps)}

Or you can provide custom equality (there is a built-in one as @Suma sugested)