Skip to content

Generators

[Source]

Convenience combinators and factories for common types of Generators.

primitive val Generators

Constructors

create

[Source]

new val create()
: Generators val^

Returns


Public Functions

unit[T: T]

[Source]

Generate a reference to the same value over and over again.

fun box unit[T: T](
  t: T)
: Generator[box->T] box

Parameters

  • t: T

Returns


none[T: None val]

[Source]

Always generate None.

fun box none[T: None val]()
: Generator[(T | None val)] box

Returns


repeatedly[T: T]

[Source]

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.

fun box repeatedly[T: T](
  f: {(): T^ ?}[T] box)
: Generator[T] box

Parameters

  • f: {(): T^ ?}[T] box

Returns


array_of[T: T]

[Source]

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]

[Source]

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


seq_of[T: T, S: Seq[T] ref]

[Source]

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


shuffled_array_gen[T: T]

[Source]

Generate an array and shuffle it.

fun box shuffled_array_gen[T: T](
  gen: Generator[Array[T] ref] box)
: Generator[Array[T] ref] box

Parameters

Returns


shuffled_iter[T: T]

[Source]

Shuffle the elements of the array and return an iterator.

fun box shuffled_iter[T: T](
  array: Array[T] ref)
: Generator[Iterator[this->T!] ref] box

Parameters

Returns


list_of[T: T]

[Source]

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)]

[Source]

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]

[Source]

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]

[Source]

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]

[Source]

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]

[Source]

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]

[Source]

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)]

[Source]

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]

[Source]

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]

[Source]

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]

[Source]

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]

[Source]

Generate a random value from the given ReadSeq. Errors if xs is empty.

fun box one_of[T: T](
  xs: ReadSeq[T] box)
: Generator[box->T] box

Parameters

Returns


one_of_safe[T: T]

[Source]

Version of one_of that errors at construction time if xs is empty.

fun box one_of_safe[T: T](
  xs: ReadSeq[T] box)
: Generator[box->T] box ?

Parameters

Returns


frequency[T: T]

[Source]

Choose a value from one of the given Generators, weighted by associated weights.

fun box frequency[T: T](
  weighted_generators: ReadSeq[WeightedGenerator[T]] box)
: Generator[T] box

Parameters

Returns


frequency_safe[T: T]

[Source]

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

Returns


zip2[T1: T1, T2: T2]

[Source]

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


zip3[T1: T1, T2: T2, T3: T3]

[Source]

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


zip4[T1: T1, T2: T2, T3: T3, T4: T4]

[Source]

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


map2[T1: T1, T2: T2, T3: T3]

[Source]

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


map3[T1: T1, T2: T2, T3: T3, T4: T4]

[Source]

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

Returns


map4[T1: T1, T2: T2, T3: T3, T4: T4, T5: T5]

[Source]

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

Returns


bool

[Source]

Generate random Bool values.

fun box bool()
: Generator[Bool val] box

Returns


u8

[Source]

Generate U8 values in [from, to]. Order does not matter.

fun box u8(
  from: U8 val = U8.min_value(),
  to: U8 val = U8.max_value())
: Generator[U8 val] box

Parameters

  • from: U8 val = U8.min_value()
  • to: U8 val = U8.max_value()

Returns


u16

[Source]

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

  • from: U16 val = U16.min_value()
  • to: U16 val = U16.max_value()

Returns


u32

[Source]

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

  • from: U32 val = U32.min_value()
  • to: U32 val = U32.max_value()

Returns


u64

[Source]

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

  • from: U64 val = U64.min_value()
  • to: U64 val = U64.max_value()

Returns


u128

[Source]

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

  • from: U128 val = U128.min_value()
  • to: U128 val = U128.max_value()

Returns


usize

[Source]

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

  • from: USize val = USize.min_value()
  • to: USize val = USize.max_value()

Returns


ulong

[Source]

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

  • from: ULong val = ULong.min_value()
  • to: ULong val = ULong.max_value()

Returns


i8

[Source]

Generate I8 values in [from, to]. Order does not matter.

fun box i8(
  from: I8 val = I8.min_value(),
  to: I8 val = I8.max_value())
: Generator[I8 val] box

Parameters

  • from: I8 val = I8.min_value()
  • to: I8 val = I8.max_value()

Returns


i16

[Source]

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

  • from: I16 val = I16.min_value()
  • to: I16 val = I16.max_value()

Returns


i32

[Source]

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

  • from: I32 val = I32.min_value()
  • to: I32 val = I32.max_value()

Returns


i64

[Source]

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

  • from: I64 val = I64.min_value()
  • to: I64 val = I64.max_value()

Returns


i128

[Source]

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

  • from: I128 val = I128.min_value()
  • to: I128 val = I128.max_value()

Returns


ilong

[Source]

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

  • from: ILong val = ILong.min_value()
  • to: ILong val = ILong.max_value()

Returns


isize

[Source]

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

  • from: ISize val = ISize.min_value()
  • to: ISize val = ISize.max_value()

Returns


byte_string

[Source]

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

[Source]

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

Returns


ascii_printable

[Source]

Generate strings of printable ASCII characters.

fun box ascii_printable(
  from: USize val = 0,
  to: USize val = 100)
: Generator[String val] box

Parameters

Returns


ascii_numeric

[Source]

Generate strings of numeric ASCII characters.

fun box ascii_numeric(
  from: USize val = 0,
  to: USize val = 100)
: Generator[String val] box

Parameters

Returns


ascii_letters

[Source]

Generate strings of ASCII letter characters.

fun box ascii_letters(
  from: USize val = 0,
  to: USize val = 100)
: Generator[String val] box

Parameters

Returns


utf32_codepoint_string

[Source]

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

[Source]

Generate a random String of Unicode code points.

fun box unicode(
  from: USize val = 0,
  to: USize val = 100)
: Generator[String val] box

Parameters

Returns


unicode_bmp

[Source]

Generate a random String of Unicode BMP code points.

fun box unicode_bmp(
  from: USize val = 0,
  to: USize val = 100)
: Generator[String val] box

Parameters

Returns


eq

[Source]

fun box eq(
  that: Generators val)
: Bool val

Parameters

Returns


ne

[Source]

fun box ne(
  that: Generators val)
: Bool val

Parameters

Returns