@std/test/property.ms#
Import each required symbol with import Name from "@std/test/property.ms".
Drawn Type#
A generated value and the source after the draws that made it.
type Drawn[T] {
value T
source Source
}Drawn.source#
The source to continue drawing from; draws already made are recorded in it.
source SourceDrawn.value#
The value a generator built from the draws it read.
value TGen Type#
A generator of T values. Build one with the functions in this module and run it
with check.
type Gen[T] {
make fn(move Source) Drawn[T]
}Gen.make#
Reads draws from the source and builds a value.
make fn(move Source) Drawn[T]Gen.filter#
Keeps only the values for which keep is true. After 50 consecutive rejections the
case is marked invalid and discarded.
fn filter(move keep fn(T) Bool) Gen[T]Gen.flat_map#
Generates a value, then generates again with the generator that next returns for
it (dependent generation).
fn flat_map[B](move next fn(T) Gen[B]) Gen[B]Gen.map#
Returns a generator that applies transform to every generated value.
fn map[B](move transform fn(T) B) Gen[B]Gen.zip#
Generates one value from this generator and one from other, and combines them
with combine.
fn zip[B, C](other Gen[B], move combine fn(T, B) C) Gen[C]PropertyOptions Type#
Settings for check: how many cases to generate (default 100) and an optional fixed
seed that replays a failing run.
type PropertyOptions {
runs Int = 100
seed Int? = null
}PropertyOptions.runs#
Number of generated cases (default 100).
runs Int = 100PropertyOptions.seed#
Fixes the random seed to replay a failure; null picks a fresh seed.
seed Int? = nullSettings Type#
Run settings. ms test fills them from --runs, --seed and --fuzz through
environment variables.
type Settings {
runs Int
fuzz_milliseconds Int
seed Int? = null
}Settings.fuzz_milliseconds#
Time budget in milliseconds; above 0, cases run until it expires instead of
stopping at runs.
fuzz_milliseconds IntSettings.runs#
Cases to run when not fuzzing.
runs IntSettings.seed#
First case seed, or null for a random one that failures report.
seed Int? = nullSource Type#
The recorded stream of draws that a generator reads. Create one with source;
generators call draw.
type Source {
choices List[Int]
pos Int
state Int
fresh Bool
invalid Bool
}Source.choices#
Every draw so far, in order, each within its bound.
choices List[Int]Source.fresh#
True while generating new input, false while replaying a recorded prefix (missing draws read as 0).
fresh BoolSource.invalid#
Set by filter when it cannot satisfy its predicate; check discards such cases
instead of running them.
invalid BoolSource.pos#
How many entries of choices the current generation has read.
pos IntSource.state#
Pseudo-random state; fresh draws past the recorded prefix come from it.
state IntSource.next_bits#
Internal: returns the next 64 random bits as a signed Int (SplitMix64).
var fn next_bits() Intbools Function#
Generates true and false, shrinking toward false.
fn bools() Gen[Bool] { ... }check Function#
Runs property on generated values and fails, naming a shrunk counterexample, when it returns an error.
A property returns a Result, like a test assertion; write it with expect_* calls and ?.
A fault (panic) inside a property counts as a failing case and shrinks like an error.
fn check[T](name String, gen Gen[T], property fn(T) Result[Void, Error], options PropertyOptions = PropertyOptions()) Result[Void, Error] { ... }constant Function#
Always generates a copy of value, consuming no draws, so it never shrinks.
fn constant[T Clonable](value T) Gen[T] { ... }draw Function#
Draws an integer from 0 through max, both included, and returns it with the
advanced source; max must not be negative. Fresh draws favor the two ends.
Shrinking lowers each draw toward 0, so 0 is the simplest outcome.
fn draw(move source Source, max Int) Drawn[Int] { ... }element_of Function#
Generates one of values, shrinking toward the first. values must not be empty.
fn element_of[T Clonable](values List[T]) Gen[T] { ... }floats Function#
Generates floats from low through high at 2^-53 resolution, shrinking toward
low. The bounds may be as far apart as the largest finite Floats.
fn floats(low Float, high Float) Gen[Float] { ... }ints Function#
Generates integers from low through high, both included, shrinking toward the
value nearest 0. When the range spans 0, a sign draw comes first and the magnitude
after it. high - low must fit in Int.
fn ints(low Int, high Int) Gen[Int] { ... }lists Function#
Generates lists of min_length through max_length elements, shrinking toward fewer
and simpler elements.
fn lists[T](move gen Gen[T], min_length Int = 0, max_length Int = 20) Gen[List[T]] { ... }one_of Function#
Generates by picking one of gens, shrinking toward the first. gens must not be
empty.
fn one_of[T](gens List[Gen[T]]) Gen[T] { ... }optionals Function#
Generates a value or null, shrinking toward null.
fn optionals[T](move gen Gen[T]) Gen[T?] { ... }pairs Function#
Generates a 2-element Pair.
fn pairs[A, B](move first Gen[A], move second Gen[B]) Gen[Pair[A, B]] { ... }settings Function#
Returns the run settings, with runs as the default case count, after applying the
ms test flag overrides (MS_TEST_RUNS, MS_TEST_SEED, MS_TEST_FUZZ_MS).
fn settings(runs Int = 100) Settings { ... }source Function#
Returns a source that generates fresh input from seed.
fn source(seed Int) Source { ... }strings Function#
Generates strings of up to max_length characters drawn from alphabet, shrinking
toward shorter text of its first characters. alphabet must not be empty.
fn strings(alphabet String = "abcdefghijklmnopqrstuvwxyz0123456789 ", max_length Int = 20) Gen[String] { ... }