gpt4 book ai didi

unit-testing - quickCheckAll 总是返回 "True"

转载 作者:行者123 更新时间:2023-12-04 06:59:53 24 4
gpt4 key购买 nike

我正在尝试使用 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 并调用 checkcheck2 .我明白了
quickCheck
*** Failed! (after 1 test):
Exception:
list.hs:(7,1)-(8,23): Non-exhaustive patterns in function last'
""
我认为这是合理的。但是,我从 check2 得到这个
quickCheckAll
True
我很困惑,因为无论我如何更改 last'函数,甚至错误, quickCheckAll总是返回 True。
我的代码有什么问题?我怎样才能解决这个问题?

最佳答案

来自 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.


添加 return []在您的 check 之前让它对我有用。

关于unit-testing - quickCheckAll 总是返回 "True",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28358575/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com