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?

有帮助吗?

解决方案

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.

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top