box(T) = #'@box'{dom = domain(T), value = T}
abstract datatype: domain(T)
Domain of values of type T.
domrec(T) = {'@', atom() | tuple(), pick_fun(T), shrink_fun(T), boolean()}
abstract datatype: pick_fun(T)
Picks members of the domain(T)
.
Return pair of {domain(T),T}
; the "output domain" is what will
be used for shrinking the value.
abstract datatype: shrink_fun(T)
Shrinks members of the domain(T)
.
Return pair of {domain(T),T}
; the "output domain" is what will
be used for further shrinking the value.
abstract datatype: uchar()
Valid unicode code point.
uchars() = unicode:unicode_characters()
any/0 | |
atom/0 | The domain of atoms. |
atom/1 | |
binary/0 | |
binary/1 | |
bitstring/0 | The domain of bitstrings. |
bitstring/1 | |
bool/0 | The domain of booleans. |
byte/0 | |
char/0 | |
choose/2 | |
domain/3 | Create custom domain. |
elements/1 | Generates a member of the list L . |
float/0 | |
frequency/1 | Choose domain from list [{Weight, Domain}, ...]. |
int/0 | The domain of integers. |
int/1 | |
int/2 | |
largeint/0 | The domain of "big" integers. |
list/1 | Returns the domain of lists of the argument. |
non_empty/1 | |
non_neg_integer/0 | The domain of non-negative integers. |
noshrink/1 | |
oneof/1 | |
open/1 | Open a box, yielding a domain which always generates the same value. |
peek/1 | |
pick/2 | The heart of the random structure generator; pick a value from the domain. |
pos_integer/0 | The domain of positive integers. |
real/0 | The domain of floats. |
resize/2 | |
return/1 | Returns the domain containing exactly Value . |
sample/1 | Generate a sample of output values from a generator. |
sampleshrink/1 | Print a value generated by Domain , followed by a sample of shrinkings. |
seal/1 | Get the domain of boxes of T. |
shrink/2 | The shrinking step function used internally in Triq. |
shrink_without_duplicates/1 | |
sized/1 | Support function for the ?SIZED macro. |
tuple/1 | |
unicode_binary/0 | |
unicode_binary/1 | Generate an unicode binary binary. |
unicode_binary/2 | Generate an unicode binary. |
unicode_char/0 | |
unicode_characters/0 | |
unicode_characters/1 | |
unicode_string/0 | Generate a list of unicode code points. |
unicode_string/1 | Generate a list of unicode code points of length Size . |
vector/2 |
any() -> domain(any())
atom() -> domain(integer())
The domain of atoms
atom(Size::non_neg_integer()) -> domrec(atom())
binary() -> domrec(binary())
binary(Size::non_neg_integer()) -> domrec(binary())
bitstring() -> domain(bitstring())
The domain of bitstrings
bitstring(Size::non_neg_integer()) -> domrec(bitstring())
bool() -> domain(true | false)
The domain of booleans. Shrinks to false.
byte() -> domrec(integer())
char() -> domrec(32..126)
choose(M::integer(), N::integer()) -> domrec(integer())
domain(Name::any(), PickFun::pick_fun(T), ShrinkFun::shrink_fun(T)) -> domain(T)
Create custom domain. This function allows you to create a custom domain with it's own shrinking logic. For instance, the even numbers can be specified thus:
even() -> domain(even, fun(Self,Size) -> Value = (triq_rnd:uniform(Size) * 2) div 2, {Self, Value} end, fun(Self,Value) when Value>0 -> {Self, Value-2}; (Self,_,0) -> {0, 0} end).
The domain itself (Self
in the above code) is passed as the first argument
to each invocation of both the picking and the shrinking functions.
elements(L::[any()]) -> domain(any())
Generates a member of the list L
. Shrinks towards the first element
of the list.
float() -> domrec(float())
frequency(GenList) -> any()
Choose domain from list [{Weight, Domain}, ...]
int() -> domain(integer())
The domain of integers.
int(Max) -> any()
int(Min, Max) -> any()
largeint() -> domrec(largeint())
The domain of "big" integers.
Note, this is sized to ensure it remains a big integer, even on 64 bit implementations.
Returns the domain of lists of the argument.
For example, list(int())
yields the domain of lists of integers.
non_empty(Dom) -> any()
non_neg_integer() -> domain(non_neg_integer())
The domain of non-negative integers.
Open a box, yielding a domain which always generates the same value.
peek(X1::box(T)) -> T
The heart of the random structure generator; pick a value from the
domain.
Returns a pair of {domain(T), T}
where the first component describes
the structure of the picked value.
pos_integer() -> domain(pos_integer())
The domain of positive integers.
real() -> domain(float())
The domain of floats.
resize(Sz, Dom) -> any()
return(Value::Type) -> domain(Type)
Returns the domain containing exactly Value
.
Triq uses internally records of type @
; and so to avoid
interpretation of such values you can wrap it with this. This would
be the case if you have constants in your domains contain the atom @
.
I.e., the following would break because Triq tries to interpret the @
:
?FORALL(X, [int(), {'@', 4}], [IntVal, {'@', 4}] = X )To fix it, do like this:
?FORALL(X, [int(), return({'@', 4})], [IntVal, {'@', 4}] = X )
sample(Dom::domain(T)) -> [T]
Generate a sample of output values from a generator. This should not be used except for REPL testing purposes; it will only ever generate fairly small-valued samples.
sampleshrink(Domain::domain(any())) -> ok
Print a value generated by Domain
, followed by a sample of shrinkings.
For each line of successive output, it prints up to five samples of
shrinking. The first value on each like is used as the target for the next
round of shrinking.
1> sampleshrink(list(int())). [-2,-8,2] [[-1,-8,2],[0,-8,2],[-1,-7,2],[-2,-8,1],[-1,-8,1]] [[0,-8,2],[0,-6,1],[-1,-7,2],[0,-7,2]] [[0,-8,0],[0,-7,0],[0,-7,2],[0,-8,1],[0,-5,2],[0,-7,1]] [[0,-7,0],[0,-5,0]] [[0,-5,0],[0,-6,0]] [[0,-4,0],[0,-3,0]] [[0,-2,0],[0,-3,0],[0,-1,0]] [[0,-1,0]] [[0,0,0]] [[0,0]] [[0]] [[]] ok
Get the domain of boxes of T
The shrinking step function used internally in Triq.
Performs one single step of shrinking. If unsuccessful, i.e. value cound not be shrunk, the output is equal to the input.
Takes aDomain
and a Value
from said domain, and shrinks
the value within the constraints of the domain. The result is
a tuple of a (possibly smaller) output domain, and the
shrunken value.
shrink_without_duplicates(Dom) -> any()
Support function for the ?SIZED macro.
unicode_binary() -> domrec(binary())
unicode_binary(Size::Size | Encoding) -> domrec(binary())
Generate an unicode binary binary.
unicode_binary(Size, Encoding) -> domrec(binary())
Generate an unicode binary.
unicode_characters(Encoding) -> domrec(uchars())
Generate a list of unicode code points.
Generate a list of unicode code points of length Size
.
vector(Size, ElemDom) -> any()
Generated by EDoc