What's new in QuickCheck 2?

后端 未结 1 1028
闹比i
闹比i 2021-01-31 02:32

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 b

相关标签:
1条回答
  • 2021-01-31 03:19

    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 :-)

    0 讨论(0)
提交回复
热议问题