diff options
Diffstat (limited to 'ripple/fossil/src')
-rw-r--r-- | ripple/fossil/src/chunker/mod.rs | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/ripple/fossil/src/chunker/mod.rs b/ripple/fossil/src/chunker/mod.rs index 638b6fa..e5221c3 100644 --- a/ripple/fossil/src/chunker/mod.rs +++ b/ripple/fossil/src/chunker/mod.rs @@ -70,7 +70,10 @@ impl<'a> Iterator for Chunker<'a> { #[cfg(test)] mod test { - use std::io::Read; + use { + super::{Chunker, MAX_CHUNK_SIZE, MIN_CHUNK_SIZE, WINDOW_SIZE}, + std::io::Read, + }; fn generate(length: usize) -> Vec<u8> { let mut h = blake3::Hasher::new(); @@ -153,7 +156,7 @@ mod test { #[test] fn golden() { let data = generate(1024 * 64 * 64); - let chunks = super::Chunker::from(&data).map(blake3::hash); + let chunks = Chunker::from(&data).map(blake3::hash); for (actual, &expected) in chunks.zip(GOLDEN.iter()) { assert_eq!(actual, blake3::Hash::from(expected)); } @@ -164,11 +167,11 @@ mod test { // all-zero byte sequences don't contain any split points, // so the chunker is forced to limit the chunk size assert_eq!( - super::Chunker::from(&[0u8; super::MAX_CHUNK_SIZE + 1]) + Chunker::from(&[0u8; MAX_CHUNK_SIZE + 1]) .next() .unwrap() .len(), - super::MAX_CHUNK_SIZE + MAX_CHUNK_SIZE ); } @@ -179,44 +182,41 @@ mod test { // a "tail" is a window-sized byte sequence that terminates a chunk // we extract one from our test vectors, since every chunk smaller // than MAX_CHUNK_SIZE ends in a tail - let mut tail = [0; super::WINDOW_SIZE]; + let mut tail = [0; WINDOW_SIZE]; tail.copy_from_slice({ - let chunk = super::Chunker::from(&data).next().unwrap(); - chunk.rchunks_exact(super::WINDOW_SIZE).next().unwrap() + let chunk = Chunker::from(&data).next().unwrap(); + chunk.rchunks_exact(WINDOW_SIZE).next().unwrap() }); - let mut data = vec![0; super::MIN_CHUNK_SIZE - super::WINDOW_SIZE]; + let mut data = vec![0; MIN_CHUNK_SIZE - WINDOW_SIZE]; data.extend(tail); data.push(0); - assert_eq!( - super::Chunker::from(&data).next().unwrap().len(), - super::MIN_CHUNK_SIZE - ); + assert_eq!(Chunker::from(&data).next().unwrap().len(), MIN_CHUNK_SIZE); } #[test] fn short_chunk() { assert_eq!( - super::Chunker::from(&[0u8; super::MIN_CHUNK_SIZE / 2]) + Chunker::from(&[0u8; MIN_CHUNK_SIZE / 2]) .next() .unwrap() .len(), - super::MIN_CHUNK_SIZE / 2 + MIN_CHUNK_SIZE / 2 ); } #[test] fn size_hint() { - assert_eq!(super::Chunker::from(&[]).size_hint(), (0, Some(0))); - assert_eq!(super::Chunker::from(&[0]).size_hint(), (1, Some(1))); + assert_eq!(Chunker::from(&[]).size_hint(), (0, Some(0))); + assert_eq!(Chunker::from(&[0]).size_hint(), (1, Some(1))); assert_eq!( - super::Chunker::from(&[0; super::MAX_CHUNK_SIZE]).size_hint(), - (1, Some(super::MAX_CHUNK_SIZE / super::MIN_CHUNK_SIZE)) + Chunker::from(&[0; MAX_CHUNK_SIZE]).size_hint(), + (1, Some(MAX_CHUNK_SIZE / MIN_CHUNK_SIZE)) ); assert_eq!( - super::Chunker::from(&[0; super::MAX_CHUNK_SIZE + 1]).size_hint(), - (2, Some(super::MAX_CHUNK_SIZE / super::MIN_CHUNK_SIZE + 1)) + Chunker::from(&[0; MAX_CHUNK_SIZE + 1]).size_hint(), + (2, Some(MAX_CHUNK_SIZE / MIN_CHUNK_SIZE + 1)) ); } } |