Get counterexamples from QuickCheck as Haskell values http://www.github.com/nick8325/quickcheck-with-counterexamples

Version on this page:1.0
LTS Haskell 11.22:1.0
Stackage Nightly 2018-03-12:1.0
Latest on Hackage:1.1

See all snapshots quickcheck-with-counterexamples appears in

BSD3 licensed by Nick Smallbone
Maintained by nick@smallbone.se

Module documentation for 1.0

When QuickCheck finds a counterexample, it prints it out but
doesn't save it so that the programmer can access it. This can be
annoying when debugging.

This library provides a small extension to QuickCheck that returns
counterexamples as normal Haskell values. To use it, just import
Test.QuickCheck.Counterexamples instead of Test.QuickCheck.
The library is largely compatible with normal QuickCheck, but the
return types of quickCheck and related functions are changed to
include a counterexample.

Here is an example of getting counterexamples.
Suppose we have the following property:

prop_reverse_append :: [Int] -> [Int] -> Property
prop_reverse_append xs ys =
reverse (xs++ys) === reverse xs ++ reverse ys

If we look at the type of quickCheck, we see that it will return a

> :t quickCheck prop_reverse_append
quickCheck prop_reverse_append :: IO (Maybe ([Int] :&: [Int] :&: ()))

The Maybe is there because we get Nothing if the property succeeds;
":&:" is a datatype of pairs.

If we run QuickCheck, we can get the counterexample as a normal
Haskell value:

> Just (xs :&: ys :&: ()) <- quickCheck prop_reverse_append
*** Failed! Falsifiable (after 5 tests and 4 shrinks):
[1,0] /= [0,1]

> :t xs
xs :: [Int]

> xs

> ys
Depends on 3 packages:
Used by 1 package:
comments powered byDisqus