def test_chunk_happy_path(): data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] expected_results = [ [1, 2, 3, 4], [3, 4, 5, 6], [5, 6, 7, 8], [7, 8, 9, 10], ] assert (np.array(list(chunk(data, 4))) == expected_results).all()
def test_chunk_happy_path_not_even_chunk_size(): data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] expected_results = [ [1, 2, 3], [2, 3, 4], [3, 4, 5], [4, 5, 6], [5, 6, 7], [6, 7, 8], [7, 8, 9], [8, 9, 10], ] assert (np.array(list(chunk(data, 3))) == expected_results).all()
def test_chunk_happy_path_not_even_data(): data = [1, 2, 3, 4, 5, 6, 7] expected_results = [[1, 2, 3, 4], [3, 4, 5, 6], [5, 6, 7]] assert list(map(list, list(chunk(data, 4)))) == expected_results
def test_chunk_size_bigger_than_data(): assert (np.array(list(chunk([1, 2, 3], 10))) == [[1, 2, 3]]).all()
def test_chunk_empty_list(): assert list(chunk([], 5)) == []