Skip to content

Commit

Permalink
Add arbitrary simple shrink tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorenesduarte committed Mar 9, 2019
1 parent 2933b8c commit e7619a4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/arbitrary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,33 @@ impl<T: Actor + Arbitrary> Arbitrary for VClock<T> {
Box::new(vec.shrink().map(|v| VClock::from_vec(v)))
}
}

#[cfg(test)]
mod test {
use crate::*;
use quickcheck::{Arbitrary, StdThreadGen};

#[test]
fn multiset_shrink() {
let count = shrink_count::<MultiSet<u64>>();
assert!(count > 0);
}

#[test]
fn dot_shrink() {
let count = shrink_count::<Dot<u64>>();
assert!(count == 0);
}

#[test]
fn vclock_shrink() {
let count = shrink_count::<VClock<u64>>();
assert!(count > 0);
}

fn shrink_count<T: Arbitrary>() -> usize {
let mut g = StdThreadGen::new(100);
let instance: T = Arbitrary::arbitrary(&mut g);
instance.shrink().count()
}
}
4 changes: 3 additions & 1 deletion src/multiset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ impl<T: Ord> MultiSet<T> {
/// assert_eq!(mset.count(&17), 1);
/// ```
pub fn singleton(elem: T) -> Self {
Self::from_vec(vec![(elem, 1)])
let mut mset = Self::new();
mset.add_elem(elem);
mset
}

/// Creates a new `MultiSet` from a vector of tuples (elem, elem count).
Expand Down

0 comments on commit e7619a4

Please sign in to comment.