separate mod for tests

This commit is contained in:
NikVolf 2016-09-29 13:39:13 +03:00
parent b477ca17fe
commit 59c0551ff4

View File

@ -209,27 +209,32 @@ pub struct BloomJournal {
pub entries: Vec<(usize, u64)>, pub entries: Vec<(usize, u64)>,
} }
#[test]
fn bloom_test_set() { #[cfg(test)]
mod tests {
use super::Bloom;
#[test]
fn bloom_test_set() {
let mut bloom = Bloom::new(10, 80); let mut bloom = Bloom::new(10, 80);
let key = vec![115u8, 99]; let key = vec![115u8, 99];
assert!(!bloom.check(&key)); assert!(!bloom.check(&key));
bloom.set(&key); bloom.set(&key);
assert!(bloom.check(&key)); assert!(bloom.check(&key));
} }
#[test] #[test]
fn bloom_journalling() { fn bloom_journalling() {
let initial = vec![0u64; 8]; let initial = vec![0u64; 8];
let mut bloom = Bloom::from_parts(&initial, 3); let mut bloom = Bloom::from_parts(&initial, 3);
bloom.set(&vec![5u8, 4]); bloom.set(&vec![5u8, 4]);
let drain = bloom.drain_journal(); let drain = bloom.drain_journal();
assert_eq!(2, drain.entries.len()) assert_eq!(2, drain.entries.len())
} }
#[test] #[test]
fn bloom_howfull() { fn bloom_howfull() {
let initial = vec![0u64; 8]; let initial = vec![0u64; 8];
let mut bloom = Bloom::from_parts(&initial, 3); let mut bloom = Bloom::from_parts(&initial, 3);
bloom.set(&vec![5u8, 4]); bloom.set(&vec![5u8, 4]);
@ -237,4 +242,5 @@ fn bloom_howfull() {
let full = bloom.how_full(); let full = bloom.how_full();
// 2/8/64 = 0.00390625 // 2/8/64 = 0.00390625
assert!(full >= 0.0039f64 && full <= 0.004f64); assert!(full >= 0.0039f64 && full <= 0.004f64);
}
} }