haskellquickcheck

How is arbitrary distributed for Int? Why is it limited by so small values?


I am trying to compare the QuickCheck library to the SmallCheck one. In SmallCheck I can reach particular value manipulating depth parameter. In QuickCheck:

>a<-generate (replicateM 10000 arbitrary) :: IO [Int]
>length a
10000
>maximum a
30

and my question then is: why are 10,000 "random" ("arbitrary") integers limited by 30?! I expected to see more "widely" distributed values within the range 0..10,000, maybe the maximum value close to 5,000.


Solution

  • The documentation contains a clue:

    The size passed to the generator is always 30

    By default QuickCheck works by starting with 'easy' or 'small' inputs to see if it can find counterexamples with those. Only if it finds no problems with the small inputs does it gradually widen the range of generated input. The size value (which runs implicitly throughout everything that QuickCheck does) is the value that controls this behaviour.

    When you run QuickCheck (e.g. with quickCheck) it automatically increases the size as it goes.

    You're not really supposed to use the generate function directly, but if you do, you can resize it:

    ghci> b <- generate (replicateM 10000 (resize 60 arbitrary)) :: IO [Int]
    ghci> maximum b
    60
    

    That said, how are you supposed to use QuickCheck? The documentation describes quickCheck along with a multitude of variations you can use to evaluate properties.

    Personally, I integrate my QuickCheck properties with a unit testing framework with testProperty. You can see examples here: Property-based testing is not the same as partition testing.