Skip to main content

Crate dicetest

Crate dicetest 

Source
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 DieOnce and Die adapters.
codice
The standard collection of Codie implementations.
dice
The standard collection of DieOnce and Die implementations.
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 format macro.
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 format macro as stat value.
stat_debug
Creates a stat with the stringified argument as stat key and the argument value converted with Debug as 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 DieOnce and Die.
Limit
The upper limit for the length of dynamic data structures generated with DieOnce and Die.
Prng
A pseudorandom number generator.
Seed
A seed for pseudorandomness.

Traits§

Codie
Trait for converting values of type T into a seed.
Dice
Provides a Die implementation that generats pseudorandom values of Self.
Die
Trait for generating pseudorandom values of type T.
DieOnce
Trait for generating a single pseudorandom value of type T.

Functions§

die
Summons a Die for T based on Dice.

Derive Macros§

Dicederive
Derives the trait Dice for structs and enums.