test_count_neighbours   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 315
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 241
dl 0
loc 315
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A Tests.test_Extra() 0 3 2
A Tests.test_Basics() 0 3 2
1
import unittest
2
3
from count_neighbours import count_neighbours
4
5
6
class Tests(unittest.TestCase):
7
    TESTS = {
8
        "Basics": [
9
            {
10
                "input": (
11
                    (
12
                        (1, 0, 0, 1, 0),
13
                        (0, 1, 0, 0, 0),
14
                        (0, 0, 1, 0, 1),
15
                        (1, 0, 0, 0, 0),
16
                        (0, 0, 1, 0, 0),
17
                    ),
18
                    1,
19
                    2,
20
                ),
21
                "answer": 3,
22
            },
23
            {
24
                "input": (
25
                    (
26
                        (1, 0, 0, 1, 0),
27
                        (0, 1, 0, 0, 0),
28
                        (0, 0, 1, 0, 1),
29
                        (1, 0, 0, 0, 0),
30
                        (0, 0, 1, 0, 0),
31
                    ),
32
                    0,
33
                    0,
34
                ),
35
                "answer": 1,
36
            },
37
            {"input": (((1, 1, 1), (1, 1, 1), (1, 1, 1)), 0, 2), "answer": 3},
38
            {"input": (((0, 0, 0), (0, 1, 0), (0, 0, 0)), 1, 1), "answer": 0},
39
        ],
40
        "Extra": [
41
            {"input": [[[1, 1, 1], [1, 1, 1], [1, 1, 1]], 1, 2], "answer": 5},
42
            {
43
                "input": [
44
                    [
45
                        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
46
                        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
47
                        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
48
                        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
49
                        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
50
                        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
51
                        [1, 1, 1, 1, 0, 1, 1, 1, 1, 1],
52
                        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
53
                        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
54
                        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
55
                        [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
56
                    ],
57
                    5,
58
                    5,
59
                ],
60
                "answer": 7,
61
            },
62
            {
63
                "input": [
64
                    [
65
                        [1, 0, 1, 0, 1],
66
                        [0, 1, 0, 1, 0],
67
                        [1, 0, 1, 0, 1],
68
                        [0, 1, 0, 1, 0],
69
                        [1, 0, 1, 0, 1],
70
                        [0, 1, 0, 1, 0],
71
                    ],
72
                    5,
73
                    4,
74
                ],
75
                "answer": 2,
76
            },
77
            {
78
                "input": [
79
                    [
80
                        [1, 0, 1, 0, 1],
81
                        [0, 1, 0, 1, 0],
82
                        [1, 0, 1, 0, 1],
83
                        [0, 1, 0, 1, 0],
84
                        [1, 1, 1, 0, 1],
85
                        [0, 1, 0, 1, 0],
86
                    ],
87
                    5,
88
                    0,
89
                ],
90
                "answer": 3,
91
            },
92
            {
93
                "input": [
94
                    [
95
                        [1, 1, 1, 0, 1, 1, 1, 0, 0, 1],
96
                        [1, 0, 0, 1, 1, 1, 1, 1, 0, 0],
97
                        [0, 1, 0, 0, 0, 0, 1, 1, 1, 1],
98
                        [1, 0, 1, 1, 1, 0, 1, 1, 1, 1],
99
                        [1, 1, 1, 0, 1, 1, 1, 1, 1, 1],
100
                        [0, 0, 0, 1, 1, 1, 1, 1, 1, 1],
101
                        [1, 0, 1, 1, 0, 0, 0, 1, 1, 1],
102
                        [0, 0, 1, 0, 0, 1, 0, 0, 1, 0],
103
                        [1, 0, 0, 0, 0, 1, 1, 1, 0, 1],
104
                        [1, 1, 0, 1, 1, 0, 1, 1, 0, 0],
105
                    ],
106
                    5,
107
                    6,
108
                ],
109
                "answer": 6,
110
            },
111
            {
112
                "input": [
113
                    [
114
                        [0, 1, 1, 0, 0, 0, 1, 1, 1, 1],
115
                        [0, 0, 0, 1, 1, 0, 0, 1, 1, 0],
116
                        [1, 0, 1, 1, 0, 0, 0, 1, 0, 1],
117
                        [1, 0, 1, 0, 0, 0, 0, 0, 0, 0],
118
                        [0, 0, 1, 1, 1, 0, 0, 1, 1, 0],
119
                        [1, 1, 1, 0, 0, 1, 0, 1, 1, 1],
120
                        [0, 0, 1, 0, 1, 1, 1, 0, 1, 1],
121
                        [0, 1, 0, 1, 0, 0, 1, 0, 1, 1],
122
                        [0, 1, 1, 0, 0, 0, 1, 1, 0, 0],
123
                        [0, 1, 1, 0, 1, 1, 1, 0, 0, 1],
124
                    ],
125
                    7,
126
                    6,
127
                ],
128
                "answer": 4,
129
            },
130
            {
131
                "input": [
132
                    [
133
                        [1, 0, 0, 0, 1, 0, 0, 1, 1, 0],
134
                        [0, 1, 0, 1, 0, 1, 1, 0, 0, 1],
135
                        [1, 1, 1, 1, 0, 1, 0, 0, 0, 1],
136
                        [0, 0, 1, 1, 0, 1, 0, 0, 0, 1],
137
                        [1, 1, 0, 1, 1, 0, 1, 0, 0, 1],
138
                        [0, 1, 1, 1, 0, 0, 1, 1, 1, 0],
139
                        [1, 1, 1, 0, 0, 0, 0, 0, 1, 1],
140
                        [0, 0, 0, 1, 0, 1, 0, 0, 1, 1],
141
                        [0, 0, 0, 1, 0, 1, 0, 1, 0, 1],
142
                        [1, 1, 0, 0, 0, 1, 0, 1, 1, 1],
143
                    ],
144
                    9,
145
                    8,
146
                ],
147
                "answer": 4,
148
            },
149
            {
150
                "input": [
151
                    [
152
                        [1, 1, 0, 1, 0, 0, 0, 1, 1, 0],
153
                        [1, 1, 1, 0, 0, 0, 1, 0, 1, 1],
154
                        [0, 1, 0, 0, 1, 0, 1, 0, 1, 0],
155
                        [0, 1, 0, 1, 0, 0, 0, 1, 1, 1],
156
                        [1, 0, 1, 1, 1, 1, 0, 1, 1, 0],
157
                        [1, 1, 1, 0, 0, 0, 0, 0, 1, 1],
158
                        [0, 1, 0, 0, 0, 0, 1, 0, 0, 0],
159
                        [1, 1, 0, 0, 1, 1, 0, 0, 0, 1],
160
                        [0, 1, 0, 1, 0, 0, 0, 1, 0, 0],
161
                        [1, 0, 1, 0, 0, 0, 1, 1, 1, 1],
162
                    ],
163
                    9,
164
                    7,
165
                ],
166
                "answer": 3,
167
            },
168
            {
169
                "input": [
170
                    [
171
                        [0, 1, 1, 1, 1, 0, 0, 0, 1, 0],
172
                        [1, 0, 0, 0, 1, 1, 0, 0, 0, 1],
173
                        [0, 0, 0, 1, 0, 1, 0, 1, 0, 0],
174
                        [1, 1, 0, 1, 1, 1, 1, 1, 1, 1],
175
                        [0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
176
                        [0, 0, 0, 1, 1, 0, 0, 0, 1, 1],
177
                        [0, 0, 0, 0, 0, 1, 1, 0, 1, 1],
178
                        [0, 0, 0, 0, 1, 1, 1, 0, 0, 0],
179
                        [0, 1, 1, 1, 0, 0, 1, 0, 1, 1],
180
                        [1, 0, 0, 0, 0, 0, 0, 1, 0, 0],
181
                    ],
182
                    7,
183
                    5,
184
                ],
185
                "answer": 5,
186
            },
187
            {
188
                "input": [
189
                    [
190
                        [0, 0, 0, 0, 0, 1, 0, 0, 1, 0],
191
                        [1, 1, 0, 1, 0, 1, 0, 0, 0, 0],
192
                        [0, 1, 1, 0, 0, 1, 1, 1, 1, 0],
193
                        [0, 1, 0, 1, 0, 0, 0, 1, 1, 1],
194
                        [0, 0, 1, 0, 1, 1, 1, 0, 1, 1],
195
                        [0, 1, 0, 1, 0, 0, 1, 1, 1, 0],
196
                        [0, 1, 1, 0, 0, 1, 0, 1, 0, 0],
197
                        [0, 1, 0, 1, 1, 1, 1, 1, 0, 1],
198
                        [0, 1, 1, 0, 1, 0, 0, 0, 1, 1],
199
                        [0, 1, 0, 0, 0, 1, 1, 1, 0, 0],
200
                    ],
201
                    7,
202
                    2,
203
                ],
204
                "answer": 6,
205
            },
206
            {
207
                "input": [
208
                    [
209
                        [1, 1, 1, 1, 0, 1, 1, 0, 0, 0],
210
                        [0, 1, 1, 1, 1, 0, 1, 1, 0, 0],
211
                        [0, 0, 0, 0, 1, 1, 0, 0, 1, 0],
212
                        [1, 1, 1, 1, 0, 1, 0, 0, 0, 0],
213
                        [0, 1, 0, 0, 1, 1, 0, 0, 1, 1],
214
                        [1, 0, 1, 0, 1, 0, 1, 0, 1, 0],
215
                        [1, 0, 0, 0, 1, 0, 1, 1, 1, 1],
216
                        [1, 1, 1, 0, 1, 1, 1, 0, 1, 0],
217
                        [0, 1, 0, 0, 0, 1, 0, 1, 1, 1],
218
                        [0, 0, 1, 1, 0, 0, 0, 1, 0, 0],
219
                    ],
220
                    7,
221
                    9,
222
                ],
223
                "answer": 5,
224
            },
225
            {
226
                "input": [
227
                    [
228
                        [1, 1, 1, 0, 1, 0, 0, 0, 0, 1],
229
                        [1, 1, 1, 1, 1, 1, 0, 0, 0, 0],
230
                        [0, 0, 1, 0, 0, 0, 0, 1, 1, 0],
231
                        [1, 1, 0, 0, 1, 0, 1, 1, 1, 1],
232
                        [0, 0, 0, 1, 0, 1, 0, 1, 1, 1],
233
                        [0, 1, 0, 0, 1, 0, 0, 1, 0, 0],
234
                        [0, 1, 1, 0, 0, 1, 1, 0, 0, 1],
235
                        [0, 1, 1, 0, 0, 0, 0, 1, 1, 0],
236
                        [0, 0, 1, 1, 0, 1, 1, 0, 1, 0],
237
                        [1, 0, 1, 0, 1, 1, 0, 0, 1, 0],
238
                    ],
239
                    2,
240
                    9,
241
                ],
242
                "answer": 3,
243
            },
244
            {
245
                "input": [
246
                    [
247
                        [0, 0, 1, 0, 1, 1, 0, 1, 1, 1],
248
                        [0, 0, 1, 0, 0, 1, 1, 1, 0, 1],
249
                        [0, 0, 1, 0, 0, 0, 1, 1, 0, 0],
250
                        [0, 0, 1, 0, 0, 0, 0, 0, 0, 1],
251
                        [0, 0, 1, 0, 1, 1, 0, 1, 0, 0],
252
                        [0, 1, 0, 1, 1, 1, 0, 0, 1, 0],
253
                        [1, 0, 0, 1, 1, 0, 0, 1, 0, 1],
254
                        [0, 1, 1, 0, 0, 1, 1, 0, 0, 0],
255
                        [0, 1, 0, 1, 0, 0, 1, 1, 0, 0],
256
                        [1, 1, 0, 1, 1, 1, 0, 1, 1, 1],
257
                    ],
258
                    8,
259
                    3,
260
                ],
261
                "answer": 3,
262
            },
263
            {
264
                "input": [
265
                    [
266
                        [0, 0, 0, 1, 1, 0, 0, 0, 0, 0],
267
                        [1, 1, 1, 0, 0, 0, 1, 1, 1, 0],
268
                        [1, 1, 0, 1, 0, 0, 0, 1, 0, 0],
269
                        [1, 0, 0, 0, 0, 1, 1, 0, 0, 0],
270
                        [1, 0, 0, 1, 1, 0, 1, 0, 0, 0],
271
                        [0, 1, 0, 1, 0, 0, 0, 1, 1, 1],
272
                        [1, 1, 1, 0, 0, 0, 0, 0, 0, 1],
273
                        [1, 1, 0, 1, 1, 0, 0, 1, 1, 0],
274
                        [0, 1, 0, 1, 0, 1, 0, 0, 0, 1],
275
                        [1, 1, 1, 0, 1, 1, 0, 0, 0, 0],
276
                    ],
277
                    5,
278
                    1,
279
                ],
280
                "answer": 4,
281
            },
282
            {
283
                "input": [
284
                    [
285
                        [0, 1, 0, 1, 0, 1, 0, 0, 1, 1],
286
                        [0, 1, 1, 0, 0, 0, 0, 1, 1, 1],
287
                        [0, 1, 0, 0, 0, 1, 1, 0, 0, 0],
288
                        [1, 0, 1, 1, 0, 1, 1, 1, 1, 1],
289
                        [0, 1, 0, 0, 1, 1, 0, 0, 1, 0],
290
                        [0, 1, 1, 1, 1, 0, 1, 0, 0, 0],
291
                        [1, 0, 1, 0, 0, 0, 1, 0, 0, 0],
292
                        [0, 0, 0, 1, 0, 0, 0, 0, 1, 0],
293
                        [0, 1, 0, 1, 0, 0, 1, 1, 1, 1],
294
                        [1, 0, 0, 0, 1, 0, 0, 1, 0, 0],
295
                    ],
296
                    0,
297
                    7,
298
                ],
299
                "answer": 3,
300
            },
301
        ],
302
    }
303
304
    def test_Basics(self):
305
        for i in self.TESTS['Basics']:
306
            assert count_neighbours(*i['input']) == i['answer']
307
308
    def test_Extra(self):
309
        for i in self.TESTS['Extra']:
310
            assert count_neighbours(*i['input']) == i['answer']
311
312
313
if __name__ == "__main__":  # pragma: no cover
314
    unittest.main()
315