[Haskell-cafe] Generating test data in QuickCheck

Janek S. fremenzone at poczta.onet.pl
Mon Oct 15 11:30:34 CEST 2012


I'm writing tests using QuickCheck to test data types that are not an instance of QC's Arbitrary. 
To prevent orphan instances I use forAll function instead of instantiating these types as 
Arbitrary. The problems arise when I need to generate several different variables for one test. 
To do this I either nest calls to forAll or create a pair generator like this:

genPair = liftM2 (,) (myGenerator1) (myGenerator2)

Running time of such tests is very long (both with nesting forAll and using pair generator) and it 
gets shorter when I resize myGenerator1 and myGenerator2. This leads me to conslusion that, due 
to nesting of generators QC is generating 100*100*100 test cases instead of 100. How do 
I "flatten" my generators to always get 100 test cases (or whatever the default number of test 
is)?

Janek



More information about the Haskell-Cafe mailing list