Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I register an Arbitrary instance in FsCheck and have xUnit use it?

Tags:

f#

xunit

fscheck

I've got a type Average with a field count that's a positive int64 and a double field called sum.

I made an arbitrary that generates valid instances with

 let AverageGen = Gen.map2 (fun s c -> Average(float(s),int64(int(c))) (Arb.Default.NormalFloat().Generator)  (Arb.Default.PositiveInt().Generator) |> Arb.fromGen

How do I get this to be generate arguments with type Average in Property style tests in xUnit?

[<Property>]
static member average_test(av:Average) = ...
like image 445
nimish Avatar asked Mar 28 '14 17:03

nimish


1 Answers

type Generators =
    static member TestCase() =
        { new Arbitrary<TestCase>() with
            override x.Generator =
                gen { ...
                      return TestCase(...) }}

[<Property(Arbitrary=[|typeof<Generators>|])>]
like image 122
Vasily Kirichenko Avatar answered Oct 06 '22 01:10

Vasily Kirichenko