Skip to content

Commit

Permalink
Fix #380.
Browse files Browse the repository at this point in the history
  • Loading branch information
kurtschelfthout committed Aug 28, 2017
1 parent fabde1a commit ceb7da7
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/FsCheck/ReflectArbitrary.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module internal ReflectArbitrary =
open Microsoft.FSharp.Reflection
open Reflect
open Gen
open Gen

let inline private orElems<'a when 'a : (static member (|||) : 'a * 'a -> 'a) and 'a : (static member Zero : 'a)>
t
Expand Down Expand Up @@ -52,10 +53,12 @@ module internal ReflectArbitrary =
Seq.empty

fieldType = containingType
|| seen.Contains(fieldType.AssemblyQualifiedName)
|| (let fields = children fieldType
let newSeen = seen.Add fieldType.AssemblyQualifiedName
fields |> Seq.exists (fun field -> isRecursive field containingType newSeen))
|| (if seen.Contains(fieldType.AssemblyQualifiedName) then
false
else
let fields = children fieldType
let newSeen = seen.Add fieldType.AssemblyQualifiedName
fields |> Seq.exists (fun field -> isRecursive field containingType newSeen))

let productGen (ts : seq<Type>) create =
let gs = [| for t in ts -> getGenerator t |]
Expand Down
62 changes: 61 additions & 1 deletion tests/FsCheck.Test/Gen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,64 @@ module Gen =
let r1 = Gen.sample 100 100 (Arb.Default.Derive<MyRecord>().Generator)
let r2 = Gen.sample 100 100 (Arb.Default.Derive<MyUnion>().Generator)
let r3 = Gen.sample 100 100 (Arb.Default.Derive<MyOtherUnion>().Generator)
test <@ r1.Length + r2.Length + r3.Length = 300 @>
test <@ r1.Length + r2.Length + r3.Length = 300 @>


// these types were taking from the FSharpLu project, as there was some regression
// when these types, or a subset of them, was generated.

type WithFields = SomeField of int * int
type SimpleDu = Foo | FooBar | Bar
type ComplexDu = ComplexDu of WithFields | SimpleDU | AString of string
type 'a RecursiveList = RecListLeaf of 'a | RecListCons of 'a RecursiveList
type OptionOfBase = int option
type OptionOfDu = SimpleDu option
type Color = Red | Blue
type Shape = Circle of int * int | Rectangle
type 'a Tree = Leaf of 'a | Node of 'a Tree * 'a Tree
type 'a Test = Case1 | Case2 of int | Case3 of int * string * 'a
type MapType = Map<string,Color>
type 'a NestedOptions = 'a option option option option

type 'a Wrapper = { WrappedField : 'a }
type NestedStructure = { subField : int }
type NestedOptionStructure = { field : NestedStructure option }

module SomeAmbiguity =
type 'a RecordWithFieldNamedSome = { Some : 'a }
type DUWithFieldlessCaseNamedSome = Some of string | Bla
type DUWithCaseWithFieldNamedSome = Some | Bla
type 'a Ambiguous1 = 'a RecordWithFieldNamedSome option
type Ambiguous2 = DUWithFieldlessCaseNamedSome option
type Ambiguous3 = DUWithCaseWithFieldNamedSome option


[<Fact>]
let ``generate FSharpLu test types``() =
let size = 25
let times = 10000
let r = Gen.sample size times Arb.generate<ComplexDu>
let r = Gen.sample size times Arb.generate<ComplexDu RecursiveList>
let r = Gen.sample size times Arb.generate<WithFields>
let r = Gen.sample size times Arb.generate<SimpleDu>
let r = Gen.sample size times Arb.generate<ComplexDu>
let r = Gen.sample size times Arb.generate<OptionOfBase>
let r = Gen.sample size times Arb.generate<OptionOfDu>
let r = Gen.sample size times Arb.generate<Color>
let r = Gen.sample size times Arb.generate<Shape>
let r = Gen.sample size times Arb.generate<int Tree>
let r = Gen.sample size times Arb.generate<int Tree Test>
let r = Gen.sample size times Arb.generate<int Test>
let r = Gen.sample size times Arb.generate<int list Tree>
let r = Gen.sample size times Arb.generate<string NestedOptions>
let r = Gen.sample size times Arb.generate<string>
let r = Gen.sample size times Arb.generate<string option>
let r = Gen.sample size times Arb.generate<string option option>
let r = Gen.sample size times Arb.generate<string option option option option>
let r = Gen.sample size times Arb.generate<int NestedOptions>
let r = Gen.sample size times Arb.generate<SomeAmbiguity.Ambiguous1<string>>
let r = Gen.sample size times Arb.generate<SomeAmbiguity.Ambiguous1<SimpleDu>>
let r = Gen.sample size times Arb.generate<NestedOptionStructure>
let r = Gen.sample size times Arb.generate<SomeAmbiguity.Ambiguous2>
let r = Gen.sample size times Arb.generate<SomeAmbiguity.Ambiguous3>
()

0 comments on commit ceb7da7

Please sign in to comment.