use crate::tests::arbitrary::Musk;
use crate::*;
use quickcheck::TestResult;
use quickcheck_macros::quickcheck;
#[quickcheck]
fn vclock_threshold_union(
actor: Musk,
event: u64,
clock_a: VClock<Musk>,
clock_b: VClock<Musk>,
clock_c: VClock<Musk>,
) -> TestResult {
if event == 0 {
return TestResult::discard();
}
let clocks = vec![clock_a, clock_b, clock_c];
let mut tclock = TClock::new();
for clock in clocks.clone() {
tclock.add(clock);
}
let thresholds = vec![1, 2, 3, 4];
let result = thresholds.into_iter().all(|threshold| {
let (clock, equal_to_union) = tclock.threshold_union(threshold as u64);
let result1 = if threshold == 1 { equal_to_union } else { true };
let occurrences = clocks
.iter()
.filter(|clock| clock.contains(&actor, event))
.count();
let result2 = if clock.contains(&actor, event) {
occurrences >= threshold
} else {
occurrences < threshold
};
result1 && result2
});
TestResult::from_bool(result)
}
#[quickcheck]
fn vclock_union(clock_a: VClock<Musk>, clock_b: VClock<Musk>) -> TestResult {
let mut tclock = TClock::new();
tclock.add(clock_a.clone());
tclock.add(clock_b.clone());
let (clock, all_equal) = tclock.union();
let result = if clock_a == clock_b {
clock == clock_a && all_equal
} else {
true
};
TestResult::from_bool(result)
}
#[quickcheck]
fn beclock_threshold_union(
actor: Musk,
event: u64,
clock_a: BEClock<Musk>,
clock_b: BEClock<Musk>,
clock_c: BEClock<Musk>,
) -> TestResult {
if event == 0 {
return TestResult::discard();
}
let clocks = vec![clock_a, clock_b, clock_c];
let mut tclock = TClock::new();
for clock in clocks.clone() {
tclock.add(clock);
}
let thresholds = vec![1, 2, 3, 4];
let result = thresholds.into_iter().all(|threshold| {
let clock = tclock.threshold_union(threshold as u64);
let occurrences = clocks
.iter()
.filter(|clock| clock.contains(&actor, event))
.count();
if clock.contains(&actor, event) {
occurrences >= threshold
} else {
occurrences < threshold
}
});
TestResult::from_bool(result)
}