Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's new in QuickCheck 2?

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?

like image 609
Alexey Romanov Avatar asked Dec 19 '09 16:12

Alexey Romanov


People also ask

What does QuickCheck Check?

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.

What is QuickCheck in Haskell?

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.

How do I get QuickCheck with Haskell?

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 .


1 Answers

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

like image 140
Raoul Supercopter Avatar answered Sep 21 '22 16:09

Raoul Supercopter