I am trying to implement a custom Arbitrary
one that generates glob syntax templates such as a*c?
. I believe that my implementation is correct, simply that when running the test with Xunit, FsCheck does not seem to use arbitrary arbitrary Pattern
to generate test data. When I use LINQPad, everything works as expected. Here is the code:
open Xunit
open FsCheck
type Pattern = Pattern of string with
static member op_Explicit(Pattern s) = s
type MyArbitraries =
static member Pattern() =
(['a'..'c']@['?'; '*'])
|> Gen.elements
|> Gen.nonEmptyListOf
|> Gen.map (List.map string >> List.fold (+) "")
|> Arb.fromGen
|> Arb.convert Pattern string
Arb.register<MyArbitraries>() |> ignore
[<Fact>]
let test () =
let prop (Pattern p) = p.Length = 0
Check.QuickThrowOnFailure prop
This is the conclusion:
Falsifiable, after 2 tests (0 is compressed) (StdGen (1884571966,296370531)): Original: null pattern with exception: System.NullReferenceException ...
And here is the code that I run in LINQPad along with the exit:
open FsCheck
type Pattern = Pattern of string with
static member op_Explicit(Pattern s) = s
type MyArbitraries =
static member Pattern() =
(['a'..'c']@['?'; '*'])
|> Gen.elements
|> Gen.nonEmptyListOf
|> Gen.map (List.map string >> List.fold (+) "")
|> Arb.fromGen
|> Arb.convert Pattern string
Arb.register<MyArbitraries>() |> ignore
let prop (Pattern p) = p.Length = 0
Check.Quick prop
Falsifiable, after 1 test (0 is compressed) (StdGen (1148389153,296370531)): Original: Sample "a *"
, FsCheck null
Pattern
Xunit, Gen.elements
Gen.nonEmptyListOf
. , , , . LINQPad . F # Visual Studio 2017, Arbitrary
, .
? FsCheck string
Arbitrary
Xunit?
, : https://github.com/bert2/GlobMatcher
( Prop.forAll
, Arbitrary
Prop.forAll
, . , , F # Prop.forAll
Arbitrary
.)