[QuickCheck] Shrinking a list

Nick Smallbone nicsma at chalmers.se
Thu Dec 20 14:35:20 GMT 2012


Hi Jurriën,

When a property fails, QuickCheck repeats the shrinking process until
it can't shrink the counterexample any more. For example, if a
property fails on [0,1,2], QuickCheck will try each of the shrink
candidates ([], [1,2] etc.) in turn. If the property turns out to fail
on [1,2], QuickCheck will shrink that and try, among other things,
[1]. So you eventually get a minimal counterexample.

This is a heuristic (e.g. if the property failed on singleton lists
and lists of length 3 but not on lists of length 2 then any
counterexample would only shrink to a list of length 3 and then stop)
but in practice it usually finds near-minimal counterexamples. It
means we avoid having to try too many shrink candidates, which would
slow shrinking down.

Nick

On 20 December 2012 14:21, Jurriën Stutterheim <j.stutterheim at me.com> wrote:
> Dear QC devs,
>
>
> I am trying to understand `shrink`'s behaviour. Let's start with a small example:
>
> Prelude Test.QuickCheck> shrink [0,1,2]
> [[],[1,2],[0,2],[0,1],[0,0,2],[0,1,0],[0,1,1]]
>
> In this example, where I apply `shrink` to the list `[0,1,2]`, `shrink` does not produce any singleton lists. Why is that? After all, a minimal counter-example could be found in, e.g., the list `[1]`.
>
> Thanks in advance!
>
>
> Jurriën
> _______________________________________________
> QuickCheck mailing list
> QuickCheck at projects.haskell.org
> http://projects.haskell.org/cgi-bin/mailman/listinfo/quickcheck



More information about the QuickCheck mailing list