Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Last active February 2, 2017 12:06
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/bbdc45d4661be725eacb7e7b5a8ecb5d to your computer and use it in GitHub Desktop.
Save deque-blog/bbdc45d4661be725eacb7e7b5a8ecb5d to your computer and use it in GitHub Desktop.
forAll :: (Show a, Testable testable) => Gen a -> (a -> testable) -> Property
forAll argGen 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
subProp = property (prop arg) -- Use the `a` to access the sub-property
result = runProp subProp rand2 -- Use the second generator to run it
in overFailure result $ \failure -> -- Enrich the counter-example with `arg`
failure { counterExample = show arg : counterExample failure }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment