scala - Scalatest 'DoubleTolerance' 中的错误?

标签 scala scalatest

我遇到过失败的测试,据我所知,这些测试都应该通过。我在这里遗漏了一些明显的东西吗?

import org.scalatest._

class xxxTests extends FlatSpec with ShouldMatchers {
  import math.{Pi => PI}

  "" should "(this should pass)" in {
    assert( 0.0 === 0.0 )  // ok

    (1e-100) should equal ((0.0) plusOrMinus 1e-5)    // FAILS!!!  "1.0E-100 did not equal DoubleTolerance(0.0,1.0E-5)"
    (1e-3) should not equal ((0.0) plusOrMinus 1e-5)    // ok
    (0.0) should equal ((0.0) plusOrMinus 1e-5)    // FAILS!!!  "0.0 did not equal DoubleTolerance(0.0,1.0E-5)"
  }
}

我在 Scalatest 1.8 和 2.0M4 上都经历过这种情况。

最佳答案

问题:必须使用be ,不是 equal .

离开这里是我愚蠢的标志(嗯,注意力不集中)。

https://groups.google.com/forum/?fromgroups=#!msg/scalatest-users/pb54GzOej6I/C9714h_OW_UJ

You must use plusOrMinus with "be" not "equal". "equal" always compares for equality by invoking == on one object, passing in the other. "be" does different things depending on what object is being passed. So try:

0.5 must be (0.5 plusOrMinus 0.1)

关于scala - Scalatest 'DoubleTolerance' 中的错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12970246/

相关文章:

scala - 在 scala 中递归构建列表的挑战

scala - 拒绝理解

ScalaTest afterAll() 在每次测试后被调用

Scalatest:组合断言

bdd - ScalaTest 和 Spock 的比较

java - 为什么 VisualVM Profiler 不能分析我的 Scala 控制台应用程序?

scala - 从 scala 2.8.1 到 scala 2.9.1 的主要变化是什么?

scala - 是否需要为 Scala 2.10 上导出的宏库导出 Quasiquotes 依赖项?

scala - 对 ScalaTest 中 beforeAll 构造的用处有点困惑

ruby - 如何配置 Buildr 以运行 ScalaTest 2.11?