def test_isConnected(self): """ scheduleinput._isConnected should return correct values and raise exceptions if necessary. """ lecType = "LEC" labType = "LAB" lecTup = ("28100", lecType, "HA", "4", "STAFF", "MWF 9:00- 9:50", "BS3 1200", "Wed, Mar 16, 8:00-10:00am", "64", "53", "n/a", "57", "0", "", "OPEN") labTup = ("28100", labType, "HA", "4", "STAFF", "MWF 9:00- 9:50", "BS3 1200", "Wed, Mar 16, 8:00-10:00am", "64", "53", "n/a", "57", "0", "", "OPEN") lec = coursedataparser.toClass(lecType, lecTup) lab = coursedataparser.toClass(labType, labTup) self.assertFalse(scheduleinput._isConnected([])) self.assertFalse(scheduleinput._isConnected([[lec]])) self.assertFalse(scheduleinput._isConnected([[lec, lec]])) self.assertFalse(scheduleinput._isConnected([[lec], [lab], [lec]])) self.assertFalse(scheduleinput._isConnected([[lec, lec], [lab], [lec]])) self.assertTrue(scheduleinput._isConnected([[lec], [lab]])) self.assertRaises(ValueError, scheduleinput._isConnected, [[lec], [lab], [lec, lec], [lab]]) self.assertRaises(ValueError, scheduleinput._isConnected, [[lec], [lab], [lab, lab], [lab]])
def test_getClassCodes(self): """ Schedule should return correct class codes. """ classRawTuple1 = ("10000", "LEC", "1", "0", "STAFF", "MWF 8:00- 9:50", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN") classRawTuple2 = ("20000", "LEC", "2", "0", "STAFF", "MWF 1:00- 2:50p", "ICS 180", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN") sched = schedule.Schedule([ coursedataparser.toClass("", classRawTuple1), coursedataparser.toClass("", classRawTuple2) ]) self.assertEqual(sched.getClassCodes(), [10000, 20000])
def test_class_name(self): """ Class should correctly store name argument. """ name = "ClassName" class1 = coursedataparser.toClass(name, self._classRawTuple1) self.assertEqual(class1.name, name)
def test_course_classes(self): """ course.Course should correctly store classes argument. """ classRawTuple1 = ("10000", "LEC", "1", "0", "STAFF", "MWF 8:00- 9:50", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN") classRawTuple2 = ("20000", "LEC", "2", "0", "STAFF", "MWF 1:00- 2:50p", "ICS 180", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN") classes = [ coursedataparser.toClass(self.NAME, classRawTuple1), coursedataparser.toClass(self.NAME, classRawTuple2) ] c1 = course.Course(self.NAME, classes) self.assertEqual(c1.classes, classes)
def test_calculateRedZoneScore(self): """ calculateRedZoneScore should return correct value. """ c1_1 = coursedataparser.toClass( "", ("52111", "RedIn", "1", "0", "STAFF", "TuTh 6:10- 7:00", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) c1_2 = coursedataparser.toClass( "", ("10010", "OK", "1", "0", "STAFF", "MWF 9:10- 10:00", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) c1_3 = coursedataparser.toClass( "", ("11112", "RedIn", "1", "0", "STAFF", "MWF 3:10- 4:00p", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) c1_4 = coursedataparser.toClass( "", ("20010", "RedOv", "1", "0", "STAFF", "MWF 4:10- 5:10p", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) c1_5 = coursedataparser.toClass( "", ("42111", "RedOv", "1", "0", "STAFF", "TuTh 9:10- 10:30p", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) c2_1 = coursedataparser.toClass( "", ("52111", "OK", "1", "0", "STAFF", "TuTh 10:10- 11:00", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) c2_2 = coursedataparser.toClass( "", ("10010", "OK", "1", "0", "STAFF", "MWF 9:10- 10:00", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) c2_3 = coursedataparser.toClass( "", ("11112", "RedIn", "1", "0", "STAFF", "MWF 3:10- 4:00p", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) c2_4 = coursedataparser.toClass( "", ("20010", "RedOv", "1", "0", "STAFF", "MWF 4:10- 5:10p", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) c2_5 = coursedataparser.toClass( "", ("42111", "RedOv", "1", "0", "STAFF", "TuTh 9:10- 10:30p", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) schedule1 = schedule.Schedule([c1_1, c1_2, c1_3, c1_4, c1_5]) schedule2 = schedule.Schedule([c2_1, c2_2, c2_3, c2_4, c2_5]) schedules = [schedule1, schedule2] redZones = [ coursedataparser.toClassTime("1:00- 9:00"), coursedataparser.toClassTime("3:00- 5:00p"), coursedataparser.toClassTime("10:00- 11:00p") ] self.assertEqual(schedule1.calculateRedZoneScore(redZones), -6) self.assertEqual(schedule2.calculateRedZoneScore(redZones), -4)
def test_class_parse(self): """ coursedataparser.toClass should correctly parse tuples. """ class1 = coursedataparser.toClass("", self._classRawTuple1) self.assertEqual(class1.code, 36610) self.assertEqual(class1.days.days, [0, 2, 4]) self.assertEqual(class1.classTime.start, coursedataparser.toTime("8:00")) self.assertEqual(class1.classTime.end, coursedataparser.toTime("9:50")) self.assertEqual(class1.type, "LAB")
def _convertToClassesByType(courseName: str, tuples: 'list of tuple') -> 'list of list of course.Class': """ Converts argument list of class-tuples into multiple lists of course.Class, where each list is made up of the classes of one type in sequence. E.g. For [lec, lec, lab, lec], returns [[lec, lec], [lab], [lec]]. """ classes = [] prevType = None for tup in tuples: try: currClass = coursedataparser.toClass(courseName, tup) except ValueError: print("SKIPPING INVALID CLASS: {}".format(tup)) else: currType = currClass.type if currType != prevType: classes.append([currClass]) prevType = currType else: classes[-1].append(currClass) return classes
def test_generatePossibleSchedules(self): """ schedule.generatePossibleSchedules should return correct values. """ class_2_1 = coursedataparser.toClass( "", ("21000", "LEC", "1", "0", "STAFF", "MWF 3:00- 3:50", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) class_2_2 = coursedataparser.toClass( "", ("22000", "LEC", "1", "0", "STAFF", "MWF 4:00- 5:00", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) course2 = course.Course("", [class_2_1, class_2_2]) class_3_1 = coursedataparser.toClass( "", ("31000", "LEC", "1", "0", "STAFF", "TuTh 7:00- 8:00", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) class_3_2 = coursedataparser.toClass( "", ("32000", "LEC", "1", "0", "STAFF", "MW 7:00- 8:00", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) course3 = course.Course("", [class_3_1, class_3_2]) class_4_1 = coursedataparser.toClass( "", ("41000", "LEC", "1", "0", "STAFF", "TuTh 10:00- 11:00", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) course4 = course.Course("", [class_4_1]) class_5_1 = coursedataparser.toClass( "", ("51000", "LEC", "1", "0", "STAFF", "TuTh 10:00- 10:50", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) course5 = course.Course("", [class_5_1]) scheds_1 = schedule.generatePossibleSchedules([course2], {}) scheds_2 = schedule.generatePossibleSchedules([course2, course4], {}) scheds_3 = schedule.generatePossibleSchedules([course2, course3], {}) scheds_4 = schedule.generatePossibleSchedules([course4, course5], {}) self.assertEqual([s.classes for s in scheds_1], [(class_2_1, ), (class_2_2, )]) self.assertEqual([s.classes for s in scheds_2], [(class_2_1, class_4_1), (class_2_2, class_4_1)]) self.assertEqual([s.classes for s in scheds_3], [(class_2_1, class_3_1), (class_2_1, class_3_2), (class_2_2, class_3_1), (class_2_2, class_3_2)]) self.assertEqual([s.classes for s in scheds_4], [])
def test_hasValidConnections(self): """ hasValidConnections should return correct value. """ c1_class1 = coursedataparser.toClass( "", ("52111", "LEC", "1", "0", "STAFF", "MWF 3:00- 3:50", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) c2_class1 = coursedataparser.toClass( "", ("10010", "LEC", "1", "0", "STAFF", "MWF 3:00- 3:50", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) c2_class2 = coursedataparser.toClass( "", ("20010", "LEC", "1", "0", "STAFF", "MWF 3:00- 3:50", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) c2_class3 = coursedataparser.toClass( "", ("30010", "LEC", "1", "0", "STAFF", "MWF 3:00- 3:50", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) c3_class1 = coursedataparser.toClass( "", ("11111", "LAB", "1", "0", "STAFF", "MWF 3:00- 3:50", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) c3_class2 = coursedataparser.toClass( "", ("11112", "LAB", "1", "0", "STAFF", "MWF 3:00- 3:50", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) c3_class3 = coursedataparser.toClass( "", ("21111", "LAB", "1", "0", "STAFF", "MWF 3:00- 3:50", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) c3_class4 = coursedataparser.toClass( "", ("21112", "LAB", "1", "0", "STAFF", "MWF 3:00- 3:50", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) c3_class5 = coursedataparser.toClass( "", ("21113", "LAB", "1", "0", "STAFF", "MWF 3:00- 3:50", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) c3_class6 = coursedataparser.toClass( "", ("31111", "LAB", "1", "0", "STAFF", "MWF 3:00- 3:50", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) c4_class1 = coursedataparser.toClass( "", ("42111", "LAB", "1", "0", "STAFF", "MWF 3:00- 3:50", "ICS 189", "", "44", "10/15", "n/a", "9", "0", "A&N", "OPEN")) connectedClassDict = { 10010: [c3_class1, c3_class2], 20010: [c3_class3, c3_class4, c3_class5], 30010: [c3_class6] } self.assertTrue( schedule.Schedule([c2_class1, c3_class1, c1_class1 ]).hasValidConnections(connectedClassDict)) self.assertFalse( schedule.Schedule([c2_class1, c3_class3 ]).hasValidConnections(connectedClassDict)) self.assertTrue( schedule.Schedule([c2_class3, c3_class6 ]).hasValidConnections(connectedClassDict)) self.assertFalse( schedule.Schedule([c2_class3, c3_class5 ]).hasValidConnections(connectedClassDict)) self.assertTrue( schedule.Schedule([c1_class1, c4_class1 ]).hasValidConnections(connectedClassDict)) self.assertTrue( schedule.Schedule([c3_class1, c3_class5 ]).hasValidConnections(connectedClassDict) ) # True because connection is one-way, lec to lab