-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmini_auto_grader.py
More file actions
executable file
·82 lines (70 loc) · 2.32 KB
/
mini_auto_grader.py
File metadata and controls
executable file
·82 lines (70 loc) · 2.32 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
import ID3, parse, random
def mini_grader():
data = [dict(a=1, b=0, Class=1), dict(a=1, b=1, Class=1)]
try:
tree = ID3.ID3(data, 0)
if tree != None:
ans = ID3.evaluate(tree, dict(a=1, b=0))
if ans != 1:
print("ID3 test 1 failed.")
else:
print("ID3 test 1 succeeded.")
else:
print("ID3 test 1 failed -- no tree returned")
except Exception:
print("ID3 test 1 failed runtime error")
data = [dict(a=1, b=0, Class=0), dict(a=1, b=1, Class=1)]
try:
tree = ID3.ID3(data, 0)
if tree != None:
ans = ID3.evaluate(tree, dict(a=1, b=0))
if ans != 0:
print("ID3 test 2 failed.")
else:
print("ID3 test 2 succeeded.")
else:
print("ID3 test 2 failed -- no tree returned")
except Exception:
print("ID3 test 2 failed runtime error")
data = [dict(a=1, b=0, Class=2), dict(a=1, b=1, Class=1),
dict(a=2, b=0, Class=2), dict(a=2, b=1, Class=3),
dict(a=3, b=0, Class=1), dict(a=3, b=1, Class=3)]
try:
tree = ID3.ID3(data, 0)
if tree != None:
ans = ID3.evaluate(tree, dict(a=1, b=0))
if ans != 2:
print("ID3 test 3-1 failed.")
else:
print("ID3 test 3-1 succeeded.")
ans = ID3.evaluate(tree, dict(a=1, b=1))
if ans != 1:
print("ID3 test 3-2 failed.")
else:
print("ID3 test 3-2 succeeded.")
else:
print("ID3 test 3 failed -- no tree returned")
except Exception:
print("ID3 test 3 failed runtime error")
data = [dict(a=1, b=0, c='?', Class=1), dict(a=1, b=3, c=2, Class=1),
dict(a=2, b='?', c=1, Class=2), dict(a=2, b=1, c=3, Class=2),
dict(a=3, b=0, c=1, Class=3), dict(a=3, b=2, c='?', Class=3)]
try:
tree = ID3.ID3(data, 0)
if tree != None:
ans = ID3.evaluate(tree, dict(a=1, b=1, c=1))
if ans != 1:
print("ID3 test 4-1 failed.")
else:
print("ID3 test 4-1 succeeded.")
ans = ID3.evaluate(tree, dict(a=2, b=0, c=0))
if ans != 2:
print("ID3 test 4-2 failed.")
else:
print("ID3 test 4-2 succeeded.")
else:
print("ID3 test 4 failed -- no tree returned")
except Exception:
print("ID3 test 4 failed runtime error")
if __name__ == "__main__":
mini_grader()