From d9ea1f645cdb855d6713b62bb533c3f6c86619c5 Mon Sep 17 00:00:00 2001 From: edef Date: Sun, 1 May 2022 17:57:47 +0000 Subject: ripple/fossil/chunker: simplify and test Chunker::size_hint Full test coverage for fossil/chunker! :) Change-Id: I0436a266220bbed6d85c291dcca827d1770294dd --- ripple/fossil/src/chunker/mod.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'ripple/fossil') 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) { - 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)) + ); + } } -- cgit 1.4.1