forked from benevolentprof/inf1340_2015_asst2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_exercise3.py
197 lines (149 loc) · 4.62 KB
/
test_exercise3.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
#!/usr/bin/env python
""" Assignment 2, Exercise 3, INF1340, Fall, 2015. DBMS
Test module for exercise3.py
"""
__author__ = 'Aaron Campbell, Sebastien Dagenais-Maniatopoulos & Susan Sim'
__email__ = "aaronl.campbell@mail.utoronto.ca, sebastien.maniatopoulos@mail.utoronto.ca & ses@drsusansim.org"
__copyright__ = "2015 Aaron Campbell & Sebastien Dagenais-Maniatopoulos & Susan Sim"
__license__ = "MIT License"
from exercise3 import schema_check, union, intersection, difference, MismatchedAttributesException
###########
# TABLES ##
###########
GRADUATES = [["Number", "Surname", "Age"],
[7274, "Robinson", 37],
[7432, "O'Malley", 39],
[9824, "Darkes", 38]]
MANAGERS = [["Number", "Surname", "Age"],
[9297, "O'Malley", 56],
[7432, "O'Malley", 39],
[9824, "Darkes", 38]]
# tables with mismatch headings in table1 and an extra column in table2
GRADS_WRONG = [["Number", "Surname", "Sex"],
[7274, "Robinson", "M"],
[7432, "O'Malley", "F"],
[9824, "Darkes", "N/A"]]
MNGRS_WRONG = [["Number", "Surname", "FirstName", "Sex"],
[9297, "O'Malley", "Martha", "F", ],
[7432, "O'Malley", "Clark" "M", ],
[9824, "Darkes", "Hortense", "F", ]]
#####################
# HELPER FUNCTIONS ##
#####################
def is_equal(t1, t2):
return t1.sort() == t2.sort()
###################
# TEST FUNCTIONS ##
###################
def test_schema_check():
"""
Test to determine whether an error is thrown if the columns do not match
"""
try:
schema_check(GRADUATES, MNGRS_WRONG)
except MismatchedAttributesException:
assert True
else:
assert False
try:
schema_check(GRADS_WRONG, MANAGERS)
except MismatchedAttributesException:
assert True
else:
assert False
def test_union():
"""
Test union operation.
"""
result = [["Number", "Surname", "Age"],
[7274, "Robinson", 37],
[9297, "O'Malley", 56],
[7432, "O'Malley", 39],
[9824, "Darkes", 38]]
assert is_equal(result, union(GRADUATES, MANAGERS))
# test for MismatchedAttributesException
try:
union(GRADS_WRONG, MANAGERS)
except MismatchedAttributesException:
assert True
else:
assert False
def test_intersection():
"""
Test intersection operation.
"""
result = [["Number", "Surname", "Age"],
[7432, "O'Malley", 39],
[9824, "Darkes", 38]]
assert is_equal(result, intersection(GRADUATES, MANAGERS))
# intersection mismatch
try:
intersection(GRADS_WRONG, MNGRS_WRONG)
except MismatchedAttributesException:
assert True
else:
assert False
try:
intersection(MANAGERS, GRADS_WRONG)
except MismatchedAttributesException:
assert True
else:
assert False
def test_difference():
"""
Test difference operation.
"""
result = [["Number", "Surname", "Age"],
[7274, "Robinson", 37]]
assert is_equal(result, difference(GRADUATES, MANAGERS))
# mismatched tables
try:
difference(GRADS_WRONG, MANAGERS)
except MismatchedAttributesException:
assert True
else:
assert False
try:
difference(MNGRS_WRONG, MANAGERS)
except MismatchedAttributesException:
assert True
else:
assert False
LIBRARY_1 = [["Title", "Author_Last_Name", "Holdings"],
["Hitcher's Guide to the Galaxy", "Adams", "Robarts"],
["Suite Venitienne", "Calle", "Robarts"],
["Practical Programming", "Gries, Campbell", "Robarts"],
["Illuminations", "Benjamin", "Pratt"]]
LIBRARY_2 = [["Title", "Author_Last_Name", "Holdings"],
["Hitcher's Guide to the Galaxy", "Adams", "Robarts"],
["Restaurant at the End of the Universe", "Adams", "Pratt"],
["Arcades Project", "Benjamin", "Robarts"],
["Practical Programming", "Gries, Campbell", "Robarts"]]
def my_test_union():
"""
Test union operation.
"""
result = [["Title", "Author_Last_Name", "Holdings"],
["Hitcher's Guide to the Galaxy", "Adams", "Robarts"],
["Suite Venitienne", "Calle", "Robarts"],
["Practical Programming", "Gries, Campbell", "Robarts"],
["Illuminations", "Benjamin", "Pratt"],
["Restaurant at the End of the Universe", "Adams", "Pratt"],
["Arcades Project", "Benjamin", "Robarts"]]
assert result == union(LIBRARY_1, LIBRARY_2)
def my_test_intersection():
"""
Test intersection operation.
"""
result = [["Title", "Author_Last_Name", "Holdings"],
["Hitcher's Guide to the Galaxy", "Adams", "Robarts"],
["Practical Programming", "Gries, Campbell", "Robarts"]]
assert result == intersection(LIBRARY_1, LIBRARY_2)
def my_test_difference():
"""
Test difference operation.
"""
result = [["Title", "Author_Last_Name", "Holdings"],
["Suite Venitienne", "Calle", "Robarts"],
["Illuminations", "Benjamin", "Pratt"]]
assert result == difference(LIBRARY_1, LIBRARY_2)