FsCheck


Gen Module

Namespace: FsCheck.FSharp

Assembly: FsCheck.dll

Table of contents

Other module members

Functions and values

Function or value Description

Gen.apply arg1 arg2

Full Usage: Gen.apply arg1 arg2

Parameters:
    arg0 : Gen<('T -> 'U)>
    arg1 : Gen<'T>

Returns: Gen<'U>

Apply the functions f from the first generator to the values from the second generator pairwise, yielding a new generator that generates the results.

arg0 : Gen<('T -> 'U)>
arg1 : Gen<'T>
Returns: Gen<'U>

Gen.array2DOf gen

Full Usage: Gen.array2DOf gen

Parameters:
    gen : Gen<'T>

Returns: Gen<'T[,]>

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

gen : Gen<'T>
Returns: Gen<'T[,]>

Gen.array2DOfDim rows cols gen

Full Usage: Gen.array2DOfDim rows cols gen

Parameters:
    rows : int
    cols : int
    gen : Gen<'T>

Returns: Gen<'T[,]>

Generates 2D arrays of the given dimensions.

rows : int
cols : int
gen : Gen<'T>
Returns: Gen<'T[,]>

Gen.arrayOf gen

Full Usage: Gen.arrayOf gen

Parameters:
    gen : Gen<'T>

Returns: Gen<'T[]>

Generates arrays of random length between zero and size.

gen : Gen<'T>
Returns: Gen<'T[]>

Gen.arrayOfLength length gen

Full Usage: Gen.arrayOfLength length gen

Parameters:
    length : int
    gen : Gen<'T>

Returns: Gen<'T[]>

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

length : int
gen : Gen<'T>
Returns: Gen<'T[]>

Gen.bind k arg2

Full Usage: Gen.bind k arg2

Parameters:
    k : 'T -> Gen<'U>
    arg1 : Gen<'T>

Returns: Gen<'U>

Creates a new generator that generates values from the source generator, applies the function k to them, and generates values from the resulting generator.

k : 'T -> Gen<'U>
arg1 : Gen<'T>
Returns: Gen<'U>

Gen.choose (l, h)

Full Usage: Gen.choose (l, h)

Parameters:
    l : int
    h : int

Returns: Gen<int>

Generates ints between l and h, inclusive.

l : int
h : int
Returns: Gen<int>

Gen.choose64 (l, h)

Full Usage: Gen.choose64 (l, h)

Parameters:
    l : int64
    h : int64

Returns: Gen<int64>

Generates int64 between l and h, inclusive.

l : int64
h : int64
Returns: Gen<int64>

Gen.constant value

Full Usage: Gen.constant value

Parameters:
    value : 'T

Returns: Gen<'T>

Always generate the same given value. See also fresh.

value : 'T
Returns: Gen<'T>

Gen.elements xs

Full Usage: Gen.elements xs

Parameters:
    xs : seq<'T>

Returns: Gen<'T>

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

xs : seq<'T>
Returns: Gen<'T>

Gen.filter predicate generator

Full Usage: Gen.filter predicate generator

Parameters:
    predicate : 'T -> bool
    generator : Gen<'T>

Returns: Gen<'T>

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.

predicate : 'T -> bool
generator : Gen<'T>
Returns: Gen<'T>

Gen.four g

Full Usage: Gen.four g

Parameters:
Returns: Gen<'T * 'T * 'T * 'T>

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

g : Gen<'T>
Returns: Gen<'T * 'T * 'T * 'T>

Gen.frequency dist

Full Usage: Gen.frequency dist

Parameters:
    dist : seq<int * Gen<'T>> - Sequence of tuples where each tuple contains a weight and a generator.

Returns: Gen<'T>

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.

dist : seq<int * Gen<'T>>

Sequence of tuples where each tuple contains a weight and a generator.

Returns: Gen<'T>
ArgumentException Thrown if the sum of the probabilities is less than or equal to 0.

Gen.fresh create

Full Usage: Gen.fresh create

Parameters:
    create : unit -> 'T

Returns: Gen<'T>

Generate fresh instances by calling create every time the generator generates a new value. Useful for generating new instances of mutable objects. See also constant.

create : unit -> 'T
Returns: Gen<'T>

Gen.growingElements xs

Full Usage: Gen.growingElements xs

Parameters:
    xs : seq<'T>

Returns: Gen<'T>

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 size into account.

xs : seq<'T>
Returns: Gen<'T>

Gen.listOf gen

Full Usage: Gen.listOf gen

Parameters:
    gen : Gen<'T>

Returns: Gen<'T list>

Generates lists of random lengths between zero and size.

gen : Gen<'T>
Returns: Gen<'T list>

Gen.listOfLength length gen

Full Usage: Gen.listOfLength length gen

Parameters:
    length : int
    gen : Gen<'T>

Returns: Gen<'T list>

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

length : int
gen : Gen<'T>
Returns: Gen<'T list>

Gen.map f arg2

Full Usage: Gen.map f arg2

Parameters:
    f : 'T -> 'U
    arg1 : Gen<'T>

Returns: Gen<'U>

Create a new generator by applying f to each value in the given generator.

f : 'T -> 'U
arg1 : Gen<'T>
Returns: Gen<'U>

Gen.map2 f arg2 arg3

Full Usage: Gen.map2 f arg2 arg3

Parameters:
    f : 'a -> 'b -> 'c
    arg1 : Gen<'a>
    arg2 : Gen<'b>

Returns: Gen<'c>

Create a new generator by applying f to each value in the given generators.

f : 'a -> 'b -> 'c
arg1 : Gen<'a>
arg2 : Gen<'b>
Returns: Gen<'c>

Gen.map3 f arg2 arg3 arg4

Full Usage: Gen.map3 f arg2 arg3 arg4

Parameters:
    f : 'a -> 'b -> 'c -> 'd
    arg1 : Gen<'a>
    arg2 : Gen<'b>
    arg3 : Gen<'c>

Returns: Gen<'d>

Create a new generator by applying f to each value in the given generators.

f : 'a -> 'b -> 'c -> 'd
arg1 : Gen<'a>
arg2 : Gen<'b>
arg3 : Gen<'c>
Returns: Gen<'d>

Gen.map4 f arg2 arg3 arg4 arg5

Full Usage: Gen.map4 f arg2 arg3 arg4 arg5

Parameters:
    f : 'a -> 'b -> 'c -> 'd -> 'e
    arg1 : Gen<'a>
    arg2 : Gen<'b>
    arg3 : Gen<'c>
    arg4 : Gen<'d>

Returns: Gen<'e>

Create a new generator by applying f to each value in the given generators.

f : 'a -> 'b -> 'c -> 'd -> 'e
arg1 : Gen<'a>
arg2 : Gen<'b>
arg3 : Gen<'c>
arg4 : Gen<'d>
Returns: Gen<'e>

Gen.map5 f arg2 arg3 arg4 arg5 arg6

Full Usage: Gen.map5 f arg2 arg3 arg4 arg5 arg6

Parameters:
    f : 'a -> 'b -> 'c -> 'd -> 'e -> 'f
    arg1 : Gen<'a>
    arg2 : Gen<'b>
    arg3 : Gen<'c>
    arg4 : Gen<'d>
    arg5 : Gen<'e>

Returns: Gen<'f>

Create a new generator by applying f to each value in the given generators.

f : 'a -> 'b -> 'c -> 'd -> 'e -> 'f
arg1 : Gen<'a>
arg2 : Gen<'b>
arg3 : Gen<'c>
arg4 : Gen<'d>
arg5 : Gen<'e>
Returns: Gen<'f>

Gen.map6 f arg2 arg3 arg4 arg5 arg6 arg7

Full Usage: Gen.map6 f arg2 arg3 arg4 arg5 arg6 arg7

Parameters:
    f : 'a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g
    arg1 : Gen<'a>
    arg2 : Gen<'b>
    arg3 : Gen<'c>
    arg4 : Gen<'d>
    arg5 : Gen<'e>
    arg6 : Gen<'f>

Returns: Gen<'g>

Create a new generator by applying f to each value in the given generators.

f : 'a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g
arg1 : Gen<'a>
arg2 : Gen<'b>
arg3 : Gen<'c>
arg4 : Gen<'d>
arg5 : Gen<'e>
arg6 : Gen<'f>
Returns: Gen<'g>

Gen.nonEmptyListOf gen

Full Usage: Gen.nonEmptyListOf gen

Parameters:
    gen : Gen<'T>

Returns: Gen<'T list>

Generates non-empty lists of random lengths between zero and size.

gen : Gen<'T>
Returns: Gen<'T list>

Gen.oneof gens

Full Usage: Gen.oneof gens

Parameters:
    gens : seq<Gen<'T>>

Returns: Gen<'T>

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

gens : seq<Gen<'T>>
Returns: Gen<'T>

Gen.optionOf g

Full Usage: Gen.optionOf g

Parameters:
Returns: Gen<'T option>

Generates option values that are 'None' 1/8 of the time.

g : Gen<'T>
Returns: Gen<'T option>

Gen.piles length sum

Full Usage: Gen.piles length sum

Parameters:
    length : int
    sum : int

Returns: Gen<int[]>

Generates random arrays of given length where the sum of all elements equals the given sum.

length : int
sum : int
Returns: Gen<int[]>

Gen.resize newSize arg2

Full Usage: Gen.resize newSize arg2

Parameters:
    newSize : int
    arg1 : Gen<'T>

Returns: Gen<'T>

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

newSize : int
arg1 : Gen<'T>
Returns: Gen<'T>

Gen.sample nbSamples gen

Full Usage: Gen.sample nbSamples gen

Parameters:
    nbSamples : int
    gen : Gen<'T>

Returns: 'T[]

Generates a given number of values with a new seed and a size of 50.

nbSamples : int
gen : Gen<'T>
Returns: 'T[]

Gen.sampleWithSeed seed size nbSamples arg4

Full Usage: Gen.sampleWithSeed seed size nbSamples arg4

Parameters:
    seed : Rnd
    size : int
    nbSamples : int
    arg3 : Gen<'T>

Returns: 'T[]

Generates n values of the given size and starting with the given seed.

seed : Rnd
size : int
nbSamples : int
arg3 : Gen<'T>
Returns: 'T[]

Gen.sampleWithSize size nbSamples gen

Full Usage: Gen.sampleWithSize size nbSamples gen

Parameters:
    size : int
    nbSamples : int
    gen : Gen<'T>

Returns: 'T[]

Generates a given number of values with a new seed and a given size.

size : int
nbSamples : int
gen : Gen<'T>
Returns: 'T[]

Gen.scaleSize f g

Full Usage: Gen.scaleSize f g

Parameters:
    f : int -> int
    g : Gen<'T>

Returns: Gen<'T>

Modify a size using the given function before passing it to the given Gen.

f : int -> int
g : Gen<'T>
Returns: Gen<'T>

Gen.sequenceToArray source

Full Usage: Gen.sequenceToArray source

Parameters:
    source : seq<Gen<'T>>

Returns: Gen<'T[]>

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

source : seq<Gen<'T>>
Returns: Gen<'T[]>

Gen.sequenceToList source

Full Usage: Gen.sequenceToList source

Parameters:
    source : seq<Gen<'T>>

Returns: Gen<'T list>

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

source : seq<Gen<'T>>
Returns: Gen<'T list>

Gen.sequenceToSeq source

Full Usage: Gen.sequenceToSeq source

Parameters:
    source : seq<Gen<'T>>

Returns: Gen<seq<'T>>

Sequence the given seq of generators into a generator of a seq. Each seq generated by the resulting generator can be infinite, if the source seq is infinite.

source : seq<Gen<'T>>
Returns: Gen<seq<'T>>

Gen.shuffle xs

Full Usage: Gen.shuffle xs

Parameters:
    xs : seq<'T>

Returns: Gen<'T array>

Generates random permutations of the given sequence.

xs : seq<'T>
Returns: Gen<'T array>

Gen.sized gen

Full Usage: Gen.sized gen

Parameters:
    gen : int -> Gen<'T>

Returns: Gen<'T>

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

gen : int -> Gen<'T>
Returns: Gen<'T>

Gen.subListOf lst

Full Usage: Gen.subListOf lst

Parameters:
    lst : seq<'T>

Returns: Gen<'T list>

Generates sublists of the given seq. For a given list of length n, each sublist has between 0 and n elements, and the order of the elements is the same as in the given seq.

lst : seq<'T>
Returns: Gen<'T list>

Gen.three g

Full Usage: Gen.three g

Parameters:
Returns: Gen<'T * 'T * 'T>

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

g : Gen<'T>
Returns: Gen<'T * 'T * 'T>

Gen.tryFilter predicate generator

Full Usage: Gen.tryFilter predicate generator

Parameters:
    predicate : 'T -> bool
    generator : Gen<'T>

Returns: Gen<'T option>

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.

predicate : 'T -> bool
generator : Gen<'T>
Returns: Gen<'T option>

Gen.tryWhere predicate generator

Full Usage: Gen.tryWhere predicate generator

Parameters:
    predicate : 'T -> bool
    generator : Gen<'T>

Returns: Gen<'T option>

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.

predicate : 'T -> bool
generator : Gen<'T>
Returns: Gen<'T option>

Gen.two g

Full Usage: Gen.two g

Parameters:
Returns: Gen<'T * 'T>

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

g : Gen<'T>
Returns: Gen<'T * 'T>

Gen.where predicate generator

Full Usage: Gen.where predicate generator

Parameters:
    predicate : 'T -> bool
    generator : Gen<'T>

Returns: Gen<'T>

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.

predicate : 'T -> bool
generator : Gen<'T>
Returns: Gen<'T>

Gen.zip f g

Full Usage: Gen.zip f g

Parameters:
Returns: Gen<'T1 * 'T2>

Combine two generators into a generator of pairs.

f : Gen<'T1>
g : Gen<'T2>
Returns: Gen<'T1 * 'T2>

Gen.zip3 f g h

Full Usage: Gen.zip3 f g h

Parameters:
Returns: Gen<'T1 * 'T2 * 'T3>

Combine three generators into a generator of 3-tuples.

f : Gen<'T1>
g : Gen<'T2>
h : Gen<'T3>
Returns: Gen<'T1 * 'T2 * 'T3>

Create generators from generators

Functions and values

Function or value Description

Gen.collectToList f source

Full Usage: Gen.collectToList f source

Parameters:
    f : 'T -> Gen<'U>
    source : seq<'T>

Returns: Gen<'U list>

Traverse the given enumerable into a generator of a list using the specified binder function to create generators. [category: Create generators from generators]

f : 'T -> Gen<'U>
source : seq<'T>
Returns: Gen<'U list>

Gen.collectToSeq f source

Full Usage: Gen.collectToSeq f source

Parameters:
    f : 'T -> Gen<'U>
    source : seq<'T>

Returns: Gen<seq<'U>>

Traverse the given enumerable into a generator of an enumerable using the specified binder function to create generators. Each seq generated by the resulting generator can be infinite, if the source seq is infinite. [category: Create generators from generators]

f : 'T -> Gen<'U>
source : seq<'T>
Returns: Gen<seq<'U>>

Creating generators from generators

Functions and values

Function or value Description

Gen.collectToArray f source

Full Usage: Gen.collectToArray f source

Parameters:
    f : 'T -> Gen<'U>
    source : seq<'T>

Returns: Gen<'U[]>

Traverse the given array into a generator of an array using the specified binder function to create generators. [category: Creating generators from generators]

f : 'T -> Gen<'U>
source : seq<'T>
Returns: Gen<'U[]>