Copyright © Quviq AB, 2004-2022
Version: 2.02.0
{int(), bool()}is a generator that generates random pairs of integers and booleans.
Many of the functions in this module are usually used via macros, defined in eqc.hrl. These macros are listed here.
The result is shrunk by first shrinking the value generated by G1 while the test still fails, then shrinking the value generated by G2. It is thus better to write ?LET({X, Y}, {G1, G2}, G3) than ?LET(X, G1, ?LET(Y, G2, G3)) (provided G2 does not depend on X), since in the first case shrinking can shrink G1 a bit, shrink G2, then shrink G1 some more, while in the second case G1 cannot be shrunk further once shrinking G2 has begun.
resize/2
.
?SUCHTHAT(Xs, list(int()), lists:sort(Xs)==Xs)generates predominantly very short lists, since the probability that a random longer list will just happen to be sorted is very low. If no value is found within 100 attempts, then ?SUCHTHAT exits.
?LETSHRINK([L, R], [tree(), tree()], {branch, L, R})generates a tree node {branch, L, R}, which can shrink to either L or R.
abstract datatype: gen(A)
binary/0 | Generates a binary of random size. |
binary/1 | Generates a binary of a given size in bytes. |
bitstring/0 | Generates a list of bits in a bitstring. |
bitstring/1 | Generates a bitstring of a given size in bits. |
bool/0 | Generates a random boolean. |
char/0 | Generates a random character. |
choose/2 | Generates a number in the range M to N. |
default/2 | Adds a default value to a generator, to be chosen half the time. |
elements/1 | Generates an element of the list argument. |
frequency/1 | Makes a weighted choice between the generators in its argument, such that the probability of choosing each generator is proportional to the weight paired with it. |
function0/1 | Generates a function of no arguments with result generated by G. |
function1/1 | Generates a function of one argument with result generated by G. |
int/0 | Generates a small integer (with absolute value bounded by the generation size). |
largebinary/0 | Equivalent to largebinary({limit, 255, 65535}). |
largebinary/1 | largebinary(X) is equivalent to largebinary({fixed, X}, []),. |
largebinary/2 | A generator for large binaries. |
largeint/0 | Generates an integer from a large range. |
list/1 | Generates a list of elements generated by its argument. |
list/2 | Generates a list of elements generated by its argument, of length at most MaxLen. |
map/2 | Generates a map with keys generated by K and values generated by V. |
nat/0 | Generates a small natural number (bounded by the generation size). |
non_empty/1 | Make sure that the generated value is not empty. |
noshrink/1 | Generates the same values as G, but these values are never shrunk. |
oneof/1 | Generates a value using a randomly chosen element of the list of generators. |
orderedlist/1 | Generates an ordered list of elements generated by G. |
real/0 | Generates a real number. |
resize/2 | Binds the generation size parameter to Size within G. |
return/1 | Constructs a generator that always generates the value X. |
sample/1 | Prints 11 values randomly generated by G, for sizes ranging from 10 to 20. |
sampleshrink/1 | Prints a value generated by G, followed by one way of shrinking it. |
shuffle/1 | Shuffles a list and shrinks to the unshuffled list. |
sublist/1 | Generate a random sublist of the given list. |
utf8/0 | Generates a random utf8 binary. |
utf8/1 | Generates a random utf8 binary with N unicode characters. |
vector/2 | Generates a list of the given length, with elements generated by G. |
binary() -> gen(binary())
Generates a binary of random size. The binary shrinks both in size as well as in content. If you consider the binary as a representation of a number, then each shrinking step will result in a smaller - or - equal number.
Generates a binary of a given size in bytes. When shrinking,
the size is unchanged, but content shrinks like binary/0
.
bitstring() -> gen(bitstring())
Generates a list of bits in a bitstring. For Erlang release R12B and later. The bitstring shrinks both in size as well as in content. If you consider the bitstring as a representation of a number, then each shrinking step will result in a smaller - or - equal number.
Generates a bitstring of a given size in bits. For Erlang
release R12B and later. When shrinking,
the size is unchanged, but content shrinks like bitstring/0
.
bool() -> gen(bool())
Generates a random boolean. Shrinks to false.
char() -> gen(char())
Generates a random character. Shrinks to a, b or c.
choose(M, N::integer()) -> gen(integer())
Generates a number in the range M to N. The result shrinks towards smaller absolute values.
Adds a default value to a generator, to be chosen half the time. Any other value shrinks to the default.
elements(Xs::[A]) -> gen(A)
Generates an element of the list argument. Shrinking chooses an earlier element.
Makes a weighted choice between the generators in its argument, such that the probability of choosing each generator is proportional to the weight paired with it. The weights should be non-negative numbers and sum to a positive value. A generator with a weight of zero will not be chosen.
Generates a function of no arguments with result generated by G.
Generates a function of one argument with result generated by G. The generated function is pure--will always return the same result for the same argument-- and the result depends randomly on the argument.
int() -> gen(integer())
Generates a small integer (with absolute value bounded by the generation size).
largebinary() -> gen(binary())
Equivalent to largebinary({limit, 255, 65535}).
largebinary(X::NrBytes | {fixed, NrBytes} | {limit, Lower, Upper}) -> gen(binary())
largebinary(X) is equivalent to largebinary({fixed, X}, []),
largebinary({fixed, X}) is equivalent to largebinary({fixed, X}, []), and
largebinary({limit, X, Y}) is equivalent to largebinary({limit, X, Y}).
largebinary(Size, Options) -> gen(binary())
A generator for large binaries. As a rule of thumb, large means > 128 bytes. The
problem with the standard generator (binary/0
/binary/1
) is twofold,
the number of shrinking alternatives quickly grow unfeasably large, and the generation
is memory consuming.
This generator sacrifices precision for performance. Generation is more efficient, and it shrinks faster although less precisely.
The generator can generate either:largeint() -> any()
Generates an integer from a large range.
Generates a list of elements generated by its argument. Shrinking drops elements from the list. The length of the list varies up to one third of the generation size parameter.
Generates a list of elements generated by its argument, of length at most MaxLen. Shrinking drops elements from the list.
Generates a map with keys generated by K and values generated by V.
nat() -> gen(integer())
Generates a small natural number (bounded by the generation size).
Make sure that the generated value is not empty. For example when creating a list of integers, but the list should always contain at least one element non_empty(list(int())).
noshrink(G::gen(A) | property()) -> gen(A) | property()
Generates the same values as G, but these values are never shrunk. Can also be applied to properties.
Generates a value using a randomly chosen element of the list of generators.
Generates an ordered list of elements generated by G.
real() -> gen(float())
Generates a real number.
Binds the generation size parameter to Size within G. Size should never be negative.
return(X::A) -> gen(A)
Constructs a generator that always generates the value X. Most values can also be used as generators for themselves, making return unnecessary, but return(X) may be more efficient than using X as a generator, since when return(X) is used then QuickCheck does not traverse X searching for values to be intepreted specially.
sample(G::gen(A)) -> ok
Prints 11 values randomly generated by G, for sizes ranging from 10 to 20.
sampleshrink(G::gen(A)) -> ok
Prints a value generated by G, followed by one way of shrinking it. Each following line displays a list of values that the first value on the previous line can be shrunk to in one step. Thus the output traces the leftmost path through the shrinking tree.
shuffle(Xs::[A]) -> gen([A])
Shuffles a list and shrinks to the unshuffled list.
sublist(Xs::[A]) -> gen([A])
Generate a random sublist of the given list. Generates short sublists when the size parameter is small, and ramps up to an even distribution of sublist lengths as the size parameter increases. Shrinks to shorter sublists containing elements from earlier in the list.
utf8() -> any()
Generates a random utf8 binary.
utf8(N) -> any()
Generates a random utf8 binary with N unicode characters.
Generates a list of the given length, with elements generated by G.
Generated by EDoc