FsCheck


Gen Module

Namespace: FsCheck

Assembly: FsCheck.dll

Combinators to build custom random generators for any type.

Table of contents

Other module members

Functions and values

Function or value Description

apply f gn

Full Usage: apply f gn

Parameters:
    f : Gen<('a -> 'b)>
    gn : Gen<'a>

Returns: Gen<'b>

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

f : Gen<('a -> 'b)>
gn : Gen<'a>
Returns: Gen<'b>

array2DOf g

Full Usage: array2DOf g

Parameters:
Returns: Gen<'a[,]>

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

g : Gen<'a>
Returns: Gen<'a[,]>

array2DOfDim (rows, cols) g

Full Usage: array2DOfDim (rows, cols) g

Parameters:
    rows : int
    cols : int
    g : Gen<'a>

Returns: Gen<'a[,]>

Generates a 2D array of the given dimensions.

rows : int
cols : int
g : Gen<'a>
Returns: Gen<'a[,]>

arrayOf g

Full Usage: arrayOf g

Parameters:
Returns: Gen<'a[]>

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

g : Gen<'a>
Returns: Gen<'a[]>

arrayOfLength n g

Full Usage: arrayOfLength n g

Parameters:
    n : int
    g : Gen<'a>

Returns: Gen<'a[]>

Generates an array of a specified length.

n : int
g : Gen<'a>
Returns: Gen<'a[]>

choose (l, h)

Full Usage: choose (l, h)

Parameters:
    l : int
    h : int

Returns: Gen<int>

Generates an integer between l and h, inclusive.

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

constant v

Full Usage: constant v

Parameters:
    v : 'b

Returns: Gen<'b>

Always generate the same instance v. See also fresh.

v : 'b
Returns: Gen<'b>

elements xs

Full Usage: elements xs

Parameters:
    xs : seq<'b>

Returns: Gen<'b>

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

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

elementsArr values

Full Usage: elementsArr values

Parameters:
    values : 'a array

Returns: Gen<'a>

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

values : 'a array
Returns: Gen<'a>

eval size seed arg3

Full Usage: eval size seed arg3

Parameters:
Returns: 'b

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

size : int
seed : StdGen
arg2 : Gen<'b>
Returns: 'b

filter predicate generator

Full Usage: filter predicate generator

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

Returns: Gen<'a18>

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 : 'a18 -> bool
generator : Gen<'a18>
Returns: Gen<'a18>

four g

Full Usage: four g

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

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

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

frequency xs

Full Usage: frequency xs

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

Returns: Gen<'a18>

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.

xs : seq<int * Gen<'a18>>

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

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

frequencySeqWeightAndValue weightedValues

Full Usage: frequencySeqWeightAndValue weightedValues

Parameters:
Returns: Gen<'a>

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.

weightedValues : seq<WeightAndValue<Gen<'a>>>

Sequence of weighted generators.

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

frequencyTupleArr weightedValues

Full Usage: frequencyTupleArr weightedValues

Parameters:
    weightedValues : (int * Gen<'a>)[] - Array of tuples where each tuple contains a weight and a generator.

Returns: Gen<'a>

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.

weightedValues : (int * Gen<'a>)[]

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

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

frequencyWeightAndValueArr weightedValues

Full Usage: frequencyWeightAndValueArr weightedValues

Parameters:
Returns: Gen<'a>

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.

weightedValues : WeightAndValue<Gen<'a>>[]

Array of weighted generators.

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

fresh fv

Full Usage: fresh fv

Parameters:
    fv : unit -> 'b

Returns: Gen<'b>

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

fv : unit -> 'b
Returns: Gen<'b>

freshFunc fv

Full Usage: freshFunc fv

Parameters:
Returns: Gen<'a>

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

fv : Func<'a>
Returns: Gen<'a>

growingElements xs

Full Usage: growingElements xs

Parameters:
    xs : seq<'a>

Returns: Gen<'a>

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.

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

listOf gn

Full Usage: listOf gn

Parameters:
Returns: Gen<'b list>

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

gn : Gen<'b>
Returns: Gen<'b list>

listOfLength n arb

Full Usage: listOfLength n arb

Parameters:
    n : int
    arb : Gen<'b>

Returns: Gen<'b list>

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

n : int
arb : Gen<'b>
Returns: Gen<'b list>

map f gen

Full Usage: map f gen

Parameters:
    f : 'b -> 'c
    gen : Gen<'b>

Returns: Gen<'c>

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

f : 'b -> 'c
gen : Gen<'b>
Returns: Gen<'c>

map2 f a b

Full Usage: map2 f a b

Parameters:
    f : 'a18 -> 'a19 -> 'a20
    a : Gen<'a18>
    b : Gen<'a19>

Returns: Gen<'a20>

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

f : 'a18 -> 'a19 -> 'a20
a : Gen<'a18>
b : Gen<'a19>
Returns: Gen<'a20>

map3 f a b c

Full Usage: map3 f a b c

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

Returns: Gen<'d>

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

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

map4 f a b c d

Full Usage: map4 f a b c d

Parameters:
    f : 'a18 -> 'a19 -> 'a20 -> 'a21 -> 'a22
    a : Gen<'a18>
    b : Gen<'a19>
    c : Gen<'a20>
    d : Gen<'a21>

Returns: Gen<'a22>

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

f : 'a18 -> 'a19 -> 'a20 -> 'a21 -> 'a22
a : Gen<'a18>
b : Gen<'a19>
c : Gen<'a20>
d : Gen<'a21>
Returns: Gen<'a22>

map5 f a b c d e

Full Usage: map5 f a b c d e

Parameters:
    f : 'a18 -> 'a19 -> 'a20 -> 'a21 -> 'a22 -> 'a23
    a : Gen<'a18>
    b : Gen<'a19>
    c : Gen<'a20>
    d : Gen<'a21>
    e : Gen<'a22>

Returns: Gen<'a23>

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

f : 'a18 -> 'a19 -> 'a20 -> 'a21 -> 'a22 -> 'a23
a : Gen<'a18>
b : Gen<'a19>
c : Gen<'a20>
d : Gen<'a21>
e : Gen<'a22>
Returns: Gen<'a23>

map6 f a b c d e g

Full Usage: map6 f a b c d e g

Parameters:
    f : 'a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g
    a : Gen<'a>
    b : Gen<'b>
    c : Gen<'c>
    d : Gen<'d>
    e : Gen<'e>
    g : Gen<'f>

Returns: Gen<'g>

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

f : 'a -> 'b -> 'c -> 'd -> 'e -> 'f -> 'g
a : Gen<'a>
b : Gen<'b>
c : Gen<'c>
d : Gen<'d>
e : Gen<'e>
g : Gen<'f>
Returns: Gen<'g>

nonEmptyListOf gn

Full Usage: nonEmptyListOf gn

Parameters:
Returns: Gen<'b list>

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

gn : Gen<'b>
Returns: Gen<'b list>

oneOfArr generators

Full Usage: oneOfArr generators

Parameters:
    generators : Gen<'a> array

Returns: Gen<'a>

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

generators : Gen<'a> array
Returns: Gen<'a>

oneof gens

Full Usage: oneof gens

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

Returns: Gen<'a>

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

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

optionOf g

Full Usage: optionOf g

Parameters:
Returns: Gen<'b option>

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

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

piles k sum

Full Usage: piles k sum

Parameters:
    k : int
    sum : int

Returns: Gen<int[]>

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

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

resize newSize arg2

Full Usage: resize newSize arg2

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

Returns: Gen<'b>

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

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

sample size n generator

Full Usage: sample size n generator

Parameters:
    size : int
    n : int
    generator : Gen<'b>

Returns: 'b list

Generates n values of the given size.

size : int
n : int
generator : Gen<'b>
Returns: 'b list

scaleSize f g

Full Usage: scaleSize f g

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

Returns: Gen<'b>

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

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

sequence l

Full Usage: sequence l

Parameters:
    l : seq<Gen<'a>>

Returns: Gen<'a list>

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

l : seq<Gen<'a>>
Returns: Gen<'a list>

sequenceToArr generators

Full Usage: sequenceToArr generators

Parameters:
    generators : Gen<'b> array

Returns: Gen<'b[]>

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

generators : Gen<'b> array
Returns: Gen<'b[]>

sequenceToSeq generators

Full Usage: sequenceToSeq generators

Parameters:
    generators : seq<Gen<'a>>

Returns: Gen<seq<'a>>

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

generators : seq<Gen<'a>>
Returns: Gen<seq<'a>>

shuffle xs

Full Usage: shuffle xs

Parameters:
    xs : seq<'a>

Returns: Gen<'a array>

Generates a random permutation of the given sequence.

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

sized fgen

Full Usage: sized fgen

Parameters:
    fgen : int -> Gen<'b>

Returns: Gen<'b>

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

fgen : int -> Gen<'b>
Returns: Gen<'b>

sizedFunc sizedGen

Full Usage: sizedFunc sizedGen

Parameters:
Returns: Gen<'a>

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

sizedGen : Func<int, Gen<'a>>
Returns: Gen<'a>

subListOf l

Full Usage: subListOf l

Parameters:
    l : seq<'a>

Returns: Gen<'a list>

Generates sublists of the given sequence.

l : seq<'a>
Returns: Gen<'a list>

subListOfArr s

Full Usage: subListOfArr s

Parameters:
    s : 'a array

Returns: Gen<IList<'a>>

Generates sublists of the given arguments.

s : 'a array
Returns: Gen<IList<'a>>

subListOfToIList s

Full Usage: subListOfToIList s

Parameters:
    s : seq<'a>

Returns: Gen<IList<'a>>

Generates sublists of the given IEnumerable.

s : seq<'a>
Returns: Gen<IList<'a>>

three g

Full Usage: three g

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

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

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

tryFilter predicate generator

Full Usage: tryFilter predicate generator

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

Returns: Gen<'a 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 : 'a -> bool
generator : Gen<'a>
Returns: Gen<'a option>

tryWhere predicate generator

Full Usage: tryWhere predicate generator

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

Returns: Gen<'a 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 : 'a -> bool
generator : Gen<'a>
Returns: Gen<'a option>

two g

Full Usage: two g

Parameters:
    g : Gen<'a18>

Returns: Gen<'a18 * 'a18>

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

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

unzip g

Full Usage: unzip g

Parameters:
    g : Gen<'a * 'b>

Returns: Gen<'a> * Gen<'b>

Split a generator of pairs into a pair of generators.

g : Gen<'a * 'b>
Returns: Gen<'a> * Gen<'b>

unzip3 g

Full Usage: unzip3 g

Parameters:
    g : Gen<'a * 'b * 'c>

Returns: Gen<'a> * Gen<'b> * Gen<'c>

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

g : Gen<'a * 'b * 'c>
Returns: Gen<'a> * Gen<'b> * Gen<'c>

where predicate generator

Full Usage: where predicate generator

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

Returns: Gen<'b>

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 : 'b -> bool
generator : Gen<'b>
Returns: Gen<'b>

zip f g

Full Usage: zip f g

Parameters:
Returns: Gen<'c * 'd>

Combine two generators into a generator of pairs.

f : Gen<'c>
g : Gen<'d>
Returns: Gen<'c * 'd>

zip3 f g h

Full Usage: zip3 f g h

Parameters:
Returns: Gen<'d * 'e * 'f>

Combine three generators into a generator of 3-tuples.

f : Gen<'d>
g : Gen<'e>
h : Gen<'f>
Returns: Gen<'d * 'e * 'f>

Create generators from generators

Functions and values

Function or value Description

collect f l

Full Usage: collect f l

Parameters:
    f : 'a -> Gen<'b>
    l : seq<'a>

Returns: Gen<'b 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 : 'a -> Gen<'b>
l : seq<'a>
Returns: Gen<'b list>

collectToSeq f l

Full Usage: collectToSeq f l

Parameters:
    f : 'a -> Gen<'b>
    l : seq<'a>

Returns: Gen<seq<'b>>

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

f : 'a -> Gen<'b>
l : seq<'a>
Returns: Gen<seq<'b>>

Creating generators from generators

Functions and values

Function or value Description

collectToArr f xs

Full Usage: collectToArr f xs

Parameters:
    f : 'a -> Gen<'b>
    xs : 'a array

Returns: Gen<'b[]>

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

f : 'a -> Gen<'b>
xs : 'a array
Returns: Gen<'b[]>