aboutsummaryrefslogtreecommitdiff
path: root/wqflask/tests/unit/utility/test_chunks.py
blob: 8d90a1ec62e940b92c7f9bb5154ad302b3620547 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""Test chunking"""

import unittest

from utility.chunks import divide_into_chunks


class TestChunks(unittest.TestCase):
    "Test Utility method for chunking"
    def test_divide_into_chunks(self):
        "Check that a list is chunked correctly"
        self.assertEqual(divide_into_chunks([1, 2, 7, 3, 22, 8, 5, 22, 333], 3),
                         [[1, 2, 7], [3, 22, 8], [5, 22, 333]])
        self.assertEqual(divide_into_chunks([1, 2, 7, 3, 22, 8, 5, 22, 333], 4),
                         [[1, 2, 7], [3, 22, 8], [5, 22, 333]])
        self.assertEqual(divide_into_chunks([1, 2, 7, 3, 22, 8, 5, 22, 333], 5),
                         [[1, 2], [7, 3], [22, 8], [5, 22], [333]])
        self.assertEqual(divide_into_chunks([], 5),
                         [[]])