在 scalacheck 属性中使用规范匹配器

发布于 2024-09-28 13:57:29 字数 390 浏览 2 评论 0原文

我正在尝试在 scalacheck 属性中使用规格数学。例如,我有一个像这样工作的匹配器:

x must matchMyMatcher(y)

当我想在 scalacheck 属性中使用此匹配器时,我会执行以下操作:

import org.scalacheck._
import org.specs._
...
val prop = Prop.forAll(myGen){
    (x,y) => new matchMyMatcher(x)(y)._1
}
prop must pass

不幸的是,在这种情况下,我删除了我放入匹配器中的调试信息以及属性时需要的调试信息失败了。 在 props 中使用匹配器是否有规定的方法?

I'm trying to use specs mathers inside scalacheck properties. For example, I have a matcher that works like this:

x must matchMyMatcher(y)

When I want to use this matcher inside scalacheck property, I do the following:

import org.scalacheck._
import org.specs._
...
val prop = Prop.forAll(myGen){
    (x,y) => new matchMyMatcher(x)(y)._1
}
prop must pass

Unfortunately, in this case I have erasure of debug information that I putted in matcher and that I need when property fails.
Is there a stipulated way to use matchers inside props?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

や三分注定 2024-10-05 13:57:30

如果您在匹配器中使用“must”,您将收到正确的失败消息:

val gen = Gen.oneOf(("a", "a"), ("b", "b2"))
val function = (pair: (String, String)) => pair._1 must myMatcher(pair._2)
gen must pass(function)

然后,在这种情况下,您的示例应该失败并

显示: >反例是 '(b,b2)':'b' 不等于 'b2'(0 次尝试后)

You will get the proper failure message if you use "must" with your matcher:

val gen = Gen.oneOf(("a", "a"), ("b", "b2"))
val function = (pair: (String, String)) => pair._1 must myMatcher(pair._2)
gen must pass(function)

Then, in that case your example should fail with:

> A counter-example is '(b,b2)': 'b' is not equal to 'b2' (after 0 tries)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文