use crate::MultiSet;
use quickcheck::TestResult;
use quickcheck_macros::quickcheck;
#[quickcheck]
fn singleton(x: String, y: String) -> TestResult {
if x == y {
return TestResult::discard();
}
let mset: MultiSet<String, u64> = MultiSet::from(vec![(x.clone(), 1)]);
let prop = mset.count(&x) == 1 && mset.count(&y) == 0;
TestResult::from_bool(prop)
}
#[quickcheck]
fn add_and_count(l: Vec<(u64, u64)>, mset: MultiSet<u64, u64>) -> bool {
let mut new_mset = mset.clone();
new_mset.add(l.clone());
l.iter()
.all(|(x, _)| new_mset.count(&x) == mset.count(&x) + count(&x, &l))
}
#[quickcheck]
fn threshold(threshold: u64, mset: MultiSet<u64, u64>) -> bool {
mset.threshold(threshold)
.iter()
.all(|x| mset.count(&x) >= threshold)
}
fn count(x: &u64, ls: &Vec<(u64, u64)>) -> u64 {
ls.iter()
.fold(0, |acc, (y, count)| if y == x { acc + count } else { acc })
}