Decorum (decorum v0.1.0)

Documentation for Decorum.

Summary

Functions

Use this function to chain generators together when a generator is based on the value emitted by another generator.

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

Link to this type

generator_fun(value)

@type generator_fun(value) :: (Decorum.Prng.t() -> {value, Decorum.Prng.t()})
@type t(value) :: %Decorum{generator: generator_fun(value)}
@type value() :: term()

Functions

Link to this function

and_then(decorum, fun)

@spec and_then(t(a), (a -> t(b))) :: t(b) when a: value(), b: value()

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.

@spec check((value() -> nil)) :: Decorum.Shrinker.check_function(value())
Link to this function

check(test_fn, test_value)

@spec check((value() -> nil), value()) :: Decorum.Shrinker.check_result()
Link to this function

check_all(decorum, test_fn)

@spec check_all(t(value()), (value() -> nil)) :: :ok

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.

Link to this function

constant(value)

@spec constant(value()) :: t(value())

Create a generator that is not random and always returns the same value.

Link to this function

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.

@spec integer(Range.t()) :: t(integer())

Generates integers in the given range.

Range handling borrowed from StreamData

Shrinks toward zero within the range.

Link to this function

list_of(decorum)

@spec list_of(t(value())) :: t([value()])

Generates a list of values produced by the given generator.

Use a biased coin flip to determine if another value should be gerenated or the list should be terminated.

Link to this function

list_of_length(decorum, length)

@spec list_of_length(t(value()), non_neg_integer()) :: t([value()])
Link to this function

map(decorum, fun)

@spec map(t(a), (a -> b)) :: t(b) when a: value(), b: value()

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.

@spec new(generator_fun(value())) :: t(value())

Helper for creating Decorum structs from a generator function.

Link to this function

one_of(generators)

@spec one_of([t(value())]) :: t(value())

Randomly selects one of the given generators.

generators must be a list.

@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.

Link to this function

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.

Link to this function

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.

Link to this function

zip(generators)

@spec zip([t(any())]) :: t(tuple())

Similar to Enum.zip/1

Zips corresponding elements from a finite collection of generators into a generator of tuples.

Link to this function

zip(decorum1, decorum2)

@spec zip(t(a), t(b)) :: t({a, b}) when a: value(), b: value()

Similar to Enum.zip/2

Zips corresponding elements from two generators into a generator of tuples.