Exemplo n.º 1
0
class TestStudent(unittest.TestCase):
    def setUp(self):
        self.name = 'Elvis Rodriguez'
        self.id = 0
        self.valid_class = ('MWF', 1300, 1530)
        self.invalid_class = ('MW', 1400, 1600)
        self._student = Student(self.name, self.id)

    def test_get_name(self):
        self.assertEqual(self.name, self._student.name)

    def test_get_id(self):
        self.assertEqual(self.id, self._student.id)

    def test_valid_time_interval(self):
        self.assertTrue(self._student._valid_time_interval(1200, 1400))
        self.assertFalse(self._student._valid_time_interval(1400, 1200))
        self.assertFalse(self._student._valid_time_interval(1200, 1200))

    def test_add_valid_class(self):
        self.assertTrue(self._student.add_class(*self.valid_class))

    def test_add_invalid_class(self):
        self._student.add_class(*self.valid_class)
        self.assertFalse(self._student.add_class(*self.invalid_class))
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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
Exemplo n.º 4
0
 def test_student_answer_quiz(self):
     """Test that a student can answer a quiz"""
     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')
     assert (student.submit_answer('math', 'quiz1', '1 + 1?', '1')
             and student.submit_answer('math', 'quiz1', 'name?',
                                       ['my name', 'your name'])
             and student.quizzes['math_quiz1']['response'] == {
                 '1 + 1?': '1',
                 'name?': ['my name', 'your name']
             })
Exemplo n.º 5
0
 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')
Exemplo n.º 6
0
 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'))
Exemplo n.º 7
0
 def test_student_in_class(self):
     """Test that a student can exists in a class"""
     student = Student()
     student.add_class('math')
     assert student.has_class('math')
Exemplo n.º 8
0
 def test_student_in_classes(self):
     """Test that a student can have multiple classes"""
     student = Student()
     student.add_class('math')
     student.add_class('science')
     assert student.has_class('math') and student.has_class('science')