PropCheck - Property Testing v1.1.4 PropCheck.BasicTypes View Source
This modules contains all basic type generators from PropEr. It is
automatically available by use PropCheck
.
Acknowlodgements
The functions defined here are delegated to the corresponding
definition proper_types
. Also most of the documentation is
copied over from there.
Link to this section Summary
Types
Floats extend by infinity
Integers extend by infinity
Non negative integers extend by infinity
The internal representation of a basic type in PropEr
The internal representation of a type in PropEr
Functions
All Elixir terms (that PropEr can produce)
Arity is a byte value, i.e. integer(0, 255)
All atoms
All binaries
All binaries with a byte size of length
All bitstrings
All bitstrings with a bit size of length
bool is equivalent to boolean
The atoms true
and false
. Instances shrink towards false
Byte values, i.e. integer(0, 255)
Char values (16 bit for some reason), i.e. integer(0, 0xffff)
An Erlang string, i.e. list(char)
choose is equivalent to integer(low, high)
Adds a default value, default_value
, to type
elements is equivalent to union([..])
Singleton type consisting only of value
All lists whose i-th element is an instance of the type at index i of
list_of_types
. Also written simply as a list of types
All floats, i.e. float(:inf, :inf)
All floats between low
and high
, bounds included
frequency is equivalent to weighted_union([..])
All pure functions that map instances of arg_types
to instances of
ret_type
A function with 0 parameters, i.e. function(0, ret_type)
A function with 1 parameter, i.e. function(1, ret_type)
A function with 2 parameters, i.e. function(2, ret_type)
A function with 3 parameters, i.e. function(3, ret_type)
A function with 4 parameters, i.e. function(4, ret_type)
Small integers (bound by the current value of the size
parameter)
All integers, i.e. integer(:inf, :inf)
All integers between low
and high
, bounds included
Large_int is equivalent to integer
List of any types, i.e. list(any)
All lists containing elements of type elem_type
Tuples whose elements are all of type elem_type
A map whose keys are defined by the generator k and values by the generator v
Small Small non-negative integers (bound by the current value of the size
parameter)
Negative integers, i.e. integer(:inf, -1)
This is a predefined constraint that can be applied to random-length list and binary types to ensure that the produced values are never empty
Non negative floats, i.e. float(0.0, inf)
Non negative integers, i.e. integer(0, :inf)
Creates a new type which is equivalent to type
, but whose instances
are never shrunk by the shrinking subsystem
Numbers are integers or floats, i.e. union([integer(), float()])
oneof is equivalent to union([..])
All sorted lists containing elements of type elem_type
Returns the value associated with parameter
, or :undefined
in case
parameter
is not associated with any value
Returns the value associated with parameter
, or default
in case
parameter
is not associated with any value
Strictly positive integers, i.e. integer(1, :inf)
A range is equivalent to integers
real is equivalent to float
Overrides the size
parameter used when generating instances of
type
with new_size
return is equivalent to exactly
A type that generates exactly the list list
Term is a synonym for any
timeout values, i.e. union([non_neg_integer() | :infinity])
Tuples of any types, i.e. loose_tuple(any)
All tuples whose i-th element is an instance of the type at index i of
list_of_types
The union of all types in list_of_types
utf8-encoded unbounded size binary
utf8-encoded bounded upper size binary
Bounded upper size utf8 binary, codepoint length =< MaxCodePointSize
All lists of length length
containing elements of type elem_type
A specialization of default/2
A specialization of union/1
, where each type in list_of_types
is
assigned a frequency
Associates the atom key parameter
with the value value
while
generating instances of type
Similar to with_parameter/3
, but accepts a list of
{parameter, value}
pairs
weighted_union(FreqChoices)
Link to this section Types
ext_float()
View Source
ext_float() :: float() | :inf
ext_float() :: float() | :inf
Floats extend by infinity
ext_int()
View Source
ext_int() :: integer() | :inf
ext_int() :: integer() | :inf
Integers extend by infinity
ext_non_neg_integer()
View Source
ext_non_neg_integer() :: non_neg_integer() | :inf
ext_non_neg_integer() :: non_neg_integer() | :inf
Non negative integers extend by infinity
frequency()
View Source
frequency() :: pos_integer()
frequency() :: pos_integer()
raw_type()
View Source
raw_type() :: :proper_types.raw_type()
raw_type() :: :proper_types.raw_type()
The internal representation of a basic type in PropEr
size()
View Source
size() :: PropCheck.size()
size() :: PropCheck.size()
type()
View Source
type() :: :proper_types.type()
type() :: :proper_types.type()
The internal representation of a type in PropEr
value()
View Source
value() :: any()
value() :: any()
Link to this section Functions
any()
View Source
any() :: type()
any() :: type()
All Elixir terms (that PropEr can produce).
For reasons of efficiency, functions are never produced as instances of this type.
CAUTION: Instances of this type are expensive to produce, shrink and instance- check, both in terms of processing time and consumed memory. Only use this type if you are certain that you need it.
arity()
View Source
arity() :: type()
arity() :: type()
Arity is a byte value, i.e. integer(0, 255)
atom()
View Source
atom() :: type()
atom() :: type()
All atoms.
All atoms used internally by PropEr start with a :$
, so
such atoms will never be produced as instances of this type. You should also
refrain from using such atoms in your code, to avoid a potential clash.
Instances shrink towards the empty atom, :""
.
binary()
View Source
binary() :: type()
binary() :: type()
All binaries.
Instances shrink towards the empty binary, ""
.
binary(length)
View Source
binary(non_neg_integer()) :: type()
binary(non_neg_integer()) :: type()
All binaries with a byte size of length
.
length
must be an Elixir expression that evaluates to a non-negative integer.
Instances shrink towards binaries of zeroes.
bitstring()
View Source
bitstring() :: type()
bitstring() :: type()
All bitstrings.
Instances shrink towards the empty bitstring, ""
.
bitstring(length)
View Source
bitstring(non_neg_integer()) :: type()
bitstring(non_neg_integer()) :: type()
All bitstrings with a bit size of length
.
length
must be an Elixir expression that evaluates to a non-negative integer.
Instances shrink towards bitstrings of zeroes.
bool()
View Source
bool() :: type()
bool() :: type()
bool is equivalent to boolean
boolean()
View Source
boolean() :: type()
boolean() :: type()
The atoms true
and false
. Instances shrink towards false
.
byte()
View Source
byte() :: type()
byte() :: type()
Byte values, i.e. integer(0, 255)
char()
View Source
char() :: type()
char() :: type()
Char values (16 bit for some reason), i.e. integer(0, 0xffff)
char_list()
View Source
char_list() :: type()
char_list() :: type()
An Erlang string, i.e. list(char)
choose(low, high) View Source
choose is equivalent to integer(low, high)
default(default_value, type) View Source
Adds a default value, default_value
, to type
.
The default serves as a primary shrinking target for instances, while it is also chosen by the random instance generation subsystem half the time.
elements(choices) View Source
elements is equivalent to union([..])
exactly(value) View Source
Singleton type consisting only of value
.
value
must be an evaluated term. Also written simply as value
.
fixed_list(list_of_types) View Source
All lists whose i-th element is an instance of the type at index i of
list_of_types
. Also written simply as a list of types.
float()
View Source
float() :: type()
float() :: type()
All floats, i.e. float(:inf, :inf)
float(low, high) View Source
All floats between low
and high
, bounds included.
low
and high
must be Elixir expressions that evaluate to floats, with
Low =< high
. Additionally, low
and high
may have the value :inf
, in
which case they represent minus infinity and plus infinity respectively.
Instances shrink towards 0.0 if low =< 0.0 =< high
, or towards the bound
with the smallest absolute value otherwise.
frequency(freq_choices) View Source
frequency is equivalent to weighted_union([..])
function(arg_types, return_type) View Source
All pure functions that map instances of arg_types
to instances of
ret_type
.
The syntax function(arity, ret_type)
is also acceptable.
function0(ret_type) View Source
A function with 0 parameters, i.e. function(0, ret_type)
function1(ret_type) View Source
A function with 1 parameter, i.e. function(1, ret_type)
function2(ret_type) View Source
A function with 2 parameters, i.e. function(2, ret_type)
function3(ret_type) View Source
A function with 3 parameters, i.e. function(3, ret_type)
function4(ret_type) View Source
A function with 4 parameters, i.e. function(4, ret_type)
int()
View Source
int() :: type()
int() :: type()
Small integers (bound by the current value of the size
parameter).
Instances shrink towards 0
.
integer()
View Source
integer() :: type()
integer() :: type()
All integers, i.e. integer(:inf, :inf)
integer(low, high) View Source
All integers between low
and high
, bounds included.
low
and high
must be Elixir expressions that evaluate to integers, with
low =< high
. Additionally, low
and high
may have the value :inf
, in
which case they represent minus infinity and plus infinity respectively.
Instances shrink towards 0 if low =< 0 =< high
, or towards the bound with
the smallest absolute value otherwise.
large_int()
View Source
large_int() :: type()
large_int() :: type()
Large_int is equivalent to integer
list()
View Source
list() :: type()
list() :: type()
List of any types, i.e. list(any)
list(elem_type) View Source
All lists containing elements of type elem_type
.
Instances shrink towards the empty list, []
.
loose_tuple(elem_type) View Source
Tuples whose elements are all of type elem_type
.
Instances shrink towards the 0-size tuple, {}
.
map(k, v) View Source
A map whose keys are defined by the generator k and values by the generator v.
nat()
View Source
nat() :: type()
nat() :: type()
Small Small non-negative integers (bound by the current value of the size
parameter).
Instances shrink towards 0
.
neg_integer()
View Source
neg_integer() :: type()
neg_integer() :: type()
Negative integers, i.e. integer(:inf, -1)
non_empty(list_type) View Source
This is a predefined constraint that can be applied to random-length list and binary types to ensure that the produced values are never empty.
Use for e.g. list/0
, char_list/0
, binary/0
non_neg_float()
View Source
non_neg_float() :: type()
non_neg_float() :: type()
Non negative floats, i.e. float(0.0, inf)
non_neg_integer()
View Source
non_neg_integer() :: type()
non_neg_integer() :: type()
Non negative integers, i.e. integer(0, :inf)
noshrink(type) View Source
Creates a new type which is equivalent to type
, but whose instances
are never shrunk by the shrinking subsystem.
number()
View Source
number() :: type()
number() :: type()
Numbers are integers or floats, i.e. union([integer(), float()])
oneof(choices) View Source
oneof is equivalent to union([..])
ordered_list(elem_type) View Source
All sorted lists containing elements of type elem_type
.
Instances shrink towards the empty list, []
.
parameter(parameter) View Source
Returns the value associated with parameter
, or :undefined
in case
parameter
is not associated with any value.
Association occurs with calling with_parameter/3
or with_parameters/2
before.
parameter(parameter, default) View Source
Returns the value associated with parameter
, or default
in case
parameter
is not associated with any value.
Association occurs with calling with_parameter/3
or with_parameters/2
before.
pos_integer()
View Source
pos_integer() :: type()
pos_integer() :: type()
Strictly positive integers, i.e. integer(1, :inf)
range(low, high) View Source
A range is equivalent to integers
real()
View Source
real() :: type()
real() :: type()
real is equivalent to float
resize(new_size, raw_type) View Source
Overrides the size
parameter used when generating instances of
type
with new_size
.
Has no effect on size-less types, such as unions.
Also, this will not affect the generation of any internal types contained in
type
, such as the elements of a list - those will still be generated
using the test-wide value of size
. One use of this function is to modify
types to produce instances that grow faster or slower, like so:
iex> quickcheck(forall l <- list(integer()) do
...> length(l) <= 42
...> end)
true
iex> long_list = sized(size, resize(size * 2, list(integer())))
iex> really_long = such_that_maybe l <- long_list, when:
...> length(l) > 42
iex> quickcheck(forall l <- really_long do
...> (length(l) <= 84)
...> |> measure("List length", length l)
...> |> collect(length l)
...> end)
true
The above specifies a list type that grows twice as fast as normal lists.
return(e) View Source
return is equivalent to exactly
shrink_list(list) View Source
A type that generates exactly the list list
.
Instances shrink towards shorter sublists of the original list.
term()
View Source
term() :: type()
term() :: type()
Term is a synonym for any
timeout()
View Source
timeout() :: type()
timeout() :: type()
timeout values, i.e. union([non_neg_integer() | :infinity])
tuple()
View Source
tuple() :: type()
tuple() :: type()
Tuples of any types, i.e. loose_tuple(any)
tuple(list_of_types) View Source
All tuples whose i-th element is an instance of the type at index i of
list_of_types
.
Also written simply as a tuple of types.
union(list_of_types) View Source
The union of all types in list_of_types
.
list_of_types
can't be empty.
The random instance generator is equally likely to choose any one of the
types in list_of_types
. The shrinking subsystem will always try to shrink an
instance of a type union to an instance of the first type in list_of_types
,
thus you should write the simplest case first.
utf8()
View Source
utf8() :: type()
utf8() :: type()
utf8-encoded unbounded size binary
utf8(n)
View Source
utf8(ext_non_neg_integer()) :: type()
utf8(ext_non_neg_integer()) :: type()
utf8-encoded bounded upper size binary.
utf8(n, max_codepoint_size)
View Source
utf8(ext_non_neg_integer(), 1..4) :: type()
utf8(ext_non_neg_integer(), 1..4) :: type()
Bounded upper size utf8 binary, codepoint length =< MaxCodePointSize
.
Limiting codepoint size can be useful when applications do not accept full unicode range. For example, MySQL in utf8 encoding accepts only 3-byte unicode codepoints in VARCHAR fields.
If unbounded length is needed, use :inf
as first argument.
vector(length, elem_type)
View Source
vector(non_neg_integer(), raw_type()) :: type()
vector(non_neg_integer(), raw_type()) :: type()
All lists of length length
containing elements of type elem_type
.
length
must be an Elixir expression that evaluates to a non-negative integer.
weighted_default(default, type) View Source
A specialization of default/2
.
Parameters default
and type
are
assigned weights to be considered by the random instance generator. The
shrinking subsystem will ignore the weights and try to shrink using the
default value.
weighted_union(list_of_types) View Source
A specialization of union/1
, where each type in list_of_types
is
assigned a frequency.
Frequencies must be Elixir expressions that evaluate to positive integers. Types with larger frequencies are more likely to be chosen by the random instance generator. The shrinking subsystem will ignore the frequencies and try to shrink towards the first type in the list.
with_parameter(parameter, value, type) View Source
Associates the atom key parameter
with the value value
while
generating instances of type
.
with_parameters(pv_list, type) View Source
Similar to with_parameter/3
, but accepts a list of
{parameter, value}
pairs.
wunion(freq_choices) View Source
weighted_union(FreqChoices)