ScalaCheck 帮助
我想使用 ScalaTest 的 Checkers 特征来使用 ScalaTest 案例中的 ScalaCheck。
我正在玩的一个简单的例子是:
test("can create local date UTC from millis") {
check(localDate.toTimestampUTC.toLocalDateUTC == localDate)
}
我需要创建一个任意的 LocalDate,所以我尝试了这个:
object ArbitraryValues {
implicit def abc(): Arbitrary[LocalDate] = Arbitrary(Gen.choose(new LocalDate(0L), new LocalDate(Long.MaxValue)))
}
它不会编译,说,
错误:找不到参数 c 的隐式值: org.scalacheck.Choose[org.joda.time.LocalDate] 隐式 val abc: 任意[LocalDate] = 任意(Gen.choose(new LocalDate(0L), new LocalDate(Long.MaxValue)))
和
错误:未找到:值 localDate 检查(localDate.toTimestampUTC.toLocalDateUTC == localDate)
I'd like to use ScalaTest's Checkers trait to use ScalaCheck from ScalaTest cases.
A simple case I'm playing with is:
test("can create local date UTC from millis") {
check(localDate.toTimestampUTC.toLocalDateUTC == localDate)
}
I need to create a arbitrary LocalDate, so I tried this:
object ArbitraryValues {
implicit def abc(): Arbitrary[LocalDate] = Arbitrary(Gen.choose(new LocalDate(0L), new LocalDate(Long.MaxValue)))
}
It doesn't compile, saying,
error: could not find implicit value for parameter c:
org.scalacheck.Choose[org.joda.time.LocalDate] implicit val abc:
Arbitrary[LocalDate] = Arbitrary(Gen.choose(new LocalDate(0L), new
LocalDate(Long.MaxValue)))
and
error: not found: value localDate
check(localDate.toTimestampUTC.toLocalDateUTC == localDate)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,通过反复试验弄清楚了。我的工作代码如下所示:
我必须更改创建 Arbitrary[LocalDate] 的方式,然后更新检查语法。
Ok figured it out through trial and error. My working code looks like this:
I had to change the way I was creating the Arbitrary[LocalDate], and then update my syntax for the check.