quickCheckAll 总是 return "True"
quickCheckAll always return "True"
我正在尝试使用 another answer 之后的 QuickCheck。
我这样测试:
{-# LANGUAGE TemplateHaskell #-}
import Test.QuickCheck
import Test.QuickCheck.All
last' :: [a] -> a
last' [x] = x
last' (_:xs) = last' xs
prop_test x = last' x == last x
check = do
putStrLn "quickCheck"
quickCheck (prop_test :: [Char]-> Bool)
check2 = do
putStrLn "quickCheckAll"
$quickCheckAll
然后我将它加载到 winGHCI 中并调用 check
和 check2
。我得到
quickCheck
*** Failed! (after 1 test):
Exception:
list.hs:(7,1)-(8,23): Non-exhaustive patterns in function last'
""
我认为这是合理的。但是,我从 check2
得到这个
quickCheckAll
True
我很困惑,因为无论我如何更改 last'
函数,即使错误,quickCheckAll
总是 return 正确。
我的代码有什么问题?我该如何解决这个问题?
来自 Test.QuickCheck.All
文档:
To use quickCheckAll
, add a definition to your module along the lines of
return []
runTests = $quickCheckAll
and then execute runTests
.
Note: the bizarre return []
in the example above is needed on GHC 7.8; without it, quickCheckAll
will not be able to find any of the properties.
在你的 check
之前添加 return []
使它对我有用。
要使用 quickCheckAll,您需要一个函数:
return []
runTests = $quickCheckAll
其他评论提到了这一点,但没有指出它将始终 return 正确,除非该函数位于所有 quickCheck 函数的下方!
我正在尝试使用 another answer 之后的 QuickCheck。 我这样测试:
{-# LANGUAGE TemplateHaskell #-}
import Test.QuickCheck
import Test.QuickCheck.All
last' :: [a] -> a
last' [x] = x
last' (_:xs) = last' xs
prop_test x = last' x == last x
check = do
putStrLn "quickCheck"
quickCheck (prop_test :: [Char]-> Bool)
check2 = do
putStrLn "quickCheckAll"
$quickCheckAll
然后我将它加载到 winGHCI 中并调用 check
和 check2
。我得到
quickCheck
*** Failed! (after 1 test):
Exception:
list.hs:(7,1)-(8,23): Non-exhaustive patterns in function last'
""
我认为这是合理的。但是,我从 check2
quickCheckAll
True
我很困惑,因为无论我如何更改 last'
函数,即使错误,quickCheckAll
总是 return 正确。
我的代码有什么问题?我该如何解决这个问题?
来自 Test.QuickCheck.All
文档:
To use
quickCheckAll
, add a definition to your module along the lines ofreturn [] runTests = $quickCheckAll
and then execute
runTests
.Note: the bizarre
return []
in the example above is needed on GHC 7.8; without it,quickCheckAll
will not be able to find any of the properties.
在你的 check
之前添加 return []
使它对我有用。
要使用 quickCheckAll,您需要一个函数:
return []
runTests = $quickCheckAll
其他评论提到了这一点,但没有指出它将始终 return 正确,除非该函数位于所有 quickCheck 函数的下方!