extrapolate: generalize counter-examples of test properties

[ bsd3, library, testing ] [ Propose Tags ]

Extrapolate is a tool able to provide generalized counter-examples of test properties where irrelevant sub-expressions are replaces with variables.

For the incorrect property xs -> nub xs == (xs::[Int]):

[Skip to Readme]
Versions [RSS] [faq] 0.0.1, 0.1.0, 0.2.0, 0.2.1, 0.2.2, 0.2.3, 0.2.4, 0.3.0, 0.3.1, 0.3.2, 0.3.3, 0.4.0, 0.4.1, 0.4.2, 0.4.4, 0.4.6
Dependencies base (==4.*), leancheck (>=0.6.4), speculate (>=0.2.6), template-haskell [details]
License BSD-3-Clause
Author Rudy Matela
Maintainer Rudy Matela <rudy@matela.com.br>
Category Testing
Home page https://github.com/rudymatela/extrapolate#readme
Source repo head: git clone https://github.com/rudymatela/speculate
this: git clone https://github.com/rudymatela/speculate(tag v0.1.0)
Uploaded by rudymatela at 2017-08-04T17:06:03Z
Distributions LTSHaskell:0.4.6, NixOS:0.4.6, Stackage:0.4.6
Downloads 7549 total (61 in the last 30 days)
Rating 2.0 (votes: 1) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs uploaded by user
Build status unknown [no reports yet]




Maintainer's Corner

For package maintainers and hackage trustees


Readme for extrapolate-0.1.0

[back to package description]


Extrapolate Build Status Extrapolate on Hackage

Extrapolate is a property-based testing library for Haskell capable of reporting generalized counter-examples.


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
  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]

x (x:x:xs)

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

More documentation

For more examples, see the eg folder.