def test_calculate_average_of_classroom_with_invalid_teacher(self): classroom = Classroom(Teacher('Selena Francis')) classroom.add_student(julia) error_message = 'This teacher can not correct for classroom of Selena Francis with 1 students' with self.assertRaises(BaseException) as context: self.teacher.calculate_average_of_classroom(classroom) self.assertTrue(error_message in str(context.exception))
def run(): with open(location_file, "r") as file: location = file.readline() file.close() ers = Errors() settings = Settings(location, ers) if write_errors(ers): return classroom = Classroom(settings.created_students, settings) print_testing_report(settings) write_results(classroom) subprocess.call(['open', '-a', 'TextEdit', results_file])
def test_calculate_average_of_classroom(self): classroom = Classroom(self.teacher) classroom.add_student(jude) classroom.add_student(carlee) quiz_two = Quiz() for question in questions: quiz_two.add_question(question) for student in [jude, julia, carlee, earl]: assignment = self.teacher.assign(self.quiz, student) assignment.add_answer(question_one, 'Judo') assignment.add_answer(question_two, 80) assignment.add_answer(question_three, 'Renault') assignment.add_answer(question_four, 'Tennis') assignment.add_answer(question_five, 1986) assignment = self.teacher.assign(quiz_two, student) assignment.add_answer(question_one, 'Judo') assignment.add_answer(question_two, 80) assignment.add_answer(question_three, 'Renault') generator = self.teacher.calculate_average_of_classroom(classroom) self.assertCountEqual(list(generator), [{ 'Carlee Holloway': 8.0 }, { 'Jude Arroyo': 8.0 }])
} ''')) professor1 = Professor( json_loads(''' { "first_name": "Robert", "middle_name": "", "last_name": "O'Connor", "departments": ["MA"] } ''')) classroom0 = Classroom( json_loads(''' { "room_code": "MB100", "room_type": "cr" } ''')) classroom1 = Classroom( json_loads(''' { "room_code": "MB110", "room_type": "cr" } ''')) classroom2 = Classroom( json_loads(''' { "room_code": "MB120", "room_type": "cr"
def test_get_first_available(): course0 = Course( json_loads(''' { "name": "Math Lab", "course_code": "MA-100", "credit_count": 1, "standard_minutes_per_week": 50, "section_count": 1, "room_type": "cr", "lab": null } ''')) course1 = Course( json_loads(''' { "name": "Research Methods", "course_code": "IN-200", "credit_count": 3, "standard_minutes_per_week": 150, "section_count": 2, "room_type": "cr", "lab": null } ''')) course2 = Course( json_loads(''' { "name": "College Algebra", "course_code": "MA-101", "credit_count": 3, "standard_minutes_per_week": 150, "section_count": 3, "room_type": "cr", "lab": null } ''')) course3 = Course( json_loads(''' { "name": "Calculus 1", "course_code": "MA-104", "credit_count": 4, "standard_minutes_per_week": 200, "section_count": 2, "room_type": "cr", "lab": null } ''')) professor = Professor( json_loads(''' { "first_name": "Joanne", "middle_name": "Q.", "last_name": "Smith", "departments": ["MA", "IN"] } ''')) classroom = Classroom( json_loads(''' { "room_code": "MB100", "room_type": "cr" } ''')) bookings = [] no_restrictions = [] found_days, found_time_range, _ = classroom.slots.get_first_available( 50, bookings, no_restrictions, preferred_days_per_week=1) assert found_days == DayOfWeek.list_from_string("M") assert found_time_range == TimeRange(start=time(hour=7), end=time(hour=7, minute=50)) found_days, found_time_range, _ = classroom.slots.get_first_available( 150, bookings, no_restrictions, preferred_days_per_week=2) assert found_days == DayOfWeek.list_from_string("TR") assert found_time_range == TimeRange(start=time(hour=7), end=time(hour=8, minute=15)) found_days, found_time_range, _ = classroom.slots.get_first_available( 150, bookings, no_restrictions, preferred_days_per_week=3) assert found_days == DayOfWeek.list_from_string("MWF") assert found_time_range == TimeRange(start=time(hour=7), end=time(hour=7, minute=50)) bookings.append( Booking(course0, professor, (DayOfWeek.list_from_string("M"), TimeRange.normalize(7, 0, 0, 50), classroom)).finalize()) found_days, found_time_range, _ = classroom.slots.get_first_available( 50, bookings, no_restrictions, preferred_days_per_week=1) assert found_days == DayOfWeek.list_from_string("M") assert found_time_range == TimeRange(start=time(hour=8), end=time(hour=8, minute=50)) found_days, found_time_range, _ = classroom.slots.get_first_available( 150, bookings, no_restrictions, preferred_days_per_week=2) assert found_days == DayOfWeek.list_from_string("TR") assert found_time_range == TimeRange(start=time(hour=7), end=time(hour=8, minute=15)) found_days, found_time_range, _ = classroom.slots.get_first_available( 150, bookings, no_restrictions, preferred_days_per_week=3) assert found_days == DayOfWeek.list_from_string("MWF") assert found_time_range == TimeRange(start=time(hour=8), end=time(hour=8, minute=50)) bookings.append( Booking(course1, professor, (DayOfWeek.list_from_string("F"), TimeRange.normalize(8, 0, 2, 30), classroom)).finalize()) found_days, found_time_range, _ = classroom.slots.get_first_available( 50, bookings, no_restrictions, preferred_days_per_week=1) assert found_days == DayOfWeek.list_from_string("M") assert found_time_range == TimeRange(start=time(hour=8), end=time(hour=8, minute=50)) found_days, found_time_range, _ = classroom.slots.get_first_available( 150, bookings, no_restrictions, preferred_days_per_week=2) assert found_days == DayOfWeek.list_from_string("TR") assert found_time_range == TimeRange(start=time(hour=7), end=time(hour=8, minute=15)) found_days, found_time_range, _ = classroom.slots.get_first_available( 150, bookings, no_restrictions, preferred_days_per_week=3) assert found_days == DayOfWeek.list_from_string("MWF") assert found_time_range == TimeRange(start=time(hour=10, minute=40), end=time(hour=11, minute=30)) bookings.append( Booking(course1, professor, (DayOfWeek.list_from_string("T"), TimeRange.normalize(7, 0, 2, 30), classroom)).finalize()) found_days, found_time_range, _ = classroom.slots.get_first_available( 50, bookings, no_restrictions, preferred_days_per_week=1) assert found_days == DayOfWeek.list_from_string("M") assert found_time_range == TimeRange(start=time(hour=8), end=time(hour=8, minute=50)) found_days, found_time_range, _ = classroom.slots.get_first_available( 150, bookings, no_restrictions, preferred_days_per_week=2) assert found_days == DayOfWeek.list_from_string("TR") assert found_time_range == TimeRange(start=time(hour=9, minute=40), end=time(hour=10, minute=55)) found_days, found_time_range, _ = classroom.slots.get_first_available( 150, bookings, no_restrictions, preferred_days_per_week=3) assert found_days == DayOfWeek.list_from_string("MWF") assert found_time_range == TimeRange(start=time(hour=10, minute=40), end=time(hour=11, minute=30)) bookings.append( Booking(course3, professor, (DayOfWeek.list_from_string("M"), TimeRange.normalize(8, 0, 0, 150), classroom), (DayOfWeek.list_from_string("F"), TimeRange.normalize(10, 40, 0, 50), classroom)).finalize()) found_days, found_time_range, _ = classroom.slots.get_first_available( 50, bookings, no_restrictions, preferred_days_per_week=1) assert found_days == DayOfWeek.list_from_string("M") assert found_time_range == TimeRange(start=time(hour=10, minute=40), end=time(hour=11, minute=30)) found_days, found_time_range, _ = classroom.slots.get_first_available( 150, bookings, no_restrictions, preferred_days_per_week=2) assert found_days == DayOfWeek.list_from_string("TR") assert found_time_range == TimeRange(start=time(hour=9, minute=40), end=time(hour=10, minute=55)) found_days, found_time_range, _ = classroom.slots.get_first_available( 150, bookings, no_restrictions, preferred_days_per_week=3) assert found_days == DayOfWeek.list_from_string("MWF") assert found_time_range == TimeRange(start=time(hour=11, minute=40), end=time(hour=12, minute=30)) bookings.append( Booking(course3, professor, (DayOfWeek.list_from_string("TR"), TimeRange.normalize(9, 40, 1, 40), classroom)).finalize()) found_days, found_time_range, _ = classroom.slots.get_first_available( 50, bookings, no_restrictions, preferred_days_per_week=1) assert found_days == DayOfWeek.list_from_string("M") assert found_time_range == TimeRange(start=time(hour=10, minute=40), end=time(hour=11, minute=30)) found_days, found_time_range, _ = classroom.slots.get_first_available( 150, bookings, no_restrictions, preferred_days_per_week=2) assert found_days == DayOfWeek.list_from_string("TR") assert found_time_range == TimeRange(start=time(hour=11, minute=30), end=time(hour=12, minute=45)) found_days, found_time_range, _ = classroom.slots.get_first_available( 150, bookings, no_restrictions, preferred_days_per_week=3) assert found_days == DayOfWeek.list_from_string("MWF") assert found_time_range == TimeRange(start=time(hour=11, minute=40), end=time(hour=12, minute=30)) bookings.append( Booking(course2, professor, (DayOfWeek.list_from_string("MWF"), TimeRange.normalize(11, 40, 0, 50), classroom)).finalize()) found_days, found_time_range, _ = classroom.slots.get_first_available( 50, bookings, no_restrictions, preferred_days_per_week=1) assert found_days == DayOfWeek.list_from_string("M") assert found_time_range == TimeRange(start=time(hour=10, minute=40), end=time(hour=11, minute=30)) found_days, found_time_range, _ = classroom.slots.get_first_available( 150, bookings, no_restrictions, preferred_days_per_week=2) assert found_days == DayOfWeek.list_from_string("TR") assert found_time_range == TimeRange(start=time(hour=11, minute=30), end=time(hour=12, minute=45)) found_days, found_time_range, _ = classroom.slots.get_first_available( 150, bookings, no_restrictions, preferred_days_per_week=3) assert found_days == DayOfWeek.list_from_string("MWF") assert found_time_range == TimeRange(start=time(hour=12, minute=40), end=time(hour=13, minute=30)) bookings.append( Booking(course2, professor, (DayOfWeek.list_from_string("M"), TimeRange.normalize(10, 40, 0, 50), classroom), (DayOfWeek.list_from_string("TR"), TimeRange.normalize(11, 30, 0, 50), classroom)).finalize()) found_days, found_time_range, _ = classroom.slots.get_first_available( 50, bookings, no_restrictions, preferred_days_per_week=1) assert found_days == DayOfWeek.list_from_string("M") assert found_time_range == TimeRange(start=time(hour=12, minute=40), end=time(hour=13, minute=30)) found_days, found_time_range, _ = classroom.slots.get_first_available( 150, bookings, no_restrictions, preferred_days_per_week=2) assert found_days == DayOfWeek.list_from_string("TR") assert found_time_range == TimeRange(start=time(hour=12, minute=30), end=time(hour=13, minute=45)) found_days, found_time_range, _ = classroom.slots.get_first_available( 150, bookings, no_restrictions, preferred_days_per_week=3) assert found_days == DayOfWeek.list_from_string("MWF") assert found_time_range == TimeRange(start=time(hour=12, minute=40), end=time(hour=13, minute=30)) bookings.append( Booking(course2, professor, (DayOfWeek.list_from_string("MWF"), TimeRange.normalize(12, 40, 0, 50), classroom)).finalize()) found_days, found_time_range, _ = classroom.slots.get_first_available( 50, bookings, no_restrictions, preferred_days_per_week=1) assert found_days == DayOfWeek.list_from_string("M") assert found_time_range == TimeRange(start=time(hour=13, minute=40), end=time(hour=14, minute=30)) found_days, found_time_range, _ = classroom.slots.get_first_available( 150, bookings, no_restrictions, preferred_days_per_week=2) assert found_days == DayOfWeek.list_from_string("TR") assert found_time_range == TimeRange(start=time(hour=12, minute=30), end=time(hour=13, minute=45)) found_days, found_time_range, _ = classroom.slots.get_first_available( 150, bookings, no_restrictions, preferred_days_per_week=3) assert found_days == DayOfWeek.list_from_string("MWF") assert found_time_range == TimeRange(start=time(hour=13, minute=40), end=time(hour=14, minute=30))
def create_classroom(self, class_name, course_obj): class_obj = Classroom(class_name, course_obj) self.sch_classroom[class_name] = course_obj
def create_classroom(self,claroom_name,course_obj): sch_classroom_obj = Classroom(claroom_name,course_obj) self.sch_classroom[claroom_name] = sch_classroom_obj
def create_classroom(self, classroom_name, course_obj): # 调用 src.Classroom 生成班级对象 classroom_obj = Classroom(classroom_name, course_obj) # 班级对象存入字典 self.sch_classroom[classroom_name] = classroom_obj print(self.sch_classroom)
def modify_classroom(self, class_name, course_obj): #1.添加班级对象 class_obj = Classroom(class_name, course_obj) #2.修改字典中班级信息 self.sch_classroom[class_name] = class_obj
def create_classroom(self, class_name, course_obj): #1.创建班级对象,赋值变量 class_obj = Classroom(class_name, course_obj) #2.根据班级名称为key,班级对象为value来建立对应关系,添加到字典 self.sch_classroom[class_name] = class_obj