-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtests_codility.py
53 lines (41 loc) · 1.53 KB
/
tests_codility.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import pytest
import codility
binary_gap = [(1041, 5),
(15, 0),
(32, 0),
(328, 2),
(51712, 2),
(561892, 3),
(66561, 9)
]
@pytest.mark.parametrize(['N', 'result'], binary_gap)
def test_binary_gap(N, result):
assert codility.binary_gap(N) == result
parity_degree = [(24, 3),
(48, 4),
(97, 0),
(1, 0),
(0, 0),
(2, 1)]
@pytest.mark.parametrize(['N', 'result'], parity_degree)
def test_parity_degree(N, result):
assert codility.parity_degree(N) == result
smallest_positive = [([1, 3, 6, 4, 1, 2], 5),
([1, 2, 3], 4),
([-1, 1, 5], 2),
([-1, -3], 1)]
@pytest.mark.parametrize(['A', 'result'], smallest_positive)
def test_smallest_positive(A, result):
assert codility.smallest_positive(A) == result
multiple_4 = [([0, 4, 8], 12),
([-6, -91, 1011, -100, 84, -22, 0, 1, 473], -16)]
@pytest.mark.parametrize(['A', 'result'], multiple_4)
def test_sum_multiple_4(A, result):
assert codility.sum_multiple_4(A) == result
flip_heads_or_tails = [([0, 1, 0, 1, 1], 1),
([1, 1, 0, 1, 1], 2),
([0, 1, 0], 0),
([0, 1, 1, 0], 2)]
@pytest.mark.parametrize(['A', 'result'], flip_heads_or_tails)
def test_flip_heads_or_tails(A, result):
assert codility.flip_heads_or_tails(A) == result