Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active February 8, 2017 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/1871afb70e4518289aedbade905458a2 to your computer and use it in GitHub Desktop.
Save deque-blog/1871afb70e4518289aedbade905458a2 to your computer and use it in GitHub Desktop.
forAll :: (Show a, Testable testable)
=> Gen a -> Shrink a -> (a -> testable) -> Property
forAll argGen shrink prop =
Property $ Gen $ \rand -> -- Create a new property that will
let (rand1, rand2) = split rand -- Split the generator in two
arg = runGen argGen rand1 -- Use the first generator to produce an arg
runSub = evalSubProp prop rand2 -- Factorize a runner for the sub-property
result = runSub arg -- Run the sub-property with value `arg`
in overFailure result $ \failure -> -- In case of failure,
shrinking shrink arg runSub -- Attempt to shrink the counter example
<> -- OR (in case the shrinking failed)
addToCounterExample arg failure -- Add the argument to the counter example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment