加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Scalatest’DoubleTolerance’中的一个错误?

发布时间:2020-12-16 09:49:00 所属栏目:安全 来源:网络整理
导读:我遇到了失败的测试,在我的所有理解中都应该通过.我错过了一些明显的东西吗? 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-
我遇到了失败的测试,在我的所有理解中都应该通过.我错过了一些明显的东西吗?

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上都经历过这种情况.

解决方法

问题:必须使用,不等于.

离开这里是我愚蠢的表现(恍惚,缺乏专注).

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)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读