From 767824676c0b1c783f2f378bcb8bbaf65fa6fe7a Mon Sep 17 00:00:00 2001 From: Mikael Forsberg Date: Thu, 26 Sep 2024 08:48:49 +0200 Subject: [PATCH 1/2] doc: add book section on controlling number of operations generated --- book/src/features/structured-testing.md | 44 ++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/book/src/features/structured-testing.md b/book/src/features/structured-testing.md index 27d0cccc..7bec580b 100644 --- a/book/src/features/structured-testing.md +++ b/book/src/features/structured-testing.md @@ -59,7 +59,49 @@ fn main() { } ``` -This basic test will make sure we don't panic on any of the list of operations. We can take it to the next step by using a test oracle to make sure the behavior of `MySet` is actually correct. Here we'll use `HashSet` from the `std` library: +## Controlling The Number Of Operations Generated + +Using `check!().with_type::>()` will generate vectors with lengths in the range `0..=64`. If you need more control over the number of elements being generated you can instead use `.with_generator` and provide a customized generator: + +```rust +# use bolero::{check, generator::*}; +use bolero::gen; +# use my_set::MySet; + +# #[derive(Debug, TypeGenerator)] +# enum Operation { +# Insert(u64), +# Remove(u64), +# Clear, +# } +# +fn main() { + check!() + // Generate 0 to 200 operations + .with_generator(gen::>().with().len(0..=200)) + .for_each(|operations| { +# let mut set = MySet::new(); +# +# for operation in operations.iter() { +# match operation { +# Operation::Insert(value) => { +# set.insert(value); +# } +# Operation::Remove(value) => { +# set.remove(value); +# } +# Operation::Clear => { +# set.clear(); +# } +# } +# } +# }) +# } +``` + +## Using Test Oracles + +The basic test we constructed above will make sure we don't panic on any of the list of operations. We can take it to the next step by using a test oracle to make sure the behavior of `MySet` is actually correct. Here we'll use `HashSet` from the `std` library: ```rust use bolero::{check, generator::*}; From 59aa7115ed75bc8b1771e171916a3501f0e34772 Mon Sep 17 00:00:00 2001 From: Mikael Forsberg Date: Fri, 27 Sep 2024 06:47:35 +0200 Subject: [PATCH 2/2] Update book/src/features/structured-testing.md Co-authored-by: Cameron Bytheway --- book/src/features/structured-testing.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/book/src/features/structured-testing.md b/book/src/features/structured-testing.md index 7bec580b..f462743e 100644 --- a/book/src/features/structured-testing.md +++ b/book/src/features/structured-testing.md @@ -95,8 +95,9 @@ fn main() { # } # } # } -# }) -# } + // assertions go here + }) +} ``` ## Using Test Oracles