所以我有一个属性p :: Int -> Bool
。我需要使用自定义生成器g :: Gen Int
对其进行测试。这行得通,我可以跑步
quickCheckResult $ forAll g p
但是我希望它运行100多个测试。
该文档说使用withMaxSuccess
。这适用于
quickCheck (withMaxSuccess 1000 p)
但不是
quickCheckResult $ forAll g (withMaxSuccess 1000 p)
因为它会导致:
<interactive>:38:23: error:
• Couldn't match expected type ‘Int -> prop0’
with actual type ‘Property’
• Possible cause: ‘withMaxSuccess’ is applied to too many arguments
In the second argument of ‘forAll’, namely
‘(withMaxSuccess 10000 p)’
In the expression:
forAll g (withMaxSuccess 10000 p)
In an equation for ‘it’:
it = forAll g (withMaxSuccess 10000 p)
似乎withMaxSuccess
将Int->Bool
设为Property
如何以任意数量运行forAll
?
答案 0 :(得分:1)
您只需要稍稍不同地组成表达式即可
quickCheckResult $ withMaxSuccess 1000 $ forAll g p
或者,如果您喜欢方括号:
quickCheckResult ((withMaxSuccess 1000) (forAll g p))
查看类型应解释其工作原理:
Prelude Test.QuickCheck> :t forAll g p
forAll g p :: Property
Prelude Test.QuickCheck> :t withMaxSuccess 1000
withMaxSuccess 1000 :: Testable prop => prop -> Property
Prelude Test.QuickCheck> :t (withMaxSuccess 1000) (forAll g p)
(withMaxSuccess 1000) (forAll g p) :: Property
由于Property
是Testable
实例,因此类型会排列。