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?
QuickCheck is a library for random testing of program properties. The programmer provides a specification of the program, in the form of properties which functions should satisfy, and QuickCheck then tests that the properties hold in a large number of randomly generated cases.
QuickCheck is an excelent Haskell library that allows expressing properties about programs and testing them with randomly-generated values. A property for QuickCheck is simply a truth-valued function whose arguments are implicitly universally quantified.
In short: go to an empty folder and then invoke cabal install --lib --package-env . QuickCheck . Invocations of ghci inside the folder will be able to import Test. QuickCheck .
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 :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With