def test_split_even_size_chunks(self): chunks = chunk_array([1, 2, 3, 4], 2) self.assertEqual(chunks, [[1, 2], [3, 4]]) chunks = chunk_array([1, 2, 3, 4, 5, 6, 7, 8, 9], 2) self.assertEqual(chunks, [[1, 2, 3, 4, 5], [6, 7, 8, 9]]) chunks = chunk_array([1, 2, 3, 4, 5, 6, 7, 8, 9], 3) self.assertEqual(chunks, [[1, 2, 3], [4, 5, 6], [7, 8, 9]])
def test_spilt_into_too_many_chunks(self): with self.assertRaises(AssertionError): chunk_array([1, 2, 3, 4], 7)
def test_split_into_one_chunk(self): chunks = chunk_array([1, 2, 3, 4, 5, 6, 7], 7) self.assertEqual(chunks, [[1, 2, 3, 4, 5, 6, 7]])
def test_split_into_no_chunks(self): with self.assertRaises(AssertionError): chunk_array([1, 2, 3], 0)
def test_split_chunks_with_remainder(self): chunks = chunk_array([1, 2, 3, 4, 5], 3) self.assertEqual(chunks, [[1, 2], [3, 4], [5]]) chunks = chunk_array([1, 2, 3, 4, 5], 2) self.assertEqual(chunks, [[1, 2, 3], [4, 5]])