All Projects → rudymatela → extrapolate

rudymatela / extrapolate

Licence: BSD-3-Clause license
generalize counter-examples of property-based testing

Programming Languages

haskell
3896 projects
Makefile
30231 projects
shell
77523 projects

Projects that are alternatives of or similar to extrapolate

leancheck
enumerative property-based testing for Haskell
Stars: ✭ 38 (+192.31%)
Mutual labels:  property-based-testing, testing-tools, property-testing, enumerative-testing, leancheck
probably
To probe what we can't prove, so the unprovable may become probable
Stars: ✭ 58 (+346.15%)
Mutual labels:  testing-tools, property-testing
Fsharp Hedgehog
Release with confidence, state-of-the-art property testing for .NET.
Stars: ✭ 219 (+1584.62%)
Mutual labels:  property-based-testing, testing-tools
Kotest
Powerful, elegant and flexible test framework for Kotlin with additional assertions, property testing and data driven testing
Stars: ✭ 3,234 (+24776.92%)
Mutual labels:  testing-tools, property-testing
hypothesis-gufunc
Extension to hypothesis for testing numpy general universal functions
Stars: ✭ 32 (+146.15%)
Mutual labels:  property-based-testing, testing-tools
Haskell Hedgehog
Release with confidence, state-of-the-art property testing for Haskell.
Stars: ✭ 584 (+4392.31%)
Mutual labels:  property-based-testing, testing-tools
pbt-frameworks
An overview of property-based testing functionality
Stars: ✭ 29 (+123.08%)
Mutual labels:  property-based-testing, property-testing
Deepstate
A unit test-like interface for fuzzing and symbolic execution
Stars: ✭ 603 (+4538.46%)
Mutual labels:  property-based-testing, testing-tools
Objectexporter
Object Exporter lets you export out an object while debugging in Visual Studio, the object can be serialized in either C#, JSON or XML.
Stars: ✭ 240 (+1746.15%)
Mutual labels:  debugging, testing-tools
go-test-report
Captures go test output and parses it into a single self-contained HTML file.
Stars: ✭ 68 (+423.08%)
Mutual labels:  testing-tools
generator-react-jest-tests
A React Jest test generator. Generates snapshot tests for React components.
Stars: ✭ 34 (+161.54%)
Mutual labels:  testing-tools
selenium-client
A PHP Selenium client
Stars: ✭ 31 (+138.46%)
Mutual labels:  debugging
bookish spork
Erlang library for testing http requests
Stars: ✭ 82 (+530.77%)
Mutual labels:  testing-tools
regression-testing
Regression testing in Elm!
Stars: ✭ 22 (+69.23%)
Mutual labels:  testing-tools
vPAV
viadee Process Application Validator
Stars: ✭ 47 (+261.54%)
Mutual labels:  testing-tools
eaf-linter
🤪 A linter, prettier, and test suite that does everything as-simple-as-possible.
Stars: ✭ 17 (+30.77%)
Mutual labels:  testing-tools
react-native-debug-console
A network and console debug component and modal for react native purely in JavaScript
Stars: ✭ 17 (+30.77%)
Mutual labels:  debugging
Meadow
Integrated Ethereum implementation and tool suite focused on Solidity testing and development.
Stars: ✭ 126 (+869.23%)
Mutual labels:  debugging
api-test
🌿 A simple bash script to test JSON API from terminal in a structured and organized way.
Stars: ✭ 53 (+307.69%)
Mutual labels:  testing-tools
cl-spec
BDD for Common Lisp
Stars: ✭ 18 (+38.46%)
Mutual labels:  testing-tools

Extrapolate

Extrapolate Build Status Extrapolate on Hackage Extrapolate on Stackage LTS Extrapolate on Stackage Nightly

Extrapolate logo

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

Installing Extrapolate

To install the latest version of Extrapolate from Hackage using cabal, just:

$ cabal update
$ cabal install extrapolate

To test if it installed correctly, follow through the next section.

Starting from Cabal v3, you need to pass --lib to cabal install:

$ cabal install extrapolate --lib

Using Extrapolate

To use Extrapolate, you first import the Test.Extrapolate module, then pass any properties you with to test to the function check:

$ 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:_

The operator + is commutative. The function nub is not an identity.

Configuring the number of tests

To increase the number of tests, use the for combinator:

$ 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 withBackground combinator:

$ 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 withBackground.

The combinators for and withBackground can be used in conjunction:

> check `for` 100 `withBackground` [...] $ property

Don't forget the dollar sign $.

Another Example

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.

Further reading

For more examples, see the eg folder. For type signatures, other options and uses, see Extrapolate's API documentation.

There are two other tools for Haskell capable of producing generalized counter-examples: SmartCheck and Lazy SmallCheck 2012.

Extrapolate was presented at IFL 2017 and was subject to a paper titled Extrapolate: generalizing counterexamples of functional test properties. Extrapolate is also subject to a chapter in a PhD Thesis (2017).

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].