[Haskell-cafe] Conditional properties in QuickCheck alter test data
generation?
Kevin Van Horn
kevin at ksvanhorn.com
Wed Dec 17 23:07:56 EST 2008
I'm learning QuickCheck, and I'm puzzled by the behavior I'm seeing
with conditional properties. After writing and loading a simple qsort
function from a separate file, I typed these into ghci:
let prop_minimum xs = (length xs > 0) ==> head (qsort xs) == minimum xs
where types = xs :: [Integer]
let prop_minimum1 xs = (length xs > 3) ==> head (qsort xs) == minimum xs
where types = xs :: [Integer]
These differ only in that prop_minimum1 uses a more restrictive
condition.
Then quickCheck prop_minimum outputs
"OK, passed 100 tests"
but quickCheck prop_minimum1 outputs
"Arguments exhausted after 0 tests"
Investigating with verboseCheck yields puzzling results. For example,
verboseCheck prop_minimum says "OK, passed 100 tests", but some of the
test instances it shows have length 0, contrary to the condition...
and a significant fraction of the test instances have length > 3, or
even length > 10! So why the problem when running quickCheck on
prop_minimum1?
Running verboseCheck prop_minimum1 just deepens the mystery. Now we
see most of the test instances generated having 0 length, and none of
them having length > 3. What's going on here? Why is the
distribution of generated test instances so drastically altered?
BTW, I'm using ghc version 6.10.1, running on Intel Mac OS 10.5.5.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20081217/587ce466/attachment.htm
More information about the Haskell-Cafe
mailing list