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
Generate a random date, optionally constrained before or after a given date.
Options
TODO: Not implemented yet.
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
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
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.
More sophisticated id generators can be implemented via generator schemas.
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
Generate a random time.
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.
Lazily transform the results of a stream via a function. I.e. just a
shorthand for StreamData.repeatedly/1
wrapped by StreamData.bind/2
.