Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I register my own FsCheck Generator on Expecto

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
like image 350
ntonjeta Avatar asked Dec 18 '25 11:12

ntonjeta


1 Answers

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"
like image 87
ntonjeta Avatar answered Dec 21 '25 03:12

ntonjeta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!