@hackage extrapolate0.0.1

generalize counter-examples of test properties

Extrapolate

Extrapolate Build Status Extrapolate on Hackage

Extrapolate automatically generalizes counter-examples to test properties.

Example

Consider the following (faulty) sort function and property:

sort :: Ord a => [a] -> [a]
sort [] = []
sort (x:xs) = sort (filter (< x) xs)
           ++ [x]
           ++ sort (filter (> x) xs)

prop_sortCount :: Ord a => a -> [a] -> Bool
prop_sortCount x xs = count x (sort xs) == count x xs
  where
  count x = length . filter (== x)

Extrapolate both returns a fully defined counter-example along with a generalization:

> import Test.Extrapolate
> check (prop_sortCount :: Int -> [Int] -> Bool)
*** Failed! Falsifiable (after 4 tests):
0 [0,0]
Generalization:
x (x:x:xs)

This hopefully makes it easier to find the source of the bug. In this case, the faulty sort function discard repeated elements.

More documentation

For more examples, see the eg folder.