forked from canbula/PythonProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sequences.py
More file actions
118 lines (106 loc) · 3.66 KB
/
Copy pathtest_sequences.py
File metadata and controls
118 lines (106 loc) · 3.66 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import os
files = [f for f in os.listdir(os.path.dirname(__file__)) if f.startswith("sequences")]
for f in files:
exec("import " + f[:-3] + " as " + f[:-3])
print(f"The module {f[:-3]} has been imported.")
def test_names():
for f in files:
assert "remove_duplicates" in dir(eval(f[:-3])), (
"remove_duplicates is not defined in " + f[:-3]
)
assert "list_counts" in dir(eval(f[:-3])), (
"list_counts is not defined in " + f[:-3]
)
assert "reverse_dict" in dir(eval(f[:-3])), (
"reverse_dict is not defined in " + f[:-3]
)
def test_types():
for f in files:
assert callable(eval(f[:-3]).remove_duplicates), (
"remove_duplicates is not callable in " + f[:-3]
)
assert callable(eval(f[:-3]).list_counts), (
"list_counts is not callable in " + f[:-3]
)
assert callable(eval(f[:-3]).reverse_dict), (
"reverse_dict is not callable in " + f[:-3]
)
assert isinstance(eval(f[:-3]).remove_duplicates([1, 2, 3, 4, 5, 6]), list), (
"remove_duplicates is not returning a list in " + f[:-3]
)
assert isinstance(eval(f[:-3]).list_counts([1, 2, 3, 4, 5, 6]), dict), (
"list_counts is not returning a dict in " + f[:-3]
)
assert isinstance(eval(f[:-3]).reverse_dict({1: 1, 2: 2, 3: 3}), dict), (
"reverse_dict is not returning a dict in " + f[:-3]
)
def test_remove_duplicates():
for f in files:
assert eval(f[:-3]).remove_duplicates([1, 2, 3, 3, 4, 5, 5, 5, 6]) == [
1,
2,
3,
4,
5,
6,
], (
"remove_duplicates is not working in " + f[:-3]
)
assert eval(f[:-3]).remove_duplicates([1, 2, 3, 4, 5, 6]) == [
1,
2,
3,
4,
5,
6,
], (
"remove_duplicates is not working in " + f[:-3]
)
assert eval(f[:-3]).remove_duplicates([1, 1, 1, 1, 1, 1]) == [1], (
"remove_duplicates is not working in " + f[:-3]
)
assert eval(f[:-3]).remove_duplicates([]) == [], (
"remove_duplicates is not working in " + f[:-3]
)
def test_list_counts():
for f in files:
assert eval(f[:-3]).list_counts([1, 2, 3, 3, 4, 5, 5, 5, 6]) == {
1: 1,
2: 1,
3: 2,
4: 1,
5: 3,
6: 1,
}, (
"list_counts is not working in " + f[:-3]
)
assert eval(f[:-3]).list_counts([1, 2, 3, 4, 5, 6]) == {
1: 1,
2: 1,
3: 1,
4: 1,
5: 1,
6: 1,
}, (
"list_counts is not working in " + f[:-3]
)
assert eval(f[:-3]).list_counts([1, 1, 1, 1, 1, 1]) == {1: 6}, (
"list_counts is not working in " + f[:-3]
)
assert eval(f[:-3]).list_counts([]) == {}, (
"list_counts is not working in " + f[:-3]
)
def test_reverse_dict():
for f in files:
assert eval(f[:-3]).reverse_dict({1: 1, 2: 2, 3: 3}) == {1: 1, 2: 2, 3: 3}, (
"reverse_dict is not working in " + f[:-3]
)
assert eval(f[:-3]).reverse_dict({1: 2, 2: 3, 3: 4}) == {2: 1, 3: 2, 4: 3}, (
"reverse_dict is not working in " + f[:-3]
)
assert eval(f[:-3]).reverse_dict({1: 1, 2: 1, 3: 1}) == {1: 3}, (
"reverse_dict is not working in " + f[:-3]
)
assert eval(f[:-3]).reverse_dict({}) == {}, (
"reverse_dict is not working in " + f[:-3]
)