-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24b9e68
commit 7c51fc6
Showing
3 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{-# LANGUAGE TypeApplications #-} | ||
module Main where | ||
|
||
import Test.QuickCheck | ||
import System.Exit | ||
|
||
assert :: String -> Bool -> IO () | ||
assert s False = do | ||
putStrLn $ s ++ " failed!" | ||
exitFailure | ||
assert _ _ = pure () | ||
|
||
quickCheckYes, quickCheckNo :: Property -> IO () | ||
quickCheckYes p = do | ||
res <- quickCheckResult p | ||
if isSuccess res | ||
then pure () | ||
else exitFailure | ||
quickCheckNo p = do | ||
res <- quickCheckResult p | ||
if isSuccess res | ||
then exitFailure | ||
else pure () | ||
|
||
check :: Result -> Int -> Int -> IO () | ||
check res n d = do | ||
quickCheckYes $ once $ n === numTests res | ||
quickCheckYes $ once $ d === numDiscarded res | ||
|
||
main :: IO () | ||
main = do | ||
putStrLn "Testing: False ==> True" | ||
res <- quickCheckResult $ withDiscardRatio 2 $ False ==> True | ||
check res 0 200 | ||
|
||
putStrLn "Testing: x == x" | ||
res <- quickCheckResult $ withDiscardRatio 2 $ \ x -> (x :: Int) == x | ||
check res 100 0 | ||
|
||
-- The real ratio is 20, if 1 works or 40 doesn't it's | ||
-- probably because we broke something! | ||
let p50 = forAll (choose (1, 1000)) $ \ x -> (x :: Int) < 50 ==> True | ||
putStrLn "Expecting failure (discard ratio 1): x < 50 ==> True" | ||
quickCheckNo $ withDiscardRatio 1 p50 | ||
putStrLn "Expecting success (discard ratio 40): x < 50 ==> True" | ||
quickCheckYes $ withDiscardRatio 40 p50 |