-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_a2.py
More file actions
299 lines (271 loc) · 7.52 KB
/
Copy pathtest_a2.py
File metadata and controls
299 lines (271 loc) · 7.52 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
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
"""
# Copyright William Song, 2018
# Distributed under the terms of the GNU General Public License.
#
# This file is a tester file for Assignment 2, CSCA48, Winter 2018
#
# This is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This file is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this file. If not, see <http://www.gnu.org/licenses/>.
"""
# Man, that makes this look official.
# Good luck!
# Note evaluate's formatting is:
# variables
# values
# formula
# output
from formula_game_functions import build_tree, draw_formula_tree, evaluate, play2win
test = ["Formulas"]
# You can comment these out to help you reduce the clutter while testing
test.append("build_tree")
test.append("draw_formula_tree")
test.append("evaluate")
test.append("play2win")
# Formulas from the assignment and piazza
# Valid formulas from the assignment sheet
a1 = "x"
a2 = "-y"
a3 = "(x*y)"
a4 = "((-x+y)*-(-y+x))"
a5 = "((x+y)*((y+z)*(-y+-z)))"
# Invalid formulas from the assignment sheet
a6 = "X"
a7 = "x*y"
a8 = "-(x)"
a9 = "(x+(y)*z)"
# Valid from Piazza
p1 = "(x+-y)"
p2 = "(((x*y)*z)*w)"
p3 = "--x"
p4 = "----------------x"
p5 = "(-x*(y+z))"
p6 = "((x+y)*(x+z))"
p7 = "((x+y)*((y+z)*(-y+-z)))"
p8 = "(---x*y)"
p9 = "-(x+y)"
# t(o_ot)
p10 = "(a+(((((c*v)*(t+u))+-((o+-z)+((p+(r*s))*-q)))+(d*e))*((f+-(y+z))+-((x+j)*((k+(l+w))+(m*-n))))))"
# Invalid formulas from piazza
f1 = "(x+y*z)"
f2 = "(x*y*z)"
f3 = "((x+y)*(x-y)*(x+z))"
f4 = "(x+(u*v*w*z)+y) "
f5 = "-x-y"
f6 = "(x+y*x+y)"
f7 = "x)"
f8 = "++++x"
f9 = "-(-a)"
f10 = "(x+y)*(x+z)"
f11 = "-(ab)"
f12 = "(a+(B*-c))"
f13 = "(x * c)"
f14 = "-+x"
f15 = "!a"
f16 = "(x+x(()"
f17 = "((x+y))"
f18 = ")x+y("
f19 = "(x+y))"
f20 = "((x*y)"
f21 = "((x+y)*((y!z)*(-y+-z)))"
f22 = ""
f23 = " "
f24 = "(a+*+*+*b)"
f25 = "(a+*)"
f26 = "(((((x*y)))))"
f27 = "(x*y) "
assignment_pass = [a1, a2, a3, a4, a5]
assignment_fail = [a6, a7, a8, a9]
piazza_pass = [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10]
piazza_fail = [f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11, f12, f13, f14, f15, f16, f17, f18, f19, f20, f21, f22, f23, f24, f25, f26, f27]
# build_tree
if "build_tree" in test:
print("=======================build_tree=======================")
print("========Failures========")
for formula in assignment_fail:
print(formula)
print(build_tree(formula))
print("\n")
for formula in piazza_fail:
print(formula)
print(build_tree(formula))
print("\n")
print("========Passes========")
for formula in assignment_pass:
print(formula)
print(build_tree(formula))
print("\n")
for formula in piazza_pass:
print(formula)
print(build_tree(formula))
print("\n")
# draw_formula_tree
if "draw_formula_tree" in test:
print("====================draw_formula_tree====================")
for formula in assignment_pass:
print(formula)
print(draw_formula_tree(build_tree(a1)))
print("\n")
for formula in piazza_pass:
print(formula)
print(draw_formula_tree(build_tree(a1)))
print("\n")
# evaluate
if "evaluate" in test:
print("\n\n\n\n\n\n\n\n")
print("==================evaluate==================")
values1 = ["1", "0"]
values2 = ["11", "10", "01", "00"]
values3 = ["111", "110", "101", "011", "100", "010", "001", "000"]
values4 = ["1111", "1110", "1101", "1011", "1100", "1010", "1001",
"1000", "0111", "0110", "0101", "0011", "0100", "0010", "0001", "0000"]
variables = "x"
for values in values1:
print(variables)
print(values)
print(a1)
print(evaluate(build_tree(a1), variables, values))
print("\n")
variables = "y"
for values in values1:
print(variables)
print(values)
print(a2)
print(evaluate(build_tree(a2), variables, values))
print("\n")
variables = "xy"
for values in values2:
print(variables)
print(values)
print(a3)
print(evaluate(build_tree(a3), variables, values))
print("\n")
variables = "xy"
for values in values2:
print(variables)
print(values)
print(a4)
print(evaluate(build_tree(a4), variables, values))
print("\n")
variables = "xyz"
for values in values3:
print(variables)
print(values)
print(a5)
print(evaluate(build_tree(a5), variables, values))
print("\n")
variables = "xy"
for values in values2:
print(variables)
print(values)
print(p1)
print(evaluate(build_tree(p1), variables, values))
print("\n")
variables = "wxyz"
for values in values4:
print(variables)
print(values)
print(p2)
print(evaluate(build_tree(p2), variables, values))
print("\n")
variables = "x"
for values in values1:
print(variables)
print(values)
print(p3)
print(evaluate(build_tree(p3), variables, values))
print("\n")
variables = "x"
for values in values1:
print(variables)
print(values)
print(p4)
print(evaluate(build_tree(p4), variables, values))
print("\n")
variables = "xyz"
for values in values3:
print(variables)
print(values)
print(p5)
print(evaluate(build_tree(p5), variables, values))
print("\n")
variables = "xyz"
for values in values3:
print(variables)
print(values)
print(p6)
print(evaluate(build_tree(p6), variables, values))
print("\n")
variables = "xyz"
for values in values3:
print(variables)
print(values)
print(p7)
print(evaluate(build_tree(p7), variables, values))
print("\n")
variables = "xy"
for values in values2:
print(variables)
print(values)
print(p8)
print(evaluate(build_tree(p8), variables, values))
print("\n")
variables = "xy"
for values in values2:
print(variables)
print(values)
print(p9)
print(evaluate(build_tree(p9), variables, values))
print("\n")
# play2win
if "play2win" in test:
print("\n\n\n\n\n\n\n\n")
print("==================play2win==================")
a1_tree = build_tree(a1)
print(a1)
print(play2win(a1_tree, "E", "x", ""))
print()
print(a1)
print(play2win(a1_tree, "A", "x", ""))
print()
a2_tree = build_tree(a2)
print(a2)
print(play2win(a2_tree, "E", "y", ""))
print()
print(a2)
print(play2win(a2_tree, "A", "y", ""))
print()
a3_tree = build_tree(a3)
print(a3)
print(play2win(a3_tree, "EE", "xy", ""))
print()
print(a3)
print(play2win(a3_tree, "EA", "xy", ""))
print()
print(a3)
print(play2win(a3_tree, "AE", "xy", ""))
print()
print(a3)
print(play2win(a3_tree, "AA", "xy", ""))
print()
print(a3)
print(play2win(a3_tree, "EE", "xy", "1"))
print()
print(a3)
print(play2win(a3_tree, "EA", "xy", "0"))
print()
print(a3)
print(play2win(a3_tree, "AE", "xy", "1"))
print()
print(a3)
print(play2win(a3_tree, "AA", "xy", "0"))
print()