Module documentation for 0.4.6
$ cabal update $ cabal install extrapolate
To test if it installed correctly, follow through the next section.
Starting from Cabal v3, you need to pass
$ cabal install extrapolate --lib
$ ghci > import Test.Extrapolate > check $ \x y -> x + y == y + (x :: Int) +++ OK, passed 360 tests. > import Data.List (nub) > check $ \xs -> nub xs == (xs :: [Int]) *** Failed! Falsifiable (after 3 tests): [0,0] Generalization: x:x:_
Configuring the number of tests
To increase the number of tests, use the
$ ghci > import Test.Extrapolate > check `for` 1000 $ \x y -> x + y == y + (x :: Int) +++ OK, passed 1000 tests.
Customizing the background functions (allowed in side-conditions)
To customize the background functions, use the
$ ghci > import Test.Extrapolate > import Data.List (nub) > let hasDups xs = nub xs /= (xs :: [Int]) > check `withBackground` [constant "hasDups" hasDups] $ \xs -> nub xs == (xs :: [Int]) *** Failed! Falsifiable (after 3 tests): [0,0] Generalization: x:x:_ Conditional Generalization: xs when hasDups xs
Perhaps the example above is silly (
hasDups is the negation of the property
itself!), but it illustrates the use of
> check `for` 100 `withBackground` [...] $ property
Don’t forget the dollar sign
Consider the following (faulty) sort function and a property about it:
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)
After testing the property, Extrapolate 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:_)
This hopefully makes it easier to find the source of the bug. In this case, the faulty sort function discards repeated elements.