Skip to content

Commit

Permalink
Merge pull request #324 from tzemanovic/tomas/sm-prerequisites
Browse files Browse the repository at this point in the history
state-machine prerequisites
  • Loading branch information
rex-remind101 committed May 22, 2023
2 parents b88e9ff + 6b4df75 commit 5670183
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 2 additions & 0 deletions proptest/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

### Other Notes
- Minimal failing input is now printed using debug pretty-printing
- Made public `VarBitSet`, `SizeRange` read-only methods and num sampling
functions in preparation for release of a `proptest-state-machine` crate.

## 1.1.0

Expand Down
8 changes: 5 additions & 3 deletions proptest/src/bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,13 @@ pub(crate) mod varsize {
#[cfg(not(feature = "bit-set"))]
type Inner = Vec<bool>;

/// A bit set is a set of bit flags.
#[derive(Debug, Clone)]
pub(crate) struct VarBitSet(Inner);
pub struct VarBitSet(Inner);

impl VarBitSet {
pub(crate) fn saturated(len: usize) -> Self {
/// Create a bit set of `len` set values.
pub fn saturated(len: usize) -> Self {
(0..len).collect::<VarBitSet>()
}

Expand Down Expand Up @@ -517,7 +519,7 @@ pub(crate) mod varsize {
}
}

pub(crate) use self::varsize::VarBitSet;
pub use self::varsize::VarBitSet;

#[cfg(test)]
mod test {
Expand Down
11 changes: 7 additions & 4 deletions proptest/src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,23 @@ impl SizeRange {
self.with(Default::default())
}

pub(crate) fn start(&self) -> usize {
/// The lower bound of the range (inclusive).
pub fn start(&self) -> usize {
self.0.start
}

/// Extract the ends `[low, high]` of a `SizeRange`.
pub(crate) fn start_end_incl(&self) -> (usize, usize) {
pub fn start_end_incl(&self) -> (usize, usize) {
(self.start(), self.end_incl())
}

pub(crate) fn end_incl(&self) -> usize {
/// The upper bound of the range (inclusive).
pub fn end_incl(&self) -> usize {
self.0.end - 1
}

pub(crate) fn end_excl(&self) -> usize {
/// The upper bound of the range (exclusive).
pub fn end_excl(&self) -> usize {
self.0.end
}

Expand Down
6 changes: 5 additions & 1 deletion proptest/src/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ use crate::test_runner::TestRunner;
use rand::distributions::uniform::{SampleUniform, Uniform};
use rand::distributions::{Distribution, Standard};

/// Generate a random value of `X`, sampled uniformly from the half
/// open range `[low, high)` (excluding `high`). Panics if `low >= high`.
pub(crate) fn sample_uniform<X: SampleUniform>(
run: &mut TestRunner,
start: X,
Expand All @@ -26,7 +28,9 @@ pub(crate) fn sample_uniform<X: SampleUniform>(
Uniform::new(start, end).sample(run.rng())
}

pub(crate) fn sample_uniform_incl<X: SampleUniform>(
/// Generate a random value of `X`, sampled uniformly from the closed
/// range `[low, high]` (inclusive). Panics if `low > high`.
pub fn sample_uniform_incl<X: SampleUniform>(
run: &mut TestRunner,
start: X,
end: X,
Expand Down

0 comments on commit 5670183

Please sign in to comment.