Decorum (decorum v0.1.1)
Documentation for Decorum
.
Summary
Functions
Use this function to chain generators together when a generator is based on the value emitted by another generator.
Generates alphanumeric atoms.
Generates binaries.
Generates bytes.
check_all
takes a Decorum struct and runs test_fn
against the generated values.
Create a generator that is not random and always returns the same value.
Similar to Enum.filter/2
Generates integers in the given range.
Generates a list of values produced by the given generator.
Similar to Enum.map/2
Helper for creating Decorum structs from a generator function.
Randomly selects one of the given generators.
Creates a simple generator that outputs the values it gets from the prng.
Used to run a Decorum generator with a specific Prng struct.
Generates an integer between 0 and max.
Similar to Enum.zip/1
Similar to Enum.zip/2
Types
generator_fun(value)
@type generator_fun(value) :: (Decorum.Prng.t() -> {value, Decorum.Prng.t()})
max_length()
@type max_length() :: non_neg_integer() | :none
t(value)
@type t(value) :: %Decorum{generator: generator_fun(value)}
value()
@type value() :: term()
Functions
and_then(decorum, fun)
Use this function to chain generators together when a generator is based on the value emitted by another generator.
In StreamData this funciton is called bind
.
fun
is a function that takes a value from the given generator and
returns a generator.
atom(max_length \\ :none)
@spec atom(max_length()) :: t(atom())
Generates alphanumeric atoms.
binary(max_length \\ :none)
@spec binary(max_length()) :: t(binary())
Generates binaries.
max_length
is used to cap the length of the binary. It defaults to :none
and is the same as in list_of/2
.
byte()
Generates bytes.
A byte is an integer between 0
and 255
.
check(test_fn)
check(test_fn, test_value)
check_all(decorum, test_fn)
check_all
takes a Decorum struct and runs test_fn
against the generated values.
This funciton will expand and eventually be called by a macro, but for now it's part of bootsrtapping the property testing functionality.
test_fn
should behaive like a normal ExUnit test. It throws an error if a test fails.
Use the assert or other test helper macros inside that function.
TODO: Create a Decorum.Error and raise that instead of ExUnit.AssertionError.
constant(value)
Create a generator that is not random and always returns the same value.
filter(decorum, fun, limit \\ 25)
Similar to Enum.filter/2
Filters the generator. Returns only values for which fun returns a truthy value.
Use limit
to specify how many times the generator should be called before raising an error.
integer(range)
Generates integers in the given range.
Range handling borrowed from StreamData
Shrinks toward zero within the range.
list_of(decorum, max_length \\ :none)
@spec list_of(t(value()), max_length()) :: t([value()])
Generates a list of values produced by the given generator.
max_length
is used to cap the length of the list. It defaults to :none
.
Uses a biased coin flip to determine if another value should be gerenated or the list should be terminated.
When max_length
is a value other than :none
,
then the probablility of terminating the list increases as the list size approaches max_length
.
When max_length
is :none
the probablility of generating another value is around 7/8.
list_of_length(decorum, length)
@spec list_of_length(t(value()), non_neg_integer()) :: t([value()])
map(decorum, fun)
Similar to Enum.map/2
Returns a generator where each element is the result of invoking fun on each corresponding element of the given generator.
new(generator)
@spec new(generator_fun(value())) :: t(value())
Helper for creating Decorum structs from a generator function.
one_of(generators)
Randomly selects one of the given generators.
generators
must be a list.
prng_values()
@spec prng_values() :: t(non_neg_integer())
Creates a simple generator that outputs the values it gets from the prng.
Values will be 32-bit positive integers.
stream(decorum, prng)
@spec stream(t(value()), Decorum.Prng.t()) :: Enumerable.t(value())
Used to run a Decorum generator with a specific Prng struct.
Takes a Decorum struct and a Prng struct and returns a lazy Enumerable of generated values.
uniform_integer(max)
@spec uniform_integer(non_neg_integer()) :: t(non_neg_integer())
Generates an integer between 0 and max.
Currently only supports 32-bit values and is not truly uniform as the use of rem
has a bias towards producing smaller numbers.
zip(generators)
Similar to Enum.zip/1
Zips corresponding elements from a finite collection of generators into a generator of tuples.
zip(decorum1, decorum2)
Similar to Enum.zip/2
Zips corresponding elements from two generators into a generator of tuples.