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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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 :-)