#![allow(clippy::expect_used, clippy::panic, clippy::unwrap_used)]
use flashsieve::NgramBloom;
#[test]
fn bloom_handles_all_possible_2byte_pairs() {
let mut bloom = NgramBloom::new(1_048_576).unwrap(); for a in 0u16..=255 {
for b in 0u16..=255 {
bloom.insert_ngram((a & 0xFF) as u8, (b & 0xFF) as u8);
}
}
for a in 0u16..=255 {
for b in 0u16..=255 {
assert!(
bloom.maybe_contains((a & 0xFF) as u8, (b & 0xFF) as u8),
"false negative for ({a}, {b})"
);
}
}
}
#[test]
fn bloom_from_1mb_block() {
let data: Vec<u8> = (0u32..1_048_576)
.map(|i| ((i.wrapping_mul(2_654_435_761)) >> 24) as u8)
.collect();
let bloom = NgramBloom::from_block(&data, 65536).unwrap();
assert!(bloom.maybe_contains(data[0], data[1]));
}
#[test]
fn bloom_rejects_impossible_pair() {
let data = b"hello world this is all ascii text for testing bloom rejection";
let bloom = NgramBloom::from_block(data, 4096).unwrap();
let mut rejections = 0;
for a in 240u8..=255 {
for b in 240u8..=255 {
if !bloom.maybe_contains(a, b) {
rejections += 1;
}
}
}
assert!(rejections > 0, "bloom should reject some non-ASCII pairs");
}