@@ -1,17 +1,73 @@
1module QuickCheckUtils where
1module QuickCheckUtils where
4+import qualified Data.Text as T
3import Test.QuickCheck
7import Test.QuickCheck
4−import Test.QuickCheck.Batch
9−import Data.Text.Internal
11instance Arbitrary Char where
9instance Arbitrary Char where
12 arbitrary = oneof [choose ('\0','\55295'), choose ('\57334','\1114111')]
10 arbitrary = oneof [choose ('\0','\55295'), choose ('\57334','\1114111')]
13− coarbitrary c = variant (ord c `rem` 4)
11+ coarbitrary c = variant (fromEnum c `rem` 4)
13+instance Arbitrary T.Text where
14+ arbitrary = T.pack `fmap` arbitrary
15+ coarbitrary s = coarbitrary (T.unpack s)
19+mytest :: Testable a => a -> Int -> IO (Bool, Int)
20+mytest a n = mycheck defaultConfig
22+ , configEvery= \n args -> if debug then show n ++ ":\n" ++ unlines args else [] } a
24+mycheck :: Testable a => Config -> a -> IO (Bool, Int)
27+ mytests config (evaluate a) rnd 0 0 []
29+mytests :: Config -> Gen Result -> StdGen -> Int -> Int -> [[String]] -> IO (Bool, Int)
30+mytests config gen rnd0 ntest nfail stamps
31+ | ntest == configMaxTest config = done "OK," ntest stamps >> return (True, ntest)
32+ | nfail == configMaxFail config = done "Arguments exhausted after" ntest stamps >> return (True, ntest)
34+ do putStr (configEvery config ntest (arguments result)) >> hFlush stdout
37+ mytests config gen rnd1 ntest (nfail+1) stamps
39+ mytests config gen rnd1 (ntest+1) nfail (stamp result:stamps)
41+ putStr ( "Falsifiable after "
44+ ++ unlines (arguments result)
45+ ) >> hFlush stdout >> return (False, ntest)
47+ result = generate (configSize config ntest) rnd2 gen
48+ (rnd1,rnd2) = split rnd0
50+done :: String -> Int -> [[String]] -> IO ()
51+done mesg ntest stamps =
52+ do putStr ( mesg ++ " " ++ show ntest ++ " tests" ++ table )
61+ . filter (not . null)
65+ display [x] = " (" ++ x ++ ").\n"
66+ display xs = ".\n" ++ unlines (map (++ ".") xs)
68+ pairLength xss@(xs:_) = (length xss, xs)
69+ entry (n, xs) = percentage n ntest
71+ ++ concat (intersperse ", " xs)
15−instance Arbitrary Text where
73+ percentage n m = show ((100 * n) `div` m) ++ "%"
16− arbitrary = pack `fmap` arbitrary
17− coarbitrary s = coarbitrary (unpack s)