#![cfg(feature = "rsyncable")]
use hash_roll::gzip::GzipRsyncable;
use hash_roll::Splitter;
#[test]
fn test_rsyncable() {
use std::collections::HashSet;
let d1 = b"hello, this is some bytes";
let mut d2 = d1.clone();
d2[4] = ':' as u8;
let b1 = GzipRsyncable::with_window_and_modulus(4, 8).into_vecs(d1.iter().cloned());
let b2 = GzipRsyncable::with_window_and_modulus(4, 8).into_vecs(d2.iter().cloned());
let c1 = b1.clone().count();
let c2 = b2.clone().count();
assert_eq!(c1, 4);
assert!((c1 as i64 - c2 as i64).abs() < 1);
let mut blocks = HashSet::with_capacity(c1);
let mut common_in_b1 = 0u64;
for b in b1 {
if !blocks.insert(b) {
common_in_b1 += 1;
}
}
println!("common in b1: {}", common_in_b1);
let mut shared_blocks = 0u64;
for b in b2 {
if blocks.contains(&b) {
shared_blocks += 1;
}
}
println!("shared blocks: {}", shared_blocks);
assert!(shared_blocks > (c1 as u64) / 2);
}