如何更改自定义生成器的测试量?

How do I change the amount of tests for a custom generator?

所以我有一个 属性 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)

似乎 withMaxSuccessInt->Bool 变成了 Property

我怎样才能 运行 forAll 获得任意金额?

你只需要稍微改变一下表达式:

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 实例,所以类型一致。