如何在Expecto上重新注册自己的FsCheck Generator

我已经构建了生成器类型,该类型生成三个的倍数。我想在expecto的测试中使用它,如何注册生成器并告诉我的测试使用它?

let multipleOfThree n = n * 3

type ThreeGenerator =
    static member ThreeMultiple() =
        Arb.generate<NonNegativeInt>
        |> Gen.map (fun (NonNegativeInt n) -> multipleOfThree n)
        |> Gen.filter (fun n -> n > 0)
        |> Arb.fromGen
iCMS 回答:如何在Expecto上重新注册自己的FsCheck Generator

我发现自己已经意识到了。用于在Expecto中注册您的生成器

    let multipleOfThree =
    { FsCheckConfig.defaultConfig with
          arbitrary = [ typeof<ThreeGenerator> ] }

并且可以在您的测试中使用

testPropertyWithConfig multipleOfThree "test with your generator "
          <| fun x -> Expect.equal (FunctionUnderTest x) "Expected" "Error message"
本文链接:https://www.f2er.com/1961198.html

大家都在问