コード例 #1
0
def add_grade_to_student(student: Student, new_grade: int) -> None:
    try:
        student.add_final_grade(new_grade)
    except ValueError as e:
        print(e)
    else:
        print("\nGrade successfully added!\n")
コード例 #2
0
def generate_students(number_of_students=None):
    if number_of_students is None:
        number_of_students = random.randint(1, School.MAX_STUDENTS_NUMBER)

    students = []
    for student_number in range(number_of_students):
        first_name, last_name = generate_random_name()
        student = Student(first_name, last_name)
        students.append(student)
        subjects = ["Matematyka", "Fizyka", "Biologia", "Chemia", "Historia"]
        for subject in subjects:
            final_grade = random.randint(MIN_RANDOM_GRADE, MAX_RANDOM_GRADE)
            student.add_final_grade(final_grade, subject)
    return students
 def test_add_final_grade(self):
     student = Student("Test_First", "Test_Last", "A12345678", False, [])
     student.add_final_grade(10.0)
     self.assertEqual([10.0], student.get_final_grades())
 def test_add_final_grade_out_of_range_high(self):
     student = Student("Test_First", "Test_Last", "A12345678", False, [])
     with self.assertRaises(ValueError):
         student.add_final_grade(100.01)
 def test_add_final_grade_not_a_number(self):
     student = Student("Test_First", "Test_Last", "A12345678", False, [])
     with self.assertRaises(ValueError):
         student.add_final_grade('not a number')
コード例 #6
0
 def test_add_final_grade_successful(self):
     mock_student = Student("Jenny", "Kramer", "A42154852", True, 89, 76)
     mock_student.add_final_grade(85)
     self.assertEqual(repr(mock_student).split()[4:7], ["89", "76", "85"])
コード例 #7
0
 def test_add_final_grade_with_negative_num(self):
     mock_student = Student("Jenny", "Kramer", "A42154852", True, 89, 76)
     with self.assertRaises(ValueError):
         mock_student.add_final_grade(-20)
コード例 #8
0
 def test_add_final_grade_with_num_greater_than_100(self):
     mock_student = Student("Jenny", "Kramer", "A42154852", True, 89, 76)
     with self.assertRaises(ValueError):
         mock_student.add_final_grade(150)