Custom FsCheck An arbitrary type broken in Xunit but working in LINQPad and the regular F # program

I am trying to implement a custom Arbitraryone 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 Patternto 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.)

+4
1

Arb.register. , parallelism xUnit.net 2 , .

FsCheck.Xunit Glue Library, Prop.forAll, :

[<Fact>]
let test () = 
    let prop (Pattern p) = p.Length = 0
    Check.QuickThrowOnFailure (Prop.forAll (MyArbitraries.Pattern()) prop)

( , , , , , , , .)


, , FsCheck.Xunit, Property, :

[<Property(Arbitrary = [|typeof<MyArbitraries>|])>]
let test (Pattern p) = p.Length = 0

, ; Check.QuickThrowOnFailure.

Arbitrary , , , .

Arbitraries, , [<Property>]. :

type Letters =
    static member Char() =
        Arb.Default.Char()
        |> Arb.filter (fun c -> 'A' <= c && c <= 'Z')

type DiamondPropertyAttribute() =
    inherit PropertyAttribute(
        Arbitrary = [| typeof<Letters> |],
        QuietOnSuccess = true)

[<DiamondProperty>]
let ``Diamond is non-empty`` (letter : char) =
    let actual = Diamond.make letter
    not (String.IsNullOrWhiteSpace actual)

, , "" . combinator, , .

+2

Source: https://habr.com/ru/post/1688484/


All Articles