Safe Haskell | None |
---|---|
Language | Haskell2010 |
Tutorial: http://github.com/bennofs/quickcheck-property-monad/tree/master/README.md
Note about the examples: The examples use a "-" in place of the empty line. This is required in order for doctest to work.
Documentation
PropM is a monad for writing properties that depend on random
data. This is especially useful if you have many invariants for
your data and cannot simply write an Arbitrary
instance.
You can use a PropM a
as a QuickCheck Testable if a
is Testable. For example,
you can use PropM Bool
as a Testable property:
>>>
quickCheck (return True :: PropM Bool)
+++ OK, passed 100 tests.
>>>
quickCheck (return False :: PropM Bool)
*** Failed! Falsifiable (after 1 test): -
assert :: String -> Bool -> PropM () Source
Assert that a certain condition is true. If the condition is false, fail with the given error message.
Examples:
>>>
quickCheck $ assert "True is True!" True >> return True
+++ OK, passed 100 tests.
>>>
quickCheck $ assert "False is True!" False >> return True
*** Failed! Falsifiable (after 1 test): - Assertion failed: False is True!
failWith :: String -> PropM () Source
Fail with the given error message.
Example:
>>>
quickCheck $ failWith "Something horrible happened" >> return True
*** Failed! Falsifiable (after 1 test): - Something horrible happened
gen :: Gen a -> PropM a Source
Use the given generator to generate a value.
Examples:
>>>
quickCheck $ fmap (`elem` [0..5]) $ gen (elements [0..5])
+++ OK, passed 100 tests.
>>>
quickCheck $ fmap (> 0) $ gen (choose (0,1))
*** Failed! Falsifiable (after 2 tests): -
logMessage :: String -> PropM () Source
Log a message that will be printed when the test case fails.
logMessageLn :: String -> PropM () Source
Like logMessage
but appends a line break after the message.
Example:
>>>
quickCheck $ gen (choose (0,1)) >>= \x -> logMessageLn ("Chosen: " ++ show x) >> return (x > 0)
*** Failed! Falsifiable (after 2 tests): Chosen: 0 -