View Source Myrmidex.Helpers.StreamData (myrmidex v0.2.0)

General use generators for use in generator schema modules.

By default, these generators are configured to allow for narrowing, i.e. use in property-based testing. You can, for example, wrap functions in StreamData.unshrinkable/1, or define your own more suited to your domain, in a custom generator schema.

Summary

Functions

Generate a random date, optionally constrained before or after a given date.

Choose one from a (predetermined, limited) list of values. Note that this generator is passed via StreamData.unshrinkable/1 to ensure random output.

Generate integers. Given a single integer, produces a constant stream of that value: this is useful when composing other generators, e.g. &time_stream_data/1.

Constrain integers generated to a given range.

Per StreamData docs. Useful for ids, although by default ids are only unique per runtime instance: i.e. all schemas will share the same sequence of ids.

Maps binary or bitstring input into (arbitrary) matching generation ranges.

Generate a random time.

Defaults to current time in utc. The default generator for timestamp fields.

Lazily transform the results of a stream via a function. I.e. just a shorthand for StreamData.repeatedly/1 wrapped by StreamData.bind/2.

Functions

Link to this function

date_stream_data(opts \\ [])

View Source

Generate a random date, optionally constrained before or after a given date.

Options

TODO: Not implemented yet.

Link to this function

datetime_stream_data(type \\ :utc_datetime_usec)

View Source
Link to this function

enum_stream_data(values)

View Source

Choose one from a (predetermined, limited) list of values. Note that this generator is passed via StreamData.unshrinkable/1 to ensure random output.

Examples

iex> values = ["🐜", "🪰", "🪳"]
iex> stream = Myrmidex.Helpers.StreamData.enum_stream_data(values)
iex> Myrmidex.one(stream) in values
true
Link to this function

fixed_map_stream_data(field_generators, keys \\ :atom)

View Source

Generate integers. Given a single integer, produces a constant stream of that value: this is useful when composing other generators, e.g. &time_stream_data/1.

Examples

iex> stream = Myrmidex.Helpers.StreamData.integer_stream_data()
iex> is_integer(Myrmidex.one(stream))
true
Link to this function

integer_stream_data(int)

View Source

Constrain integers generated to a given range.

Link to this function

monotonic_integer_stream_data()

View Source

Per StreamData docs. Useful for ids, although by default ids are only unique per runtime instance: i.e. all schemas will share the same sequence of ids.

More sophisticated id generators can be implemented via generator schemas.

Link to this function

string_stream_data(string)

View Source

Maps binary or bitstring input into (arbitrary) matching generation ranges.

Mainly logical re: making the docs :) Can be replaced with your own implementation with a Myrmidex.GeneratorSchema.

Examples

iex> stream = Myrmidex.Helpers.StreamData.string_stream_data(<<128>>)
iex> is_bitstring(Myrmidex.one(stream))
true

iex> stream = Myrmidex.Helpers.StreamData.string_stream_data("catch_all")
iex> is_binary(Myrmidex.one(stream))
true
Link to this function

time_stream_data(opts \\ [])

View Source

Generate a random time.

Link to this function

timestamp_stream_data(type \\ :utc_datetime_usec)

View Source

Defaults to current time in utc. The default generator for timestamp fields.

Examples

iex> stream = Myrmidex.Helpers.StreamData.timestamp_stream_data()
iex> match?(%DateTime{}, Myrmidex.one(stream))
true

iex> stream = Myrmidex.Helpers.StreamData.timestamp_stream_data(:utc_datetime)
iex> match?(%DateTime{microsecond: {0,0}}, Myrmidex.one(stream))
true

Per StreamData docs.

Link to this function

via(stream_data, via_fun)

View Source

Lazily transform the results of a stream via a function. I.e. just a shorthand for StreamData.repeatedly/1 wrapped by StreamData.bind/2.