使 Test.QuickCheck.Batch 使用默认类型来测试列表函数
我正在测试一个名为“提取”的函数,该函数可以在任何列表上运行。
extractions :: [a] -> [(a,[a])]
extractions [] = []
extractions l = extract l []
where extract [] _ = []
extract (x:xs) prev = (x, prev++xs) : extract xs (x : prev)
例如,我想测试它,
import Test.QuickCheck.Batch
prop_len l = length l == length (extractions l)
main = runTests "extractions" defOpt [run prop_len]
但是这不会编译; 我必须为 run
或 prop_len
提供类型,因为 QuickCheck 无法生成 [a]
,它必须生成具体的内容。 所以我选择了Int
:
main = runTests "extractions" defOpt [r prop_len]
where r = run :: ([Int] -> Bool) -> TestOptions -> IO TestResult
有没有办法让QuickCheck为我选择a
,而不是在run
类型中指定它?
I am testing a function called extractions that operates over any list.
extractions :: [a] -> [(a,[a])]
extractions [] = []
extractions l = extract l []
where extract [] _ = []
extract (x:xs) prev = (x, prev++xs) : extract xs (x : prev)
I want to test it, for example, with
import Test.QuickCheck.Batch
prop_len l = length l == length (extractions l)
main = runTests "extractions" defOpt [run prop_len]
But this won't compile; I have to supply a type either for run
or prop_len
, because QuickCheck can't generate [a]
, it has to generate something concrete. So I chose Int
:
main = runTests "extractions" defOpt [r prop_len]
where r = run :: ([Int] -> Bool) -> TestOptions -> IO TestResult
Is there any way to get QuickCheck to choose a
for me instead of having it specified in the type of run
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
quickcheck 手册说“不”:
The quickcheck manual says "no":