What's new in QuickCheck 2?
Asked Answered
H

1

40

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?

Hazeghi answered 19/12, 2009 at 16:1 Comment(0)
F
54

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

Faydra answered 19/12, 2009 at 18:4 Comment(1)
Coolest hack I've seen all week.Eldin

© 2022 - 2024 — McMap. All rights reserved.