Expand description
Framework for writing tests with randomly generated test data.
For more information see the guide.
§Example
use dicetest::prelude::*;
#[test]
fn result_of_sort_is_sorted() {
Dicetest::repeatedly().run(|mut fate| {
let mut vec: Vec<u8> = fate.roll(die());
hint!("unsorted: {:?}", vec);
vec.sort();
hint!(" sorted: {:?}", vec);
let is_sorted = vec.windows(2).all(|w| w[0] <= w[1]);
assert!(is_sorted);
})
}§Feature flags
There are several feature flags for disabling runtime overhead or enabling additional features at compile time.
§derive (disabled by default)
If enabled, a derive macro for Dice is available.
§hints (enabled by default)
Enables or disables the hints feature at compile time. If disabled, all hints operations are no-ops.
§stats (enabled by default)
Enables or disables the stats feature at compile time. If disabled, all stats operations are no-ops.
Modules§
- adapters
- A collection of
DieOnceandDieadapters. - codice
- The standard collection of
Codieimplementations. - dice
- The standard collection of
DieOnceandDieimplementations. - hints
- Hints help to analyze a single test run, mostly the counterexample.
- prelude
- Contains the most useful imports for writing tests and value generators.
- runner
- A runner for tests with pseudorandomly generated test data.
- stats
- Stats help to analyze repeated test runs.
Macros§
- hint
- Adds a hint that contains the arguments applied to the
formatmacro. - hint_
debug - Adds a hint that contains the stringified argument and the argument value converted with
Debug. - hint_
section - Indents all hints in the caller’s code block after this macro is called.
- stat
- Creates a stat with the first argument as stat key and the remaining arguments applied to the
formatmacro as stat value. - stat_
debug - Creates a stat with the stringified argument as stat key and the argument value converted with
Debugas stat value.
Structs§
- Dicetest
- Front end for configuring and running a test with pseudorandomly generated test data.
- Fate
- Contains parameters for controlling the value generation with
DieOnceandDie. - Limit
- The upper limit for the length of dynamic data structures generated with
DieOnceandDie. - Prng
- A pseudorandom number generator.
- Seed
- A seed for pseudorandomness.
Traits§
- Codie
- Trait for converting values of type
Tinto a seed. - Dice
- Provides a
Dieimplementation that generats pseudorandom values ofSelf. - Die
- Trait for generating pseudorandom values of type
T. - DieOnce
- Trait for generating a single pseudorandom value of type
T.