use shipper::engine::parallel::chunk_by_max_concurrent;
#[test]
fn bdd_given_empty_input_when_chunking_then_returns_no_batches() {
let items: Vec<String> = vec![];
let max_concurrent = 4;
let chunks = chunk_by_max_concurrent(&items, max_concurrent);
assert!(chunks.is_empty());
}
#[test]
fn bdd_given_limit_three_with_nine_items_then_returns_three_item_chunks() {
let items: Vec<String> = (1..=9).map(|n| format!("crate-{n}")).collect();
let max_concurrent = 3;
let chunks = chunk_by_max_concurrent(&items, max_concurrent);
assert_eq!(chunks.len(), 3);
assert!(chunks.iter().all(|chunk| chunk.len() <= max_concurrent));
assert_eq!(
chunks
.iter()
.flat_map(|chunk| chunk.iter())
.collect::<Vec<_>>(),
items.iter().collect::<Vec<_>>()
);
}