-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
242 lines (183 loc) · 8.41 KB
/
test.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
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# Do not modify this file (if you want to modify anyway, contact a mentor before, who will explain why do not modify)
import unittest
from model import data_manager
# Store module
from model.store import store
# Human Resources module
from model.hr import hr
# Tool manager module
from model.inventory import inventory
# Accounting module
from model.accounting import accounting
# Sales module
from model.sales import sales
# Customer Relationship Management (CRM) module
from model.crm import crm
def compare_lists(tester, expected_list, result_list):
if len(expected_list) == 0 and len(result_list) == 0:
return
if len(expected_list) != 0 and len(result_list) == 0:
tester.assertListEqual(result_list, expected_list)
for item in result_list:
tester.assertTrue(item in expected_list)
def get_subscribed_list():
return ["hv8@qsuotla508.com;Lieselotte Rainey",
"t1ytt@vpm5xkvn.com;Maude Toll",
"-cip@jlyzpvm.com;Fawn Lambrecht",
"38ds7@0733we.com;Phylis Farberanmt",
"net@bjewwj9.com;Genoveva Dingess",
"rnh5z@zss4-n3.com;Royce Stager",
"x0jp9xg4@2zh-j6v9ai6.com;Pierre Cotta",
"p7zgwk@jszadvjsr.com;Concetta Nussbaum",
"ixnqwxkgvlppx9@4qt-a5jtsj.com;Missy Stoney",
"ufvp64.ghw5@r2l3f1.com;Sadye Hession",
"u6vt7o4@n7a-0t.com;Kanesha Moshier",
"qq9.-2o1cj2bii@g2fdac.com;Caleb Paschal"]
def get_item_sold_between_dates():
return [["eH34Ju#&", "Astebreed", 25, 3, 10, 2016],
["bH34Ju#&", "Age of Wonders II: The Wizard's Throne", 20, 4, 1, 2016],
["vH34Ju#&", "AudioSurf", 23, 6, 2, 2016],
["kH35Ju#&", "Age of Empires", 11, 3, 7, 2016]]
def get_count_by_manufacturer_list():
return {"Ensemble Studios": 4,
"Edelweiss": 1,
"Triumph Studios": 5,
"Dylan Fitterer": 1,
"Frictional Games": 1,
"Related Designs, Ubisoft Blue Byte": 1,
"Remedy Entertainment": 1,
"Alexander Bruce": 1,
"Bohemia Interactive": 2,
"Valve Corporation": 1,
"Eugen Systems": 1,
"Innocent Grey": 2,
"Black Element Software": 1,
"Cyanide": 1,
"Jagex": 1,
"Hooksoft": 1,
"Reflexive Entertainment": 1,
"Advance Reality Interactive": 1,
"Gears for Breakfast": 1,
"Games Farm": 2}
def check_forbidden_functions(tester, file_name):
with open(file_name, "r") as file:
lines = file.read()
tester.assertEqual(lines.find("find("), -1)
tester.assertEqual(lines.find("sort("), -1)
tester.assertEqual(lines.find("sorted("), -1)
tester.assertEqual(lines.find("sum("), -1)
tester.assertEqual(lines.find("count("), -1)
tester.assertEqual(lines.find("index("), -1)
tester.assertEqual(lines.find("print("), -1)
tester.assertEqual(lines.find("input("), -1)
def check_forbidden_list_functions(tester, file_name):
with open(file_name, "r") as file:
lines = file.read()
tester.assertEqual(lines.find("find("), -1)
tester.assertEqual(lines.find("sort("), -1)
tester.assertEqual(lines.find("sorted("), -1)
tester.assertEqual(lines.find("sum("), -1)
tester.assertEqual(lines.find("count("), -1)
tester.assertEqual(lines.find("index("), -1)
class CommonTester(unittest.TestCase):
def test_forbidden_functions(self):
check_forbidden_functions(self, "model/common.py")
class terminal_viewTester(unittest.TestCase):
def test_forbidden_functions(self):
check_forbidden_list_functions(self, "view/terminal_view.py")
class AccountingTester(unittest.TestCase):
data_file = "model/accounting/items_test.csv"
def test_forbidden_functions(self):
check_forbidden_functions(self, "model/accounting/accounting.py")
def test_check_burnt_in_dates(self):
with open("model/accounting/accounting.py", "r") as file:
lines = file.read()
self.assertEqual(lines.find("2015"), -1)
self.assertEqual(lines.find("2016"), -1)
def test_which_year_max(self):
table = data_manager.get_table_from_file(self.data_file)
result = accounting.which_year_max(table)
self.assertEqual(result, 2015)
def test_avg_amount(self):
table = data_manager.get_table_from_file(self.data_file)
result = accounting.avg_amount(table, 2016)
self.assertEqual(result, 48.125)
class CRMTester(unittest.TestCase):
data_file = "model/crm/customers_test.csv"
def test_forbidden_functions(self):
check_forbidden_functions(self, "model/crm/crm.py")
def test_get_longest_name_id(self):
table = data_manager.get_table_from_file(self.data_file)
result = crm.get_longest_name_id(table)
self.assertEqual(result, "kH94Ju#&")
def test_get_subscribed_emails(self):
table = data_manager.get_table_from_file(self.data_file)
expected = get_subscribed_list()
result = crm.get_subscribed_emails(table)
compare_lists(self, expected, result)
class HRTester(unittest.TestCase):
data_file = "model/hr/persons_test.csv"
def test_forbidden_functions(self):
check_forbidden_functions(self, "model/hr/hr.py")
def test_check_using_datetime(self):
with open("model/hr/hr.py", "r") as file:
lines = file.read()
self.assertEqual(lines.find("datetime"), -1)
def test_get_oldest_person(self):
table = data_manager.get_table_from_file(self.data_file)
expected = ["Barbara Streisand", "Joey Tribbiani", "Evelin Smile"]
result = hr.get_oldest_person(table)
compare_lists(self, expected, result)
def test_get_persons_closest_to_average(self):
table = data_manager.get_table_from_file(self.data_file)
expected = ["Jimmy Hendrix"]
result = hr.get_persons_closest_to_average(table)
compare_lists(self, expected, result)
class SalesTester(unittest.TestCase):
data_file = "model/sales/sales_test.csv"
def test_forbidden_functions(self):
check_forbidden_functions(self, "model/sales/sales.py")
def test_check_using_datetime(self):
with open("model/sales/sales.py", "r") as file:
lines = file.read()
self.assertEqual(lines.find("datetime"), -1)
def test_get_lowest_price_item_id(self):
table = data_manager.get_table_from_file(self.data_file)
result = sales.get_lowest_price_item_id(table)
self.assertEqual(result, "kH35Ju#&")
def test_get_items_sold_between(self):
table = data_manager.get_table_from_file(self.data_file)
expected = get_item_sold_between_dates()
result = sales.get_items_sold_between(table, 2, 12, 2016, 7, 6, 2016)
compare_lists(self, expected, result)
class StoreTester(unittest.TestCase):
data_file = "model/store/games_test.csv"
def test_forbidden_functions(self):
check_forbidden_functions(self, "model/store/store.py")
def test_get_counts_by_manufacturers(self):
table = data_manager.get_table_from_file(self.data_file)
expected = get_count_by_manufacturer_list()
result = store.get_counts_by_manufacturers(table)
self.assertEqual(result, expected)
def test_get_average_by_manufacturer(self):
table = data_manager.get_table_from_file(self.data_file)
result = store.get_average_by_manufacturer(table, "Ensemble Studios")
self.assertEqual(result, 12.25)
class InventoryTester(unittest.TestCase):
data_file = "model/inventory/inventory_test.csv"
def test_forbidden_functions(self):
check_forbidden_functions(self, "model/inventory/inventory.py")
def test_get_available_items(self):
table = data_manager.get_table_from_file(self.data_file)
expected = [["kH34Ju#&", "PlayStation 4", "Sony", 2013, 4], ["jH34Ju#&", "Xbox One", "Microsoft", 2013, 4]]
result = inventory.get_available_items(table)
compare_lists(self, expected, result)
def test_get_average_durability_by_manufacturers(self):
table = data_manager.get_table_from_file(self.data_file)
expected = {"Sony": 3.5, "Microsoft": 4, "Nintendo": 3.25}
result = inventory.get_average_durability_by_manufacturers(table)
self.assertEqual(result, expected)
def main():
unittest.main()
if __name__ == '__main__':
main()