TestChunks   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 20
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A test_chunks_generator() 0 9 2
A test_chunks_sequence() 0 9 2
1
import unittest
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
3
from foil.iteration import chunks
4
5
6
class TestChunks(unittest.TestCase):
7
    def test_chunks_generator(self):
8
        gen = range(0, 8)
9
        chunksize = 3
10
        grouped = chunks(gen, chunksize=chunksize)
11
12
        expected = [(0, 1, 2), (3, 4, 5), (6, 7)]
13
        result = list(tuple(g) for g in grouped)
14
15
        self.assertEqual(expected, result)
16
17
    def test_chunks_sequence(self):
18
        seq = list(range(0, 9))
19
        chunksize = 3
20
        grouped = chunks(seq, chunksize=chunksize)
21
22
        expected = [(0, 1, 2), (3, 4, 5), (6, 7, 8)]
23
        result = [tuple(g) for g in grouped]
24
25
        self.assertEqual(expected, result)
26