Question

I am porting some Junit tests(for Java code) into Scalacheck. One of the Junit tests is using

http://junit.sourceforge.net/javadoc/org/junit/Assert.html#assertEquals(double, double, double)

Now when I write Scalacheck property for the same is there a way to provide delta how Junit API offers?

Was it helpful?

Solution

Comparing doubles sucks :). Here is how ScalaTest helps you with it:

import org.scalatest._

class MyTest extends FlatSpec with ShouldMatchers {

  ...

  100.0 should be (100.0 plusOrMinus 1e-9)

  ...
}

An alternative for plusOrMinus is +- method.

OTHER TIPS

ScalaTest works nicely with ScalaCheck, and the matcher I think you're looking for is at http://www.scalatest.org/user_guide/using_matchers#checkingNumbersAgainstARange

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top