QuickCheck 2 有什么新功能?

发布于 2024-08-15 08:33:55 字数 193 浏览 5 评论 0原文

QuickCheck 1 和 QuickCheck 2 之间的主要区别是什么?通过查看 Haddock 文档,我可以看到它分为更多模块,co Arbitrary 已被新的 Fun 类型和 FunArbitrary 类取代(这对我来说似乎更容易理解),并且现在支持测试单子代码。我还应该注意什么?

What are the major differences between QuickCheck 1 and QuickCheck 2? From looking at Haddock docs I can see that it is split across more modules, coarbitrary has been replaced by the new Fun type and FunArbitrary class (which seems easier to understand to me), and testing monadic code is now supported. What else should I be aware of?

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

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

发布评论

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

评论(1

一梦等七年七年为一梦 2024-08-22 08:33:55

我在 QuickCheck 2 中看到了一项重大进步,我认为它与单子代码测试一样重要,甚至更重要:

class Arbitrary  a where
    arbitrary :: Gen a
    shrink :: a -> [a]

真的非常棒。收缩方法是可选的,但如果您可以提供一个“可能为空”的类型缩减列表,那么当 QuickCheck 发现错误检查时,它会尝试通过收缩来将错误数据减少到最少,然后重新进行重新排序。 -测试一下。只要失败它就会缩小。

一个小样本可以让您信服,无需缩小:

FormulaPrim deparsing    : *** Failed! Falsifiable (after 4 tests):
Poly (Polynome "p" [(CoeffRatio (26 % 25),PolyRest (CoeffRatio (129 % 40))),(CoeffInt 96,PolyRest (CoeffInt 11)),(CoeffInt 29,PolyRest (CoeffRatio (147 % 121))),(CoeffRatio (62 % 9),PolyRest (CoeffRatio (90 % 43))),(CoeffInt 56,PolyRest (CoeffInt 27))])

带有:

FormulaPrim deparsing    : *** Failed! Falsifiable (after 2 tests and 3 shrinks):
Poly (Polynome "t" [(CoeffInt 14,PolyRest (CoeffInt 126))])

更短的失败示例意味着更快的调试:-)

I've seen one major advancement in QuickCheck 2, I think as important as monadic code testing, if not more :

class Arbitrary  a where
    arbitrary :: Gen a
    shrink :: a -> [a]

This, is really awesome. The shrink method is optional, but if you can provide a list of "possibly empty" reduction of your type, then when QuickCheck find a faulty check, it will try to reduce your faulty data to the minimum by trying to shrink it and then re-test it. It shrink it as long as it fails.

A little sample to convince you, Without shrinking :

FormulaPrim deparsing    : *** Failed! Falsifiable (after 4 tests):
Poly (Polynome "p" [(CoeffRatio (26 % 25),PolyRest (CoeffRatio (129 % 40))),(CoeffInt 96,PolyRest (CoeffInt 11)),(CoeffInt 29,PolyRest (CoeffRatio (147 % 121))),(CoeffRatio (62 % 9),PolyRest (CoeffRatio (90 % 43))),(CoeffInt 56,PolyRest (CoeffInt 27))])

With :

FormulaPrim deparsing    : *** Failed! Falsifiable (after 2 tests and 3 shrinks):
Poly (Polynome "t" [(CoeffInt 14,PolyRest (CoeffInt 126))])

Shorter fail example mean quicker debug :-)

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