-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
87 lines (76 loc) · 2.34 KB
/
tests.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import pytest
from ex1_multiplication import multiply_positives
from ex2_function_updates import reverse_negatives
from ex3_palindrome import is_palindrome
from ex4_kmer_counting import unique_substrings, kmer_counts
@pytest.mark.parametrize(
"test_input, expected_output",
[
([10, 20], 200),
([10], 10),
([10, -20], 10),
([-10], 1),
([], 1),
],
)
def test_ex1(test_input, expected_output):
assert multiply_positives(test_input) == expected_output
@pytest.mark.parametrize(
"test_input, expected_bool, expected_list",
[
([10, 20], False, [10, 20]),
([], False, []),
([10, -20], True, [10, 20]),
([-0.5, 10, -20], True, [0.5, 10, 20]),
([-10], True, [10]),
([10], False, [10]),
],
)
def test_ex2(test_input, expected_bool, expected_list):
assert reverse_negatives(test_input) == expected_bool
assert test_input == expected_list
@pytest.mark.parametrize(
"test_input, expected",
[
("p", True),
("", True),
("madam", True),
("madama", False),
("able was I ere I saw elba", True),
("Able was I here I saw Elba", False),
(["a", "a", "a"], True),
(["a", "a", "b"], False),
(["a", 1, "b"], False),
(("a", 1, "a"), True),
],
)
def test_ex3(test_input, expected):
assert is_palindrome(test_input) == expected
@pytest.mark.parametrize(
"sequence, k, expected",
[
("ACG", 1, {"A", "C", "G"}),
("ACG", 3, {"ACG"}),
("ACGT", 3, {"ACG", "CGT"}),
("ACGT" * 3 + "TTATT" * 5, 3, {"GTT", "TAT", "ATT", "ACG", "TTT", "TAC", "GTA", "CGT", "TTA"}),
("ACG", 0, set()),
("ACG", 5, set()),
],
)
def test_ex4_unique_substrings(sequence, k, expected):
assert unique_substrings(sequence, k) == expected
@pytest.mark.parametrize(
"sequence, k, expected",
[
("ACG", 1, {"A": 1, "C": 1, "G": 1}),
("ACG", 3, {"ACG": 1}),
("ACGT", 3, {"ACG": 1, "CGT": 1}),
("ACGT" * 3 + "TTATT" * 5, 3, {'ACG': 3, 'CGT': 3, 'GTA': 2, 'TAC': 2, 'GTT': 1, 'TTT': 9, 'TTA': 5, 'TAT': 5, 'ATT': 5}),
("ACG", 0, {}),
("ACG", 5, {}),
(" ", 1, {" ": 3}),
(" ", 2, {" ": 2}),
],
)
def test_ex4_kmer_counts(sequence, k, expected):
assert kmer_counts(sequence, k) == expected