gpt4 book ai didi

scala - Scalatest 'DoubleTolerance' 中的错误?

转载 作者:行者123 更新时间:2023-12-04 17:52:58 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com