Generators¶
Convenience combinators and factories for common types of Generators.
Constructors¶
create¶
Returns¶
- Generators val^
Public Functions¶
unit[T: T]¶
Generate a reference to the same value over and over again.
Parameters¶
- t: T
Returns¶
- Generator[box->T] box
none[T: None val]¶
Always generate None.
Returns¶
repeatedly[T: T]¶
Generate values by calling the lambda f repeatedly.
Values generated this way produce zero recorded choices and cannot
be shrunk. Use a generator that draws from Randomness when shrinking
matters.
Parameters¶
- f: {(): T^ ?}[T] box
Returns¶
- Generator[T] box
array_of[T: T]¶
Generate an Array[T] with size in the range from to to.
Uses boolean-per-element encoding for shrinking: each element is preceded
by a boolean deciding whether to include it. Shrinking deletes elements
while preserving all others exactly.
fun box array_of[T: T](
gen: Generator[T] box,
from: USize val = 0,
to: USize val = 100)
: Generator[Array[T] ref] box
Parameters¶
Returns¶
iso_seq_of[T: Any #send, S: Seq[T] iso]¶
Generate a Seq[T] where T must be sendable.
Uses boolean-per-element encoding.
fun box iso_seq_of[T: Any #send, S: Seq[T] iso](
gen: Generator[T] box,
from: USize val = 0,
to: USize val = 100)
: Generator[S] box
Parameters¶
Returns¶
- Generator[S] box
seq_of[T: T, S: Seq[T] ref]¶
Create a Seq from generated values with size in from to to.
Uses boolean-per-element encoding.
fun box seq_of[T: T, S: Seq[T] ref](
gen: Generator[T] box,
from: USize val = 0,
to: USize val = 100)
: Generator[S] box
Parameters¶
Returns¶
- Generator[S] box
shuffled_array_gen[T: T]¶
Generate an array and shuffle it.
Parameters¶
Returns¶
shuffled_iter[T: T]¶
Shuffle the elements of the array and return an iterator.
Parameters¶
- array: Array[T] ref
Returns¶
list_of[T: T]¶
Generate a List[T] with size in from to to.
fun box list_of[T: T](
gen: Generator[T] box,
from: USize val = 0,
to: USize val = 100)
: Generator[List[T] ref] box
Parameters¶
Returns¶
set_of[T: (Hashable #read & Equatable[T] #read)]¶
Generate a Set[T] with elements in from to to.
Uses boolean-per-element encoding with a stall guard for duplicate
rejection.
fun box set_of[T: (Hashable #read & Equatable[T] #read)](
gen: Generator[T] box,
from: USize val = 0,
to: USize val = 100)
: Generator[Set[T]] box
Parameters¶
Returns¶
set_is_of[T: T]¶
Generate a SetIs[T] with elements in from to to.
fun box set_is_of[T: T](
gen: Generator[T] box,
from: USize val = 0,
to: USize val = 100)
: Generator[SetIs[T]] box
Parameters¶
Returns¶
map_of[K: (Hashable #read & Equatable[K] #read), V: V]¶
Generate a Map[K, V] with entries in from to to.
fun box map_of[K: (Hashable #read & Equatable[K] #read), V: V](
gen: Generator[(K , V)] box,
from: USize val = 0,
to: USize val = 100)
: Generator[Map[K, V]] box
Parameters¶
Returns¶
map_is_of[K: K, V: V]¶
Generate a MapIs[K, V] with entries in from to to.
fun box map_is_of[K: K, V: V](
gen: Generator[(K , V)] box,
from: USize val = 0,
to: USize val = 100)
: Generator[MapIs[K, V]] box
Parameters¶
Returns¶
vec_of[T: Any #share]¶
Generate a persistent Vec[T] with size in from to to.
fun box vec_of[T: Any #share](
gen: Generator[T] box,
from: USize val = 0,
to: USize val = 100)
: Generator[Vec[T] val] box
Parameters¶
Returns¶
persistent_list_of[T: Any #share]¶
Generate a persistent List[T] with size in from to to.
fun box persistent_list_of[T: Any #share](
gen: Generator[T] box,
from: USize val = 0,
to: USize val = 100)
: Generator[List[T]] box
Parameters¶
Returns¶
persistent_set_of[T: (Hashable val & Equatable[T] val)]¶
Generate a persistent Set[T] with elements in from to to.
fun box persistent_set_of[T: (Hashable val & Equatable[T] val)](
gen: Generator[T] box,
from: USize val = 0,
to: USize val = 100)
: Generator[Set[T]] box
Parameters¶
Returns¶
persistent_set_is_of[T: Any #share]¶
Generate a persistent SetIs[T] with elements in from to to.
fun box persistent_set_is_of[T: Any #share](
gen: Generator[T] box,
from: USize val = 0,
to: USize val = 100)
: Generator[SetIs[T]] box
Parameters¶
Returns¶
persistent_map_of[K: (Hashable val & Equatable[K] val), V: Any #share]¶
Generate a persistent Map[K, V] with entries in from to to.
fun box persistent_map_of[K: (Hashable val & Equatable[K] val), V: Any #share](
gen: Generator[(K , V)] box,
from: USize val = 0,
to: USize val = 100)
: Generator[Map[K, V]] box
Parameters¶
Returns¶
persistent_map_is_of[K: Any #share, V: Any #share]¶
Generate a persistent MapIs[K, V] with entries in from to to.
fun box persistent_map_is_of[K: Any #share, V: Any #share](
gen: Generator[(K , V)] box,
from: USize val = 0,
to: USize val = 100)
: Generator[MapIs[K, V]] box
Parameters¶
Returns¶
one_of[T: T]¶
Generate a random value from the given ReadSeq.
Errors if xs is empty.
Parameters¶
- xs: ReadSeq[T] box
Returns¶
- Generator[box->T] box
one_of_safe[T: T]¶
Version of one_of that errors at construction time if xs is empty.
Parameters¶
- xs: ReadSeq[T] box
Returns¶
- Generator[box->T] box ?
frequency[T: T]¶
Choose a value from one of the given Generators, weighted by associated weights.
Parameters¶
- weighted_generators: ReadSeq[WeightedGenerator[T]] box
Returns¶
- Generator[T] box
frequency_safe[T: T]¶
Version of frequency that errors if the given weighted_generators is
empty.
fun box frequency_safe[T: T](
weighted_generators: ReadSeq[WeightedGenerator[T]] box)
: Generator[T] box ?
Parameters¶
- weighted_generators: ReadSeq[WeightedGenerator[T]] box
Returns¶
- Generator[T] box ?
zip2[T1: T1, T2: T2]¶
Zip two generators into a generator of a 2-tuple.
fun box zip2[T1: T1, T2: T2](
gen1: Generator[T1] box,
gen2: Generator[T2] box)
: Generator[(T1 , T2)] box
Parameters¶
Returns¶
- Generator[(T1 , T2)] box
zip3[T1: T1, T2: T2, T3: T3]¶
Zip three generators into a generator of a 3-tuple.
fun box zip3[T1: T1, T2: T2, T3: T3](
gen1: Generator[T1] box,
gen2: Generator[T2] box,
gen3: Generator[T3] box)
: Generator[(T1 , T2 , T3)] box
Parameters¶
Returns¶
- Generator[(T1 , T2 , T3)] box
zip4[T1: T1, T2: T2, T3: T3, T4: T4]¶
Zip four generators into a generator of a 4-tuple.
fun box zip4[T1: T1, T2: T2, T3: T3, T4: T4](
gen1: Generator[T1] box,
gen2: Generator[T2] box,
gen3: Generator[T3] box,
gen4: Generator[T4] box)
: Generator[(T1 , T2 , T3 , T4)] box
Parameters¶
Returns¶
- Generator[(T1 , T2 , T3 , T4)] box
map2[T1: T1, T2: T2, T3: T3]¶
Convenience combinator for mapping 2 generators into 1.
fun box map2[T1: T1, T2: T2, T3: T3](
gen1: Generator[T1] box,
gen2: Generator[T2] box,
fn: {(T1, T2): T3^}[T1, T2, T3] ref)
: Generator[T3] box
Parameters¶
Returns¶
- Generator[T3] box
map3[T1: T1, T2: T2, T3: T3, T4: T4]¶
Convenience combinator for mapping 3 generators into 1.
fun box map3[T1: T1, T2: T2, T3: T3, T4: T4](
gen1: Generator[T1] box,
gen2: Generator[T2] box,
gen3: Generator[T3] box,
fn: {(T1, T2, T3): T4^}[T1, T2, T3, T4] ref)
: Generator[T4] box
Parameters¶
- gen1: Generator[T1] box
- gen2: Generator[T2] box
- gen3: Generator[T3] box
- fn: {(T1, T2, T3): T4^}[T1, T2, T3, T4] ref
Returns¶
- Generator[T4] box
map4[T1: T1, T2: T2, T3: T3, T4: T4, T5: T5]¶
Convenience combinator for mapping 4 generators into 1.
fun box map4[T1: T1, T2: T2, T3: T3, T4: T4, T5: T5](
gen1: Generator[T1] box,
gen2: Generator[T2] box,
gen3: Generator[T3] box,
gen4: Generator[T4] box,
fn: {(T1, T2, T3, T4): T5^}[T1, T2, T3, T4, T5] ref)
: Generator[T5] box
Parameters¶
- gen1: Generator[T1] box
- gen2: Generator[T2] box
- gen3: Generator[T3] box
- gen4: Generator[T4] box
- fn: {(T1, T2, T3, T4): T5^}[T1, T2, T3, T4, T5] ref
Returns¶
- Generator[T5] box
bool¶
Generate random Bool values.
Returns¶
u8¶
Generate U8 values in [from, to]. Order does not matter.
Parameters¶
Returns¶
u16¶
Generate U16 values in [from, to]. Order does not matter.
fun box u16(
from: U16 val = U16.min_value(),
to: U16 val = U16.max_value())
: Generator[U16 val] box
Parameters¶
Returns¶
u32¶
Generate U32 values in [from, to]. Order does not matter.
fun box u32(
from: U32 val = U32.min_value(),
to: U32 val = U32.max_value())
: Generator[U32 val] box
Parameters¶
Returns¶
u64¶
Generate U64 values in [from, to]. Order does not matter.
fun box u64(
from: U64 val = U64.min_value(),
to: U64 val = U64.max_value())
: Generator[U64 val] box
Parameters¶
Returns¶
u128¶
Generate U128 values in [from, to]. Order does not matter.
fun box u128(
from: U128 val = U128.min_value(),
to: U128 val = U128.max_value())
: Generator[U128 val] box
Parameters¶
Returns¶
usize¶
Generate USize values in [from, to]. Order does not matter.
fun box usize(
from: USize val = USize.min_value(),
to: USize val = USize.max_value())
: Generator[USize val] box
Parameters¶
Returns¶
ulong¶
Generate ULong values in [from, to]. Order does not matter.
fun box ulong(
from: ULong val = ULong.min_value(),
to: ULong val = ULong.max_value())
: Generator[ULong val] box
Parameters¶
Returns¶
i8¶
Generate I8 values in [from, to]. Order does not matter.
Parameters¶
Returns¶
i16¶
Generate I16 values in [from, to]. Order does not matter.
fun box i16(
from: I16 val = I16.min_value(),
to: I16 val = I16.max_value())
: Generator[I16 val] box
Parameters¶
Returns¶
i32¶
Generate I32 values in [from, to]. Order does not matter.
fun box i32(
from: I32 val = I32.min_value(),
to: I32 val = I32.max_value())
: Generator[I32 val] box
Parameters¶
Returns¶
i64¶
Generate I64 values in [from, to]. Order does not matter.
fun box i64(
from: I64 val = I64.min_value(),
to: I64 val = I64.max_value())
: Generator[I64 val] box
Parameters¶
Returns¶
i128¶
Generate I128 values in [from, to]. Order does not matter.
fun box i128(
from: I128 val = I128.min_value(),
to: I128 val = I128.max_value())
: Generator[I128 val] box
Parameters¶
Returns¶
ilong¶
Generate ILong values in [from, to]. Order does not matter.
fun box ilong(
from: ILong val = ILong.min_value(),
to: ILong val = ILong.max_value())
: Generator[ILong val] box
Parameters¶
Returns¶
isize¶
Generate ISize values in [from, to]. Order does not matter.
fun box isize(
from: ISize val = ISize.min_value(),
to: ISize val = ISize.max_value())
: Generator[ISize val] box
Parameters¶
Returns¶
byte_string¶
Generate a string from bytes with length in from to to.
Uses boolean-per-element encoding.
fun box byte_string(
gen: Generator[U8 val] box,
from: USize val = 0,
to: USize val = 100)
: Generator[String val] box
Parameters¶
Returns¶
ascii¶
Generate a string within the given range with length in from to to.
fun box ascii(
from: USize val = 0,
to: USize val = 100,
range: ASCIIRange = ASCIIAll)
: Generator[String val] box
Parameters¶
- from: USize val = 0
- to: USize val = 100
- range: ASCIIRange = ASCIIAll
Returns¶
ascii_printable¶
Generate strings of printable ASCII characters.
Parameters¶
Returns¶
ascii_numeric¶
Generate strings of numeric ASCII characters.
Parameters¶
Returns¶
ascii_letters¶
Generate strings of ASCII letter characters.
Parameters¶
Returns¶
utf32_codepoint_string¶
Generate a string from unicode codepoints with length in from to to
codepoints.
fun box utf32_codepoint_string(
gen: Generator[U32 val] box,
from: USize val = 0,
to: USize val = 100)
: Generator[String val] box
Parameters¶
Returns¶
unicode¶
Generate a random String of Unicode code points.
Parameters¶
Returns¶
unicode_bmp¶
Generate a random String of Unicode BMP code points.
Parameters¶
Returns¶
eq¶
Parameters¶
- that: Generators val
Returns¶
- Bool val
ne¶
Parameters¶
- that: Generators val
Returns¶
- Bool val