QuickCheck 2有哪些新功能? [英] What's new in QuickCheck 2?
问题描述
QuickCheck 1和QuickCheck 2之间的主要区别是什么?从查看Haddock文档,我可以看出它跨越多个模块, coarbitrary
已被新的 Fun取代类型和
FunArbitrary
类(这对我来说似乎更容易理解),并且现在支持测试单代码。我还有什么需要注意的?
我在QuickCheck 2中看到了一个重大进步,我认为和monadic一样重要代码测试,如果不是更多:
class任意a其中
任意:: Gen a
shrink: :a - > [a]
这是真的真棒。收缩方法是可选的,但如果您可以提供可能为空的类型缩减列表,那么当QuickCheck发现错误检查时,它会尝试缩小错误数据,然后尝试缩小错误数据 - 测试它。只要它失败,它就会缩小。
一个简单的例子来说服你,而不是缩小:
FormulaPrim deparsing:***失败!可证伪(经过4次测试):
Poly(Polynomep[(CoeffRatio(26%25),PolyRest(CoeffRatio(129%40))),(CoeffInt 96,PolyRest(CoeffInt 11)),CoeffInt (CoeffRatio(147%121))),(CoeffRatio(62%9),PolyRest(CoeffRatio(90%43))),(CoeffInt 56,PolyRest(CoeffInt 27))])
与:
FormulaPrim解析:***失败!可证伪(经过2次测试和3次收缩):
Poly(Polynomet[(CoeffInt 14,PolyRest(CoeffInt 126))])
更短的失败示例意味着更快的调试: - )
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?
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 :-)
这篇关于QuickCheck 2有哪些新功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!