[Haskell-cafe] the purpose of QuickCheck's size parameter

Li-yao Xia lysxia at gmail.com
Thu Jun 14 22:22:21 UTC 2018


The purpose of the size parameter is not well-defined formally, but it 
is a very convenient knob to easily tune the test suite in various 
situations, that is definitely worth the negligible cost of having it 
around unconditionally.

Without a size parameter, a fixed distribution means that if we want the 
generator to cover all possible cases, we have to keep a small 
probability of generating humongous examples and thus go OOM. We can 
avoid that by making the size of generated values bounded by the size 
parameter (or a function thereof), which we can increase easily when 
more resources become available.

Furthermore, if we really want to generate very large examples, the only 
way with a fixed distribution is to wait longer. Instead, using a size 
parameter, we can make smaller values less likely to target further 
regions in the search space more accurately.

Some properties can take a while to test on larger examples (either 
because of the generators or the actual verification process) so we 
might like to keep the size small during development, and raise it again 
once we're done.

The Arbitrary class assigns a "default" generator for every type. While 
it is not always a good choice, having a parameter to tweak makes 
Arbitrary more generally useful.

As for your last point, small examples are faster to generate and check, 
so it seems like a decent strategy to start small by default.

Li-yao


More information about the Haskell-Cafe mailing list