Created
June 7, 2014 20:16
-
-
Save etrepum/d450420a7fd8c2e73aec to your computer and use it in GitHub Desktop.
QCFail.hs
This file contains 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
import Data.Either (isLeft) | |
import Control.Exception (try, evaluate, SomeException) | |
import Test.QuickCheck (Property, quickCheck) | |
import Test.QuickCheck.Monadic (monadicIO, run, assert) | |
isFailure :: a -> IO Bool | |
isFailure = fmap isLeft . tryEval | |
where | |
tryEval :: a -> IO (Either SomeException a) | |
tryEval = try . evaluate | |
prop_empty_list :: Int -> Property | |
prop_empty_list idx = monadicIO (run (isFailure ([] !! idx)) >>= assert) | |
prop_unexpected_success :: Int -> Property | |
prop_unexpected_success idx = monadicIO (run (isFailure ([()] !! idx)) >>= assert) | |
main :: IO () | |
main = mapM_ quickCheck [ prop_empty_list, prop_unexpected_success ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment