【发布时间】:2019-10-28 13:55:39
【问题描述】:
在原版 Scala 中,以下断言通过
assert(1D > 0F)
assert(1F > 0)
assert(1L > 0)
assert(1 > 0.toShort)
assert(1.toShort > 0.toChar)
然而 ScalaTest 中的类似匹配器 fail
1D shouldBe > (0F)
1F shouldBe > (0)
1L shouldBe > (0)
1 shouldBe > (0.toShort)
1.toShort shouldBe > (0.toChar)
一种解决方法是让两边的类型相同,例如
1D shouldBe > (0D)
为什么它在 Scala 中有效,但在 Scalatest 中无效,或者> 的签名是什么原因
def >[T : Ordering] (right: T): ResultOfGreaterThanComparison[T]
这让它失败了?
【问题讨论】:
-
有趣的是,
1D should be > 0D有效,而1D should be > 0F不编译
标签: scala scalatest matcher comparison-operators