diff options
author | edef <edef@unfathomable.blue> | 2022-05-01 17:57:47 +0000 |
---|---|---|
committer | edef <edef@unfathomable.blue> | 2022-05-01 17:57:47 +0000 |
commit | d9ea1f645cdb855d6713b62bb533c3f6c86619c5 (patch) | |
tree | 8e2ea47cad197a704fbe7d8536a0599ab851053f | |
parent | 8bc30b82e3ad35a18a1696d3bdfa63902254abc0 (diff) | |
download | unf-legacy-d9ea1f645cdb855d6713b62bb533c3f6c86619c5.tar.zst |
ripple/fossil/chunker: simplify and test Chunker::size_hint
Full test coverage for fossil/chunker! :) Change-Id: I0436a266220bbed6d85c291dcca827d1770294dd
-rw-r--r-- | ripple/fossil/src/chunker/mod.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/ripple/fossil/src/chunker/mod.rs b/ripple/fossil/src/chunker/mod.rs index 07b3e8d..c2a9f4c 100644 --- a/ripple/fossil/src/chunker/mod.rs +++ b/ripple/fossil/src/chunker/mod.rs @@ -61,9 +61,6 @@ impl<'a> Iterator for Chunker<'a> { } fn size_hint(&self) -> (usize, Option<usize>) { - if self.buffer.is_empty() { - return (0, Some(0)); - } let min = (self.buffer.len() + MAX_CHUNK_SIZE - 1) / MAX_CHUNK_SIZE; let max = (self.buffer.len() + MIN_CHUNK_SIZE - 1) / MIN_CHUNK_SIZE; (min, Some(max)) @@ -207,4 +204,18 @@ mod test { super::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!( + super::Chunker::from(&[0; super::MAX_CHUNK_SIZE]).size_hint(), + (1, Some(super::MAX_CHUNK_SIZE / super::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)) + ); + } } |