|
| 1 | +"""Tests for utility functions.""" |
| 2 | + |
| 3 | +from lazy_ecs.core.utils import batch_items |
| 4 | + |
| 5 | + |
| 6 | +def test_batch_items_basic(): |
| 7 | + items = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |
| 8 | + batches = list(batch_items(items, 3)) |
| 9 | + |
| 10 | + assert len(batches) == 4 |
| 11 | + assert batches[0] == [1, 2, 3] |
| 12 | + assert batches[1] == [4, 5, 6] |
| 13 | + assert batches[2] == [7, 8, 9] |
| 14 | + assert batches[3] == [10] |
| 15 | + |
| 16 | + |
| 17 | +def test_batch_items_exact_fit(): |
| 18 | + items = [1, 2, 3, 4, 5, 6] |
| 19 | + batches = list(batch_items(items, 3)) |
| 20 | + |
| 21 | + assert len(batches) == 2 |
| 22 | + assert batches[0] == [1, 2, 3] |
| 23 | + assert batches[1] == [4, 5, 6] |
| 24 | + |
| 25 | + |
| 26 | +def test_batch_items_single_batch(): |
| 27 | + items = [1, 2, 3] |
| 28 | + batches = list(batch_items(items, 10)) |
| 29 | + |
| 30 | + assert len(batches) == 1 |
| 31 | + assert batches[0] == [1, 2, 3] |
| 32 | + |
| 33 | + |
| 34 | +def test_batch_items_empty_list(): |
| 35 | + items = [] |
| 36 | + batches = list(batch_items(items, 5)) |
| 37 | + |
| 38 | + assert len(batches) == 0 |
| 39 | + |
| 40 | + |
| 41 | +def test_batch_items_size_one(): |
| 42 | + items = [1, 2, 3, 4, 5] |
| 43 | + batches = list(batch_items(items, 1)) |
| 44 | + |
| 45 | + assert len(batches) == 5 |
| 46 | + assert batches[0] == [1] |
| 47 | + assert batches[1] == [2] |
| 48 | + assert batches[2] == [3] |
| 49 | + assert batches[3] == [4] |
| 50 | + assert batches[4] == [5] |
| 51 | + |
| 52 | + |
| 53 | +def test_batch_items_strings(): |
| 54 | + items = ["a", "b", "c", "d", "e", "f", "g"] |
| 55 | + batches = list(batch_items(items, 3)) |
| 56 | + |
| 57 | + assert len(batches) == 3 |
| 58 | + assert batches[0] == ["a", "b", "c"] |
| 59 | + assert batches[1] == ["d", "e", "f"] |
| 60 | + assert batches[2] == ["g"] |
0 commit comments