Last active
August 29, 2015 14:11
-
-
Save TheSeamau5/f662caa5e704e8c6e9ea to your computer and use it in GitHub Desktop.
Quickcheck in Elm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
quickCheck : Generator a -> Int -> (a -> Bool) -> String | |
quickCheck randomGenerator numberOfCases testingCondition = | |
let listGenerator = list numberOfCases <| randomGenerator | |
testInputs = fst <| generate listGenerator (initialSeed 1) | |
getOutput input = (input, testingCondition input) | |
testOutputs = map getOutput testInputs | |
failingOutputs = filter (\x -> (snd x) == False) testOutputs | |
successString = "Ok, passed " ++ (toString numberOfCases) ++ " tests." | |
failingString fail = "The following input has failed the test: " ++ (toString fail) | |
in | |
if failingOutputs == [] | |
then successString | |
else failingString <| fst <| head failingOutputs | |
{- | |
Examples : | |
> quickCheck (float 0 1) 100 (\x -> (x + 1) == x) | |
"The following input has failed the test: 0.35925459858478387" | |
> quickCheck (float 0 1) 1000 (\x -> x == x) | |
"Ok, passed 1000 tests." | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment