How do I register my own FsCheck Generator on Expecto

171 Views Asked by At

I've built my generator type that generates multiples of three. I want to use it in a test with Expecto. How can register this generator and tell my test to use it?

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
1

There are 1 best solutions below

0
On BEST ANSWER

I've found answare my self. For register your generator in Expecto

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

And can use in your test

testPropertyWithConfig multipleOfThree "test with your generator "
          <| fun x -> Expect.equal (FunctionUnderTest x) "Expected" "Error message"