문제

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