diff --git a/assignments/a2/a2.pdf b/assignments/a2/a2.pdf new file mode 100644 index 0000000..723c0ab Binary files /dev/null and b/assignments/a2/a2.pdf differ diff --git a/assignments/a2/a2_example_tests.py b/assignments/a2/a2_example_tests.py index d760090..ac3b0a4 100644 --- a/assignments/a2/a2_example_tests.py +++ b/assignments/a2/a2_example_tests.py @@ -241,41 +241,39 @@ def test_section_compatible() -> None: """ Test is_section_compatible with compatible sections """ - # TODO: Create a test + assert a2_courses.is_section_compatible(SCHEDULE_1, CON123_LEC0123) def test_section_not_compatible() -> None: """ Test is_section_compatible with incompatible sections """ - # TODO: Create a test + assert not a2_courses.is_section_compatible(SCHEDULE_1, TMP000_LEC0000) + assert not a2_courses.is_section_compatible(SCHEDULE_3, CON333_LEC2001) def test_course_compatible() -> None: """ Test is_course_compatible with compatible course """ - # TODO: Create a test + assert a2_courses.is_course_compatible(SCHEDULE_1, CON123) def test_course_not_compatible() -> None: """ Test is_course_compatible with incompatible course """ - # TODO: Create a test + assert not a2_courses.is_course_compatible(SCHEDULE_1, TMP000) + assert not a2_courses.is_course_compatible(SCHEDULE_1, CON333) def test_compatible_sections() -> None: """ Test compatible_sections with compatible sections """ - actual = a2_courses.compatible_sections(SCHEDULE_1, CON123) == {CON123_LEC0123} - expected = True - assert actual == expected + assert a2_courses.compatible_sections(SCHEDULE_1, CON123) == {CON123_LEC0123} -# TODO: Create more tests - ################################################################################################### # Part 4 ################################################################################################### @@ -306,7 +304,5 @@ def test_transform_meeting_time_data() -> None: assert actual == expected -# TODO: Create more tests - if __name__ == "__main__": pytest.main(['a2_example_tests.py']) diff --git a/assignments/a2/a2_part3.py b/assignments/a2/a2_part3.py index 8896fe9..5071e1c 100644 --- a/assignments/a2/a2_part3.py +++ b/assignments/a2/a2_part3.py @@ -45,7 +45,7 @@ def num_lecture_hours(section: tuple[str, str, tuple]) -> int: Hint: you can use ".hour" to access the hour attribute of a datetime.time value. """ - return sum([t[2].hour - t[1].hour for t in section[2]]) + return sum(t[2].hour - t[1].hour for t in section[2]) def sections_in_semester(schedule: dict[str, tuple[str, str, tuple]], semester: str) \ @@ -124,7 +124,7 @@ def sections_conflict(s1: tuple[str, str, tuple], s2: tuple[str, str, tuple]) \ # Cannot conflict if they aren't in overlapping term # Conflicts when at least one meeting times conflict return (term1 == term2 or term1 == 'Y' or term2 == 'Y') and \ - any([times_conflict(m1, m2) for m1 in times1 for m2 in times2]) + any(times_conflict(m1, m2) for m1 in times1 for m2 in times2) def is_valid(schedule: dict[str, tuple[str, str, tuple]]) -> bool: @@ -248,7 +248,7 @@ def is_section_compatible(schedule: dict[str, tuple[str, str, tuple]], - section matches the format for a section described by the assignment handout. - schedule matches the format for a schedule described by the assignment handout. """ - return all([not sections_conflict(section, s) for s in schedule.values()]) + return all(not sections_conflict(section, s) for s in schedule.values()) def is_course_compatible(schedule: dict[str, tuple[str, str, tuple]], @@ -264,7 +264,7 @@ def is_course_compatible(schedule: dict[str, tuple[str, str, tuple]], - schedule matches the format for a schedule described by the assignment handout. - course[0] not in schedule """ - return any([is_section_compatible(schedule, section) for section in course[2]]) + return any(is_section_compatible(schedule, section) for section in course[2]) def compatible_sections(schedule: dict[str, tuple[str, str, tuple]],