Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

api: add Gen::set_size and Gen::from_seed #278

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions src/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,33 @@ pub struct Gen {
}

impl Gen {
/// Returns a `Gen` with the given size configuration.
pub(crate) const DEFAULT_SIZE: usize = 100;

/// Returns a `Gen` with a random seed and the given size configuration.
pub fn new(size: usize) -> Gen {
Gen { rng: rand::rngs::SmallRng::from_entropy(), size: size }
}

/// Returns a `Gen` with the given seed and a default size configuration.
///
/// Two `Gen`s created with the same seed will generate the same values. Though the values
/// may vary between QuickCheck releases.
pub fn from_seed(seed: u64) -> Gen {
Gen {
rng: rand::rngs::SmallRng::seed_from_u64(seed),
size: Self::DEFAULT_SIZE,
}
}

/// Sets the size configuration for this generator.
///
/// The `size` parameter controls the size of random values generated.
/// For example, it specifies the maximum length of a randomly generated
/// vector, but is and should not be used to control the range of a
/// randomly generated number. (Unless that number is used to control the
/// size of a data structure.)
pub fn new(size: usize) -> Gen {
Gen { rng: rand::rngs::SmallRng::from_entropy(), size: size }
pub fn set_size(&mut self, size: usize) {
self.size = size;
}

/// Returns the size configured with this generator.
Expand Down
2 changes: 1 addition & 1 deletion src/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn qc_max_tests() -> u64 {
}

fn qc_gen_size() -> usize {
let default = 100;
let default = Gen::DEFAULT_SIZE;
match env::var("QUICKCHECK_GENERATOR_SIZE") {
Ok(val) => val.parse().unwrap_or(default),
Err(_) => default,
Expand Down