【发布时间】:2017-01-24 16:10:43
【问题描述】:
我有一个嵌套的 forAll 调用,它取决于前一个生成的值。根据生成器的定义,该值是一个不应为空的集合:
"test" in {
val listGen: Gen[List[Int]] = Gen.listOfN(3, Gen.choose(0, 100))
def intGen(list: List[Int]) = Gen.oneOf(list)
implicit val arbList = Arbitrary(listGen)
forAll { list: List[Int] =>
forAll(intGen(list)) { int =>
true should be(false)
}
}
}
而不是产生诸如“真不是假”之类的错误消息,这给了我:
IllegalArgumentException was thrown during property evaluation.
Message: oneOf called on empty collection
Occurred when passed generated values (
arg0 = List() // 2 shrinks
)
我不知道为什么。这不是我期望(或理解)的测试失败消息...
如果我打印出生成的列表和整数,我会得到以下奇怪的输出:
List(72, 77, 8)
8
4
2
1
0
List(72)
72
36
18
9
4
2
1
0
List()
由于列表被截断,属性失败时整数被二除(但根据生成器定义,列表的大小应始终为 3!)
我正在使用 Scala 2.12.1,scalatest 3.0.1 abd scalacheck 1.13.4。
谢谢!
【问题讨论】:
标签: scala scalatest scalacheck