1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
//! Dicetest is a framework for writing tests with pseudorandom generated test data.
//!
//! ## Status of this crate
//!
//! The author does not consider this crate as stable yet.
//!
//! ## Simple example
//!
//! Here's an example of a broken sort function tested with Dicetest:
//! ```
//! fn bubble_sort<T: Ord>(slice: &mut [T]) {
//!     let len = slice.len();
//!
//!     for _ in 0..len {
//!         for j in 1..len - 1 {
//!             let jpp = j + 1;
//!             if slice[j] > slice[jpp] {
//!                 slice.swap(j, jpp);
//!             }
//!         }
//!     }
//! }
//!
//! #[cfg(test)]
//! mod tests {
//!     use super::*;
//!     use dicetest::prelude::tests::*;
//!
//!     #[test]
//!     fn result_of_bubble_sort_is_sorted() {
//!         dicetest!(|fate| {
//!             let mut v = dice::vec(dice::u8(..), ..).roll(fate);
//!             hint!("unsorted: {:?}", v);
//!
//!             bubble_sort(&mut v);
//!             hint!("  sorted: {:?}", v);
//!
//!             let is_sorted = v.windows(2).all(|w| w[0] <= w[1]);
//!             assert!(is_sorted);
//!         })
//!     }
//! }
//! ```
//!
//! Running `cargo test` produces the following output:
//! ```text
//! The test failed after 36 passes.
//!
//! # Config
//! - seed: 795359663177100823
//! - start limit: 0
//! - end limit: 100
//! - passes: 1000
//!
//! # Counterexample
//! - run code: "ABIDje/+CYVkmmCVTwKJ2go6VrzZWMjO2Bqc9m3b3h0DAAAAAAAAAA=="
//! - limit: 3
//! - hints:
//!     - unsorted: [255, 252, 131]
//!     -   sorted: [255, 131, 252]
//! - error: assertion failed: is_sorted
//! ```
//!
//! You can rerun the counterexample by setting a environment variable:
//! ```text
//! DICETEST_DEBUG=ABIDje/+CYVkmmCVTwKJ2go6VrzZWMjO2Bqc9m3b3h0DAAAAAAAAAA== cargo test
//! ```
//!
//! ## Alternatives
//!
//! * Write down your test data and use a loop.
//! * Use the crate `quickcheck`.
//! * Use the crate `proptest`.

mod macros;

mod util;

pub mod prand;

pub mod hints;

pub mod stats;

pub mod codie;

pub mod codice;

pub mod die;

pub mod dice;

pub mod runner;

pub mod formatter;

pub mod checker;

pub mod prelude;

#[cfg(test)]
mod asserts;