From 3da40574ffe2f60d0df2a90835b1a562d9dd025d Mon Sep 17 00:00:00 2001 From: Simon Hengel Date: Mon, 5 Jun 2017 20:49:26 +0800 Subject: [PATCH 1/4] Use mapM_ instead of sequence_ --- Test/QuickCheck/Test.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Test/QuickCheck/Test.hs b/Test/QuickCheck/Test.hs index c0eedcd6..0c56f594 100644 --- a/Test/QuickCheck/Test.hs +++ b/Test/QuickCheck/Test.hs @@ -353,7 +353,7 @@ success st = ++ ")." ) cases -> do putLine (terminal st) ":" - sequence_ [ putLine (terminal st) pt | pt <- cases ] + mapM_ (putLine $ terminal st) cases where allLabels = [ showP True p ++ " " ++ x | (x, p) <- summary st ] From bc85f670143a969602ffe6ea18d7836b035a547e Mon Sep 17 00:00:00 2001 From: Simon Hengel Date: Mon, 5 Jun 2017 21:35:22 +0800 Subject: [PATCH 2/4] Add type signatures for local bindings --- Test/QuickCheck/Test.hs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Test/QuickCheck/Test.hs b/Test/QuickCheck/Test.hs index 0c56f594..c8224183 100644 --- a/Test/QuickCheck/Test.hs +++ b/Test/QuickCheck/Test.hs @@ -355,12 +355,15 @@ success st = cases -> do putLine (terminal st) ":" mapM_ (putLine $ terminal st) cases where + allLabels :: [String] allLabels = [ showP True p ++ " " ++ x | (x, p) <- summary st ] + covers :: [String] covers = [ ("only " ++ showP False p ++ " " ++ l ++ ", not " ++ show reqP ++ "%") | (l, reqP, p) <- insufficientlyCovered st ] + showP :: Bool -> Double -> String showP pad p = (if pad && p < 10 then " " else "") ++ printf "%.*f" places p ++ "%" From 0ba35045e20b7f04d825dc913dd9db20ebb1ff0a Mon Sep 17 00:00:00 2001 From: Simon Hengel Date: Mon, 5 Jun 2017 21:35:51 +0800 Subject: [PATCH 3/4] Remove code duplication --- Test/QuickCheck/Test.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Test/QuickCheck/Test.hs b/Test/QuickCheck/Test.hs index c8224183..1e33da22 100644 --- a/Test/QuickCheck/Test.hs +++ b/Test/QuickCheck/Test.hs @@ -356,13 +356,15 @@ success st = mapM_ (putLine $ terminal st) cases where allLabels :: [String] - allLabels = - [ showP True p ++ " " ++ x | (x, p) <- summary st ] + allLabels = map (formatLabel True) (summary st) covers :: [String] - covers = [ ("only " ++ showP False p ++ " " ++ l ++ ", not " ++ show reqP ++ "%") + covers = [ ("only " ++ formatLabel False (l, p) ++ ", not " ++ show reqP ++ "%") | (l, reqP, p) <- insufficientlyCovered st ] + formatLabel :: Bool -> (String, Double) -> String + formatLabel pad (x, p) = showP pad p ++ " " ++ x + showP :: Bool -> Double -> String showP pad p = (if pad && p < 10 then " " else "") ++ From 895168f874affcada769999740a463b3d7017a7e Mon Sep 17 00:00:00 2001 From: Simon Hengel Date: Mon, 5 Jun 2017 21:40:30 +0800 Subject: [PATCH 4/4] Export Test.QuickCheck.Test.formatLabel --- Test/QuickCheck/Test.hs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Test/QuickCheck/Test.hs b/Test/QuickCheck/Test.hs index 1e33da22..92bfffa4 100644 --- a/Test/QuickCheck/Test.hs +++ b/Test/QuickCheck/Test.hs @@ -356,15 +356,15 @@ success st = mapM_ (putLine $ terminal st) cases where allLabels :: [String] - allLabels = map (formatLabel True) (summary st) + allLabels = map (formatLabel (numSuccessTests st) True) (summary st) covers :: [String] - covers = [ ("only " ++ formatLabel False (l, p) ++ ", not " ++ show reqP ++ "%") + covers = [ ("only " ++ formatLabel (numSuccessTests st) False (l, p) ++ ", not " ++ show reqP ++ "%") | (l, reqP, p) <- insufficientlyCovered st ] - formatLabel :: Bool -> (String, Double) -> String - formatLabel pad (x, p) = showP pad p ++ " " ++ x - +formatLabel :: Int -> Bool -> (String, Double) -> String +formatLabel n pad (x, p) = showP pad p ++ " " ++ x + where showP :: Bool -> Double -> String showP pad p = (if pad && p < 10 then " " else "") ++ @@ -375,7 +375,7 @@ success st = -- two decimal places if <= 10000 successful tests, and so on. places :: Integer places = - ceiling (logBase 10 (fromIntegral (numSuccessTests st)) - 2 :: Double) `max` 0 + ceiling (logBase 10 (fromIntegral n) - 2 :: Double) `max` 0 labelCount :: String -> State -> Int labelCount l st =