FsCheck


Gen

Namespace: FsCheck

Combinators to build custom random generators for any type.

Table of contents

Create generators from generators 

Functions and values

Function or valueDescription
collect f l
Signature: f:('a -> Gen<'b>) -> l:seq<'a> -> Gen<'b list>
Type parameters: 'a, 'b Attributes:
[<CompiledName("CollectToList")>]

Traverse the given enumerable into a generator of a list using the specified binder function to create generators.

CompiledName: CollectToList

collectToSeq f l
Signature: f:('?9890 -> Gen<'?9891>) -> l:seq<'?9890> -> Gen<seq<'?9891>>
Type parameters: '?9890, '?9891 Attributes:
[<CompiledName("Collect")>]

Traverse the given enumerable into a generator of an enumerable using the specified binder function to create generators.

CompiledName: Collect

Creating generators from generators 

Functions and values

Function or valueDescription
collectToArr f xs
Signature: f:('?9895 -> Gen<'?9896>) -> xs:'?9895 array -> Gen<'?9896 []>
Type parameters: '?9895, '?9896 Attributes:
[<CompiledName("CollectToArray")>]

Traverse the given array into a generator of an array using the specified binder function to create generators.

CompiledName: CollectToArray

Other module members 

Functions and values

Function or valueDescription
apply f gn
Signature: f:Gen<('a -> 'b)> -> gn:Gen<'a> -> Gen<'b>
Type parameters: 'a, 'b Attributes:
[<CompiledName("Apply")>]

Apply the given Gen function to the given generator, aka the applicative <*> operator.

CompiledName: Apply

array2DOf(g)
Signature: g:Gen<'a> -> Gen<'a [,]>
Type parameters: 'a Attributes:
[<CompiledName("Array2DOf")>]

Generates a 2D array. The square root of the size is the maximum number of rows and columns.

CompiledName: Array2DOf

array2DOfDim(rows, cols) g
Signature: (rows:int * cols:int) -> g:Gen<'a> -> Gen<'a [,]>
Type parameters: 'a Attributes:
[<CompiledName("Array2DOf")>]

Generates a 2D array of the given dimensions.

CompiledName: Array2DOf

arrayOf(g)
Signature: g:Gen<'a> -> Gen<'a []>
Type parameters: 'a Attributes:
[<CompiledName("ArrayOf")>]

Generates an array using the specified generator. The maximum length is the size+1.

CompiledName: ArrayOf

arrayOfLength n g
Signature: n:int -> g:Gen<'a> -> Gen<'a []>
Type parameters: 'a Attributes:
[<CompiledName("ArrayOf")>]

Generates an array of a specified length.

CompiledName: ArrayOf

choose(l, h)
Signature: (l:int * h:int) -> Gen<int>
Attributes:
[<CompiledName("Choose")>]

Generates an integer between l and h, inclusive.

CompiledName: Choose

constant(v)
Signature: v:'b -> Gen<'b>
Type parameters: 'b Attributes:
[<CompiledName("Constant")>]

Always generate the same instance v. See also fresh.

CompiledName: Constant

elements(xs)
Signature: xs:seq<'a> -> Gen<'a>
Type parameters: 'a Attributes:
[<CompiledName("Elements")>]

Build a generator that randomly generates one of the values in the given non-empty seq.

CompiledName: Elements

elementsArr(values)
Signature: values:'?9815 array -> Gen<'?9815>
Type parameters: '?9815 Attributes:
[<CompiledName("Elements")>]
[<CompilerMessage("This method is not intended for use from F#.", 10001, IsHidden = true, IsError = false)>]

Build a generator that randomly generates one of the values in the given non-empty seq.

CompiledName: Elements

eval size seed arg3
Signature: size:int -> seed:StdGen -> Gen<'b> -> 'b
Type parameters: 'b Attributes:
[<CompiledName("Eval")>]

Generates a value of the give size with the given seed.

CompiledName: Eval

filter predicate generator
Signature: predicate:('a18 -> bool) -> generator:Gen<'a18> -> Gen<'a18>
Type parameters: 'a18 Attributes:
[<CompiledName("Filter")>]

Generates a value that satisfies a predicate. Contrary to tryFilter, this function keeps re-trying by increasing the size of the original generator ad infinitum. Make sure there is a high probability that the predicate is satisfied.

The filter function is an alias for the where function. These two functions are identical, but co-exist so that you can choose the word that makes your code most readable in your given context.

CompiledName: Filter

four(g)
Signature: g:Gen<'b> -> Gen<'b * 'b * 'b * 'b>
Type parameters: 'b Attributes:
[<CompiledName("Four")>]

Build a generator that generates a 4-tuple of the values generated by the given generator.

CompiledName: Four

frequency(xs)
Signature: xs:seq<int * Gen<'a18>> -> Gen<'a18>
Type parameters: 'a18 Attributes:
[<CompiledName("Frequency")>]

Build a generator that generates a value from one of the generators in the given non-empty seq, with given probabilities. The sum of the probabilities must be larger than zero.

CompiledName: Frequency

frequencySeqWeightAndValue(...)
Signature: weightedValues:seq<WeightAndValue<Gen<'a>>> -> Gen<'a>
Type parameters: 'a Attributes:
[<CompiledName("Frequency")>]
[<CompilerMessage("This method is not intended for use from F#.", 10001, IsHidden = true, IsError = false)>]

Build a generator that generates a value from one of the generators in the given non-empty seq, with given probabilities. The sum of the probabilities must be larger than zero.

CompiledName: Frequency

frequencyTupleArr(weightedValues)
Signature: weightedValues:(int * Gen<'a>) [] -> Gen<'a>
Type parameters: 'a Attributes:
[<CompiledName("Frequency")>]
[<CompilerMessage("This method is not intended for use from F#.", 10001, IsHidden = true, IsError = false)>]

Build a generator that generates a value from one of the generators in the given non-empty seq, with given probabilities. The sum of the probabilities must be larger than zero.

CompiledName: Frequency

frequencyWeightAndValueArr(...)
Signature: weightedValues:WeightAndValue<Gen<'a>> [] -> Gen<'a>
Type parameters: 'a Attributes:
[<CompiledName("Frequency")>]
[<CompilerMessage("This method is not intended for use from F#.", 10001, IsHidden = true, IsError = false)>]

Build a generator that generates a value from one of the generators in the given non-empty seq, with given probabilities. The sum of the probabilities must be larger than zero.

CompiledName: Frequency

fresh(fv)
Signature: fv:(unit -> '?9797) -> Gen<'?9797>
Type parameters: '?9797 Attributes:
[<CompiledName("Fresh")>]

Generate a fresh instance every time the generator is called. Useful for mutable objects. See also constant.

CompiledName: Fresh

freshFunc(fv)
Signature: fv:Func<'?9799> -> Gen<'?9799>
Type parameters: '?9799 Attributes:
[<CompiledName("Fresh")>]
[<CompilerMessage("This method is not intended for use from F#.", 10001, IsHidden = true, IsError = false)>]

Generate a fresh instance every time the generatoris called. Useful for mutable objects. See also constant.

CompiledName: Fresh

growingElements(xs)
Signature: xs:seq<'?9819> -> Gen<'?9819>
Type parameters: '?9819 Attributes:
[<CompiledName("GrowingElements")>]

Build a generator that takes a non-empty sequence and randomly generates one of the values among an initial segment of that sequence. The size of this initial segment increases with the size parameter. Essentially this generator is Gen.elements but taking also the runtime size into account.

CompiledName: GrowingElements

listOf(gn)
Signature: gn:Gen<'a> -> Gen<'a list>
Type parameters: 'a Attributes:
[<CompiledName("ListOf")>]

Generates a list of random length. The maximum length depends on the size parameter.

CompiledName: ListOf

listOfLength n arb
Signature: n:int -> arb:Gen<'a18> -> Gen<'a18 list>
Type parameters: 'a18 Attributes:
[<CompiledName("ListOf")>]

Generates a list of given length, containing values generated by the given generator.

CompiledName: ListOf

map f gen
Signature: f:('a -> 'b) -> gen:Gen<'a> -> Gen<'b>
Type parameters: 'a, 'b Attributes:
[<CompiledName("Map")>]

Apply the function f to the value in the generator, yielding a new generator.

CompiledName: Map

map2 f a b
Signature: f:('c -> 'd -> 'e) -> a:Gen<'c> -> b:Gen<'d> -> Gen<'e>
Type parameters: 'c, 'd, 'e Attributes:
[<CompiledName("Map2")>]

Map the given function over values to a function over generators of those values.

CompiledName: Map2

map3 f a b c
Signature: f:('a18 -> 'a19 -> 'a20 -> 'a21) -> a:Gen<'a18> -> b:Gen<'a19> -> c:Gen<'a20> -> Gen<'a21>
Type parameters: 'a18, 'a19, 'a20, 'a21 Attributes:
[<CompiledName("Map3")>]

Map the given function over values to a function over generators of those values.

CompiledName: Map3

map4 f a b c d
Signature: f:('?9848 -> '?9849 -> '?9850 -> '?9851 -> '?9852) -> a:Gen<'?9848> -> b:Gen<'?9849> -> c:Gen<'?9850> -> d:Gen<'?9851> -> Gen<'?9852>
Type parameters: '?9848, '?9849, '?9850, '?9851, '?9852 Attributes:
[<CompiledName("Map4")>]

Map the given function over values to a function over generators of those values.

CompiledName: Map4

map5 f a b c d e
Signature: f:('a18 -> 'a19 -> 'a20 -> 'a21 -> 'a22 -> 'a23) -> a:Gen<'a18> -> b:Gen<'a19> -> c:Gen<'a20> -> d:Gen<'a21> -> e:Gen<'a22> -> Gen<'a23>
Type parameters: 'a18, 'a19, 'a20, 'a21, 'a22, 'a23 Attributes:
[<CompiledName("Map5")>]

Map the given function over values to a function over generators of those values.

CompiledName: Map5

map6 f a b c d e g
Signature: f:('?9863 -> '?9864 -> '?9865 -> '?9866 -> '?9867 -> '?9868 -> '?9869) -> a:Gen<'?9863> -> b:Gen<'?9864> -> c:Gen<'?9865> -> d:Gen<'?9866> -> e:Gen<'?9867> -> g:Gen<'?9868> -> Gen<'?9869>
Type parameters: '?9863, '?9864, '?9865, '?9866, '?9867, '?9868, '?9869 Attributes:
[<CompiledName("Map6")>]

Map the given function over values to a function over generators of those values.

CompiledName: Map6

nonEmptyListOf(gn)
Signature: gn:Gen<'b> -> Gen<'b list>
Type parameters: 'b Attributes:
[<CompiledName("NonEmptyListOf")>]

Generates a non-empty list of random length. The maximum length depends on the size parameter.

CompiledName: NonEmptyListOf

oneof(gens)
Signature: gens:seq<Gen<'a>> -> Gen<'a>
Type parameters: 'a Attributes:
[<CompiledName("OneOf")>]

Build a generator that generates a value from one of the generators in the given non-empty seq, with equal probability.

CompiledName: OneOf

oneOfArr(generators)
Signature: generators:Gen<'?9823> array -> Gen<'?9823>
Type parameters: '?9823 Attributes:
[<CompiledName("OneOf")>]
[<CompilerMessage("This method is not intended for use from F#.", 10001, IsHidden = true, IsError = false)>]

Build a generator that generates a value from one of the given generators, with equal probability.

CompiledName: OneOf

optionOf(g)
Signature: g:Gen<'b> -> Gen<'b option>
Type parameters: 'b

Generate an option value that is 'None' 1/8 of the time.

piles k sum
Signature: k:int -> sum:int -> Gen<int []>
Attributes:
[<CompiledName("Piles")>]

Generates a random array of length k where the sum of all elements equals the given sum.

CompiledName: Piles

resize newSize arg2
Signature: newSize:int -> Gen<'b> -> Gen<'b>
Type parameters: 'b Attributes:
[<CompiledName("Resize")>]

Override the current size of the test. resize n g invokes generator g with size parameter n.

CompiledName: Resize

sample size n generator
Signature: size:int -> n:int -> generator:Gen<'b> -> 'b list
Type parameters: 'b Attributes:
[<CompiledName("Sample")>]

Generates n values of the given size.

CompiledName: Sample

sequence(l)
Signature: l:seq<Gen<'?9888>> -> Gen<'?9888 list>
Type parameters: '?9888 Attributes:
[<CompiledName("SequenceToList")>]

Sequence the given enumerable of generators into a generator of a list.

CompiledName: SequenceToList

sequenceToArr(generators)
Signature: generators:Gen<'b> array -> Gen<'b []>
Type parameters: 'b Attributes:
[<CompiledName("Sequence")>]

Sequence the given array of generators into a generator of an array.

CompiledName: Sequence

sequenceToSeq(generators)
Signature: generators:seq<Gen<'?9893>> -> Gen<seq<'?9893>>
Type parameters: '?9893 Attributes:
[<CompiledName("Sequence")>]

Sequence the given enumerable of generators into a generator of an enumerable.

CompiledName: Sequence

shuffle(xs)
Signature: xs:seq<'?9904> -> Gen<'?9904 array>
Type parameters: '?9904 Attributes:
[<CompiledName("Shuffle")>]

Generates a random permutation of the given sequence.

CompiledName: Shuffle

sized(fgen)
Signature: fgen:(int -> Gen<'b>) -> Gen<'b>
Type parameters: 'b Attributes:
[<CompiledName("Sized")>]

Obtain the current size. sized g calls g, passing it the current size as a parameter.

CompiledName: Sized

sizedFunc(sizedGen)
Signature: sizedGen:Func<int,Gen<'?9806>> -> Gen<'?9806>
Type parameters: '?9806 Attributes:
[<CompiledName("Sized")>]
[<CompilerMessage("This method is not intended for use from F#.", 10001, IsHidden = true, IsError = false)>]

Obtain the current size. sized g calls g, passing it the current size as a parameter.

CompiledName: Sized

subListOf(l)
Signature: l:seq<'?9923> -> Gen<'?9923 list>
Type parameters: '?9923 Attributes:
[<CompiledName("SubListOfToList")>]

Generates sublists of the given sequence.

CompiledName: SubListOfToList

subListOfArr(s)
Signature: s:'?9927 array -> Gen<IList<'?9927>>
Type parameters: '?9927 Attributes:
[<CompiledName("SubListOf")>]
[<CompilerMessage("This method is not intended for use from F#.", 10001, IsHidden = true, IsError = false)>]

Generates sublists of the given arguments.

CompiledName: SubListOf

subListOfToIList(s)
Signature: s:seq<'?9925> -> Gen<IList<'?9925>>
Type parameters: '?9925 Attributes:
[<CompiledName("SubListOf")>]
[<CompilerMessage("This method is not intended for use from F#.", 10001, IsHidden = true, IsError = false)>]

Generates sublists of the given IEnumerable.

CompiledName: SubListOf

suchThat
Signature: ('?9916 -> bool) -> Gen<'?9916> -> Gen<'?9916>
Type parameters: '?9916 Attributes:
[<Obsolete("This function will be removed in a future version of FsCheck. Please use the synonyms where or filter instead.")>]
[<CompiledName("SuchThat")>]
WARNING: This API is obsolete

This function will be removed in a future version of FsCheck. Please use the synonyms where or filter instead.

Generates a value that satisfies a predicate. Contrary to suchThatOption, this function keeps re-trying by increasing the size of the original generator ad infinitum. Make sure there is a high probability that the predicate is satisfied.

CompiledName: SuchThat

suchThatOption
Signature: ('?9910 -> bool) -> Gen<'?9910> -> Gen<'?9910 option>
Type parameters: '?9910 Attributes:
[<Obsolete("This function will be removed in a future version of FsCheck. Please use the synonyms tryWhere or tryFilter instead.")>]
[<CompiledName("SuchThatOption")>]
[<EditorBrowsable(1)>]
WARNING: This API is obsolete

This function will be removed in a future version of FsCheck. Please use the synonyms tryWhere or tryFilter instead.

Tries to generate a value that satisfies a predicate. This function 'gives up' by generating None if the given original generator did not generate any values that satisfied the predicate, after trying to get values by increasing its size.

CompiledName: SuchThatOption

three(g)
Signature: g:Gen<'b> -> Gen<'b * 'b * 'b>
Type parameters: 'b Attributes:
[<CompiledName("Three")>]

Build a generator that generates a 3-tuple of the values generated by the given generator.

CompiledName: Three

tryFilter predicate generator
Signature: predicate:('?9908 -> bool) -> generator:Gen<'?9908> -> Gen<'?9908 option>
Type parameters: '?9908 Attributes:
[<CompiledName("TryFilter")>]

Tries to generate a value that satisfies a predicate. This function 'gives up' by generating None if the given original generator did not generate any values that satisfied the predicate, after trying to get values by increasing its size.

The tryFilter function is an alias for the tryWhere function. These two functions are identical, but co-exist so that you can choose the word that makes your code most readable in your given context.

CompiledName: TryFilter

tryWhere predicate generator
Signature: predicate:('a -> bool) -> generator:Gen<'a> -> Gen<'a option>
Type parameters: 'a Attributes:
[<CompiledName("TryWhere")>]

Tries to generate a value that satisfies a predicate. This function 'gives up' by generating None if the given original generator did not generate any values that satisfied the predicate, after trying to get values by increasing its size.

The tryWhere function is also aliased as tryFilter. These two functions are identical, but co-exist so that you can choose the word that makes your code most readable in your given context.

CompiledName: TryWhere

two(g)
Signature: g:Gen<'a18> -> Gen<'a18 * 'a18>
Type parameters: 'a18 Attributes:
[<CompiledName("Two")>]

Build a generator that generates a 2-tuple of the values generated by the given generator.

CompiledName: Two

unzip(g)
Signature: g:Gen<'?9878 * '?9879> -> Gen<'?9878> * Gen<'?9879>
Type parameters: '?9878, '?9879

Split a generator of pairs into a pair of generators.

unzip3(g)
Signature: g:Gen<'?9881 * '?9882 * '?9883> -> Gen<'?9881> * Gen<'?9882> * Gen<'?9883>
Type parameters: '?9881, '?9882, '?9883

Split a generator of 3-tuples into a 3-tuple of generators.

where predicate generator
Signature: predicate:('b -> bool) -> generator:Gen<'b> -> Gen<'b>
Type parameters: 'b Attributes:
[<CompiledName("Where")>]

Generates a value that satisfies a predicate. Contrary to tryWhere, this function keeps re-trying by increasing the size of the original generator ad infinitum. Make sure there is a high probability that the predicate is satisfied.

The where function is also aliased as filter. These two functions are identical, but co-exist so that you can choose the word that makes your code most readable in your given context.

CompiledName: Where

zip f g
Signature: f:Gen<'c> -> g:Gen<'d> -> Gen<'c * 'd>
Type parameters: 'c, 'd

Combine two generators into a generator of pairs.

zip3 f g h
Signature: f:Gen<'d> -> g:Gen<'e> -> h:Gen<'f> -> Gen<'d * 'e * 'f>
Type parameters: 'd, 'e, 'f

Combine three generators into a generator of 3-tuples.

Fork me on GitHub