def test_impossible_goal(self): # the scheduler should return an empty conjunction if conditions of the goal cannot be satisfied in four years # there are 100 total ECON and EDUC courses, so it is impossible to take all in 4 years all_econ_educ = [(key.program, key.designation) for key in self.course_dict if (key.program == 'ECON' or key.program == 'EDUC')] plan = course_scheduler(self.course_dict, all_econ_educ, []) self.assertEqual(plan, ())
def test_open_elective(self): # testing the open elective issue plan = course_scheduler(self.course_dict, [('CS', 'openelectives')], []) unique_courses = set() for course in plan: unique_courses.add(course[0].name) self.assertEqual(len(unique_courses), len(plan))
def test_initial_state(self): plan = course_scheduler(self.course_dict, [('CS', '1101'), ('SPAN', '1102'), ('SPAN', '3325')], [('SPAN', '1101')]) # the prereq for SPAN1102 is already satisfied so neither of its prereqs should be in the plan for course in plan: self.assertNotEqual(course[0], ('SPAN', '1101')) self.assertNotEqual(course[0], ('SPAN', '1100'))
def test_one_class_goal(self): # sum of credits must not be less than 12 per term plan = course_scheduler(self.course_dict, [('CS', '3250')], []) split_plan = split_by_term(plan) # ensure proper number of credits each semester for year in split_plan: for term in split_plan[year]: self.assertTrue((12 <= split_plan[year][term]['credits'] <= 18) or (split_plan[year][term]['credits'] == 0))
def test_proper_terms(self): # ensuring the correct years and terms are included # this goal should result in a 5-semester plan plan = course_scheduler(self.course_dict, [('MATH', '4110')], []) split_plan = split_by_term(plan) years = list(split_plan.keys()) self.assertNotEqual(split_plan['Frosh']['Fall']['courses'], []) self.assertNotEqual(split_plan['Frosh']['Spring']['courses'], []) self.assertNotEqual(split_plan['Soph']['Fall']['courses'], []) self.assertNotEqual(split_plan['Soph']['Spring']['courses'], []) self.assertNotEqual(split_plan['Junior']['Fall']['courses'], []) self.assertEqual(split_plan['Junior']['Spring']['courses'], []) self.assertEqual(split_plan['Senior']['Fall']['courses'], []) self.assertEqual(split_plan['Senior']['Spring']['courses'], [])
def test_logistics(self): # ensure that all scheduled courses are actual courses (ie. are not higher level requirements or empty) # and are offered during the semester they are scheduled plan = course_scheduler(self.course_dict, [('CS', 'major')], []) split_plan = split_by_term(plan) for year in split_plan: for term in split_plan[year]: for course in split_plan[year][term]['courses']: terms = self.course_dict[course.name].terms self.assertTrue(term in terms) self.assertNotEqual(self.course_dict[course.name].credits, 0) credit = split_plan[year][term]['credits'] self.assertTrue((12 <= credit <= 18) or credit == 0)
def test_5_credits(self): # goal of only 4 courses, but cannot all fit in one term since they're all 5-credit plan = course_scheduler(self.course_dict, [('SPAN', '1100'), ('SPAN', '1101'), ('SPAN', '1103'), ('SPAN', '2203')], []) split_plan = split_by_term(plan) self.assertNotEqual(split_plan['Frosh']['Fall']['courses'], []) self.assertNotEqual(split_plan['Frosh']['Spring']['courses'], []) self.assertEqual(split_plan['Soph']['Fall']['courses'], []) self.assertEqual(split_plan['Soph']['Spring']['courses'], []) self.assertEqual(split_plan['Junior']['Fall']['courses'], []) self.assertEqual(split_plan['Junior']['Spring']['courses'], []) self.assertEqual(split_plan['Senior']['Fall']['courses'], []) self.assertEqual(split_plan['Senior']['Spring']['courses'], [])
def test_simple_plan(self): # in this case, there is no ambiguity in the optimal terms to schedule the goal and its prereqs in plan = course_scheduler(self.course_dict, [('MATH', '2410')], []) split_plan = split_by_term(plan) self.assertTrue( ('MATH', '1200') in split_plan['Frosh']['Fall']['courses'] or ('MATH', '1300') in split_plan['Frosh']['Fall']['courses']) if ('MATH', '1200') in split_plan['Frosh']['Fall']['courses']: self.assertTrue( ('MATH', '1201') in split_plan['Frosh']['Spring']['courses']) self.assertTrue(('MATH', '2200') in split_plan['Soph']['Fall']['courses']) self.assertTrue( ('MATH', '2300') in split_plan['Soph']['Spring']['courses']) self.assertTrue( ('MATH', '2410') in split_plan['Junior']['Fall']['courses']) if ('MATH', '1300') in split_plan['Frosh']['Fall']['courses']: self.assertTrue( ('MATH', '1301') in split_plan['Frosh']['Spring']['courses']) self.assertTrue(('MATH', '2300') in split_plan['Soph']['Fall']['courses']) self.assertTrue( ('MATH', '2410') in split_plan['Soph']['Spring']['courses'])
def test_goal_satisfied(self): # testing the scheduler when the provided goal has already been satisfied plan = course_scheduler(self.course_dict, [('CS', '1101')], [('CS', '1101')]) self.assertEqual(plan, ())
def test_no_goal(self): plan = course_scheduler(self.course_dict, [], []) self.assertEqual(plan, ())