Skip to content

Commit

Permalink
Fix test failure
Browse files Browse the repository at this point in the history
sync generator, return iterator when chunk_size is greater than input
`range.end`
  • Loading branch information
tbro committed Feb 18, 2025
1 parent 866abc0 commit a6cfdc1
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions utils/src/synchronous_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ impl ChunkGenerator {
/// Panics if `chunk_size > end`.
// TODO if we make type generic we would take `Range` types here too.
pub fn new(start: u64, end: u64, chunk_size: u64) -> Self {
// TODO maybe instead of panic, behave as an iterator with a
// single item of start..end
if end < chunk_size {
panic!("End bound must be greater than chunk_size");
}
let range = start..end;
let next = if end < chunk_size {
Some(start..end)
} else {
Some(start..(start + chunk_size - 1))
};
Self {
range,
range: start..end,
chunk_size,
next: Some(start..(start + chunk_size - 1)),
next,
}
}
}
Expand Down Expand Up @@ -60,7 +59,13 @@ mod test {
assert_eq![Some(6..8), g.next()];
assert_eq![Some(9..10), g.next()];
assert_eq![None, g.next()];

// Test chunk_size > that range.end
let mut g = ChunkGenerator::new(0, 0, 3);
assert_eq![Some(0..0), g.next()];
assert_eq![None, g.next()];
}

#[test]
#[should_panic]
fn test_generator_panics() {
Expand Down

0 comments on commit a6cfdc1

Please sign in to comment.