-
Notifications
You must be signed in to change notification settings - Fork 0
/
teacher_test.py
181 lines (167 loc) · 5.98 KB
/
teacher_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
import pytest
from teacher import Teacher
from student import Student
class TestTeacher:
"""Class that contains teacher tests"""
def test_teacher_teach_class(self):
"""Test that a teacher can teach a class"""
teacher = Teacher()
teacher.add_class('math')
assert teacher.has_class('math')
def test_teacher_teach_classes(self):
"""Test that a teacher can teach multiple classes"""
teacher = Teacher()
teacher.add_class('math')
teacher.add_class('science')
assert teacher.has_class('math') and teacher.has_class('science')
def test_student_in_teacher_class(self):
"""Test if a student is part of a teacher's class"""
teacher = Teacher()
teacher.add_class('math')
student = Student()
student.add_class('math')
assert teacher.teaches(student)
def test_student_not_in_teacher_class(self):
"""Test if a student is not part of a teacher's class"""
teacher = Teacher()
teacher.add_class('math')
student = Student()
student.add_class('science')
assert not teacher.teaches(student)
def test_teacher_create_quiz(self):
"""Tests if a teacher can create a quiz"""
teacher = Teacher()
teacher.add_class('math')
questions = {
'1 + 1?': {
'1': False,
'2': True,
'3': False
},
'name?': {
'my name': True,
'your name': True,
'no name': False
}
}
teacher.create_quiz('math', 'quiz1', questions)
assert len(teacher.get_quizzes()) == 1
def test_not_teacher_create_quiz(self):
"""Tests if a teacher cant create a quiz without right answers"""
teacher = Teacher()
teacher.add_class('math')
questions = {'1 + 1?': {'1': False, '2': False, '3': False}}
assert not teacher.create_quiz('math', 'quiz1', questions)
def test_teacher_create_quizzes(self):
"""Tests if a teacher can create multiple quizzes"""
teacher = Teacher()
teacher.add_class('math')
teacher.add_class('science')
questions = {
'1 + 1?': {
'1': False,
'2': True,
'3': False
},
'name?': {
'my name': True,
'your name': True,
'no name': False
}
}
teacher.create_quiz('math', 'quiz1', questions)
questions = {'1 + 1?': {'1': False, '2': True, '3': False}}
teacher.create_quiz('science', 'quiz1', questions)
assert len(teacher.get_quizzes()) == 2
def test_teacher_assign_quiz(self):
"""Tests if a teacher can assign a quiz to a student"""
teacher = Teacher()
questions = {
'1 + 1?': {
'1': False,
'2': True,
'3': False
},
'name?': {
'my name': True,
'your name': True,
'no name': False
}
}
teacher.add_class('math')
teacher.create_quiz('math', 'quiz1', questions)
student = Student()
student.add_class('math')
assert teacher.assign_quiz(student, 'math', 'quiz1')
def test_not_teacher_assign_quiz(self):
"""Tests if a teacher can't assign a uuiz to a student that is not in his class"""
teacher = Teacher()
questions = {
'1 + 1?': {
'1': False,
'2': True,
'3': False
},
'name?': {
'my name': True,
'your name': True,
'no name': False
}
}
teacher.add_class('math')
teacher.create_quiz('math', 'quiz1', questions)
student = Student()
assert not teacher.assign_quiz(student, 'math', 'quiz1')
def test_teacher_grade_quiz(self):
"""Tests if a teacher quiz can be graded"""
teacher = Teacher()
questions = {
'1 + 1?': {
'1': False,
'2': True,
'3': False
},
'name?': {
'my name': True,
'your name': True,
'no name': False
}
}
teacher.add_class('math')
teacher.create_quiz('math', 'quiz1', questions)
student = Student()
student.add_class('math')
teacher.assign_quiz(student, 'math', 'quiz1')
student.submit_answer('math', 'quiz1', '1 + 1?', '1')
student.submit_answer('math', 'quiz1', 'name?', ['my name', 'your name'])
assert teacher.grade(student, student.get_quiz('math', 'quiz1'))
def test_teacher_compute_total(self):
"""Tests if a teacher can compute the total for a student"""
teacher = Teacher()
questions = {
'1 + 1?': {
'1': False,
'2': True,
'3': False
},
'name?': {
'my name': True,
'your name': True,
'no name': False
}
}
teacher.add_class('math')
teacher.add_class('science')
teacher.create_quiz('math', 'quiz1', questions)
teacher.create_quiz('science', 'quiz1', questions)
student = Student('Sam')
student.add_class('math')
student.add_class('science')
teacher.assign_quiz(student, 'math', 'quiz1')
student.submit_answer('math', 'quiz1', '1 + 1?', '1')
student.submit_answer('math', 'quiz1', 'name?', ['my name', 'your name'])
teacher.assign_quiz(student, 'science', 'quiz1')
student.submit_answer('science', 'quiz1', '1 + 1?', '1')
student.submit_answer('science', 'quiz1', 'name?', ['my name', 'your name'])
teacher.grade(student, student.get_quiz('math', 'quiz1'))
assert teacher.total(student.get_name(), 'math') == 50