Handling Doubles in ScalaTest

半城伤御伤魂 提交于 2019-11-29 13:50:51
Spiro Michaylov

It looks to me like you've got an implicit instance of Equality[Double] in scope along the lines of org.scalactic.TolerantNumerics, for which the documentation is here.

The example from the doc is:

implicit val doubleEquality = TolerantNumerics.tolerantDoubleEquality(0.01)

But it looks like somebody has instantiated it with a really big tolerance value in your case.

You may also consider trying explicit tolerance by using +-:

assert(x.price() === 185.92 +- 0.01)

You can simply do actual shouldBe (expected +- tolerance) if using FlatSpec; other specs have similar matchers instead of shouldBe. It gives better messages in case of failures than assert, and the code is consistent with the other tests.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!