def test_byOffered(self): """ Tests that offered search returns correct results """ d = DescSearches() self.assertTrue(len(d.byOffered(self.three_courses, True, '=')) == 2) self.assertTrue(len(d.byOffered(self.three_courses, False, '=')) == 1)
def test_getPrerequisiteTree_not_found(self): ''' Test that getPrerequisiteTree raises an exception if root course can't be found ''' d = DescSearches() with self.assertRaises(Exception): d.getPrerequisiteTree(self.three_courses, "DNE*1234", None)
def test_byOffered_none(self): """ Tests that offered search returns empty array for no matches """ d = DescSearches() self.assertTrue(len(d.byOffered([self.three_courses[2]], True, '=')) == 0) self.assertTrue(len(d.byOffered(self.single_course, False, '=')) == 0)
def test_byKeyword_whitespace(self): """ Test that keyword search ignores leading and trailing whitespace """ d = DescSearches() self.assertTrue(len(d.byKeyword(self.single_course, " htm*4080 ", '=')) == 1) self.assertTrue(len(d.byKeyword(self.single_course, "\nhtm*4080\n", '=')) == 1) self.assertTrue(len(d.byKeyword(self.single_course, "\thtm*4080\t", '=')) == 1)
def test_byCourseSubject_contains(self): """ Test that subject search returns correct results for contains comparison """ d = DescSearches() self.assertTrue(len(d.byCourseSubject(self.three_courses, "hosp", "~")) == 1) self.assertTrue(len(d.byCourseSubject(self.three_courses, "compu", "~")) == 2)
def test_byKeyword(self): """ Test that keyword search returns correct results """ d = DescSearches() self.assertTrue(len(d.byKeyword(self.single_course, "htm*4080", '=')) == 1) self.assertTrue(len(d.byKeyword(self.single_course, "SERVICE", '=')) == 1) self.assertTrue(len(d.byKeyword(self.single_course, "hospitality and tourism", '=')) == 1)
def setUpClass(self): self.search = DescSearches() converter = PDFConverter() converter.openPDF("./c12.pdf") parser = CourseParser() self.courses = parser.open_file("converted-pdf.txt")
def test_byDepartment_contains(self): """ Tests that department search returns correct results for contains comparison """ d = DescSearches() self.assertTrue(len(d.byDepartment(self.three_courses, "tourism", "~")) == 1) self.assertTrue(len(d.byDepartment(self.three_courses, "science", "~")) == 2) self.assertTrue(len(d.byDepartment(self.three_courses, "school", "~")) == 3) self.assertTrue(len(d.byDepartment(self.three_courses, "hosp", "~")) == 1)
def test_byCourseCode_contains(self): """ Test that course code search returns correct results for contains comparison """ d = DescSearches() self.assertTrue(len(d.byCourseCode(self.three_courses, "ci", "~")) == 2) self.assertTrue(len(d.byCourseCode(self.three_courses, "h", "~")) == 1) self.assertTrue(len(d.byCourseCode(self.three_courses, "CIS", "~")) == 2) self.assertTrue(len(d.byCourseCode(self.three_courses, "HTM", "~")) == 1)
def test_byCourseLevel_invalid(self): """ Test that course level search raises exceptions for invalid numbers """ d = DescSearches() with self.assertRaises(Exception) : d.byCourseLevel(self.single_course, "0", '=') with self.assertRaises(Exception) : d.byCourseLevel(self.single_course, "11", '=') with self.assertRaises(Exception) : d.byCourseLevel(self.single_course, "a", '=') with self.assertRaises(Exception) : d.byCourseLevel(self.single_course, 4, '=')
def test_byCourseLevel_greaterThan(self): """ Test that course level search returns correct results for greater than comparison """ d = DescSearches() self.assertTrue(len(d.byCourseLevel(self.three_courses, "1", ">")) == 3) self.assertTrue(len(d.byCourseLevel(self.three_courses, "2", ">")) == 2) self.assertTrue(len(d.byCourseLevel(self.three_courses, "3", ">")) == 1) self.assertTrue(len(d.byCourseLevel(self.three_courses, "4", ">")) == 0) self.assertTrue(len(d.byCourseLevel(self.three_courses, "5", ">")) == 0)
def test_byCourseLevel_lessThanOrEqualTo(self): """ Test that course level search returns correct results for less than or equal to comparison """ d = DescSearches() self.assertTrue(len(d.byCourseLevel(self.three_courses, "1", "<=")) == 0) self.assertTrue(len(d.byCourseLevel(self.three_courses, "2", "<=")) == 1) self.assertTrue(len(d.byCourseLevel(self.three_courses, "3", "<=")) == 2) self.assertTrue(len(d.byCourseLevel(self.three_courses, "4", "<=")) == 3) self.assertTrue(len(d.byCourseLevel(self.three_courses, "5", "<=")) == 3)
def test_byKeyword_invalid(self): """ Test that keyword search raises exceptions for invalid keyword """ d = DescSearches() with self.assertRaises(Exception) : d.byKeyword(self.single_course, 5, '=') with self.assertRaises(Exception) : d.byKeyword(self.single_course, "", '=') with self.assertRaises(Exception) : d.byKeyword(self.single_course, " ", '=') with self.assertRaises(Exception) : d.byKeyword(self.single_course, "\n\t", '=')
def test_byCourseNumber_greaterThan(self): """ Test that course number search returns correct results for greater than comparison """ d = DescSearches() self.assertTrue(len(d.byCourseNumber(self.three_courses, "1000", ">")) == 3) self.assertTrue(len(d.byCourseNumber(self.three_courses, "2000", ">")) == 3) self.assertTrue(len(d.byCourseNumber(self.three_courses, "2250", ">")) == 2) self.assertTrue(len(d.byCourseNumber(self.three_courses, "3250", ">")) == 1) self.assertTrue(len(d.byCourseNumber(self.three_courses, "4080", ">")) == 0)
def test_byCourseNumber_lessThanOrEqualTo(self): """ Test that course number search returns correct results for less than or equal to comparison """ d = DescSearches() self.assertTrue(len(d.byCourseNumber(self.three_courses, "2000", "<=")) == 0) self.assertTrue(len(d.byCourseNumber(self.three_courses, "2250", "<=")) == 1) self.assertTrue(len(d.byCourseNumber(self.three_courses, "3250", "<=")) == 2) self.assertTrue(len(d.byCourseNumber(self.three_courses, "4080", "<=")) == 3) self.assertTrue(len(d.byCourseNumber(self.three_courses, "5000", "<=")) == 3)
def test_getPrerequisiteTree(self): ''' Test that getPrerequisiteTree creates correct tree ''' d = DescSearches() results = d.getPrerequisiteTree(self.three_courses, "CIS*3250", None) self.assertTrue(type(results['prerequisites'][0]['course']) is Course) self.assertTrue(results['prerequisites'][0]['course'].fullname() == "CIS*2250") self.assertTrue(len(results['prerequisites'][0]['prerequisites']) == 2) self.assertTrue(type(results['prerequisites'][0]['prerequisites'][0]['course']) is str)
def test_byCourseNumber_invalid(self): """ Test that course number search raises exceptions for invalid numbers """ d = DescSearches() with self.assertRaises(Exception) : d.byCourseNumber(self.single_course, "abcd", '=') with self.assertRaises(Exception) : d.byCourseNumber(self.single_course, 1234, '=') with self.assertRaises(Exception) : d.byCourseNumber(self.single_course, "11", '=') with self.assertRaises(Exception) : d.byCourseNumber(self.single_course, "40801", '=') with self.assertRaises(Exception) : d.byCourseNumber(self.single_course, 4, '=')
def test_byCourseSubject_invalid(self): ''' Tests that subject search fails when fed something invalid ''' d= DescSearches() with self.assertRaises(Exception): d.byCourseSubject(self.three_courses, 1, '=') with self.assertRaises(Exception): d.byCourseSubject(self.three_courses, True, '=') with self.assertRaises(Exception): d.byCourseSubject(self.three_courses, 3.14, '=') with self.assertRaises(Exception): d.byCourseSubject(self.three_courses, [], '=')
def test_byKeyword_case(self): """ Test that keyword search returns correct results regardless of upper/lower case """ upperWord = "TOURISM" lowerWord = "tourism" mixedWord = "tOUrIsM" d = DescSearches() upperResult = d.byKeyword(self.single_course, upperWord, '=') lowerResult = d.byKeyword(self.single_course, lowerWord, '=') mixedResult = d.byKeyword(self.single_course, mixedWord, '=') self.assertTrue(len(upperResult) == 1) self.assertTrue(len(lowerResult) == 1) self.assertTrue(len(mixedResult) == 1)
def test_byCourseCode_case(self): """ Test that course code search returns correct results regardless of upper/lower case """ upperCode = "HTM" lowerCode = "htm" mixedCode = "hTm" d = DescSearches() upperResult = d.byCourseCode(self.single_course, upperCode, '=') lowerResult = d.byCourseCode(self.single_course, lowerCode, '=') mixedResult = d.byCourseCode(self.single_course, mixedCode, '=') self.assertTrue(len(upperResult) == 1) self.assertTrue(len(lowerResult) == 1) self.assertTrue(len(mixedResult) == 1)
def test_byCourseSubject(self): ''' Tests that subject search returns correctly ''' d= DescSearches() self.assertTrue(len(d.byCourseSubject(self.single_course, "Hospitality and Tourism Management", '=')) == 1) self.assertTrue(len(d.byCourseSubject(self.single_course, "Computing and Information Science", '=')) == 0) self.assertTrue(len(d.byCourseSubject(self.two_courses, "Hospitality and Tourism Management", '=')) == 1) self.assertTrue(len(d.byCourseSubject(self.two_courses, "Computing and Information Science", '=')) == 1) self.assertTrue(len(d.byCourseSubject(self.three_courses, "Hospitality and Tourism Management", '=')) == 1) self.assertTrue(len(d.byCourseSubject(self.three_courses, "Computing and Information Science", '=')) == 2)
def test_byDepartment(self): #Test that department search returns correct results. d = DescSearches() self.assertTrue(len(d.byDepartment(self.single_course, "Food and Tourism Management", '=')) == 1) self.assertTrue(len(d.byDepartment(self.single_course, "School of Hospitality", '=')) == 1) self.assertTrue(len(d.byDepartment(self.two_courses, "School of Hospitality", '=')) == 1) self.assertTrue(len(d.byDepartment(self.two_courses, "School of Computer Science", '=')) == 1) self.assertTrue(len(d.byDepartment(self.three_courses, "School of Computer Science", '=')) == 2)
def test_byLectureHours(self): """ Tests that each comparison (including default) returns correct results """ d = DescSearches() self.assertTrue(len(d.byLectureHours(self.three_courses, 3.0)) == 2) # Default is "=" self.assertTrue(len(d.byLectureHours(self.three_courses, 3.5, "=")) == 1) self.assertTrue(len(d.byLectureHours(self.three_courses, 3.6, "<")) == 3) self.assertTrue(len(d.byLectureHours(self.three_courses, 3.0, "<=")) == 2) self.assertTrue(len(d.byLectureHours(self.three_courses, 3.0, ">")) == 1) self.assertTrue(len(d.byLectureHours(self.three_courses, 3.0, ">=")) == 3) self.assertTrue(len(d.byLectureHours(self.three_courses, 3.5, ">=")) == 1) self.assertTrue(len(d.byLectureHours(self.three_courses, 0.0, ">=")) == 3)
def test_byOffered_invalid(self): """ Tests that offered search throws error for invalid arguments """ d = DescSearches() with self.assertRaises(Exception): d.byOffered(self.single_course, 1, '=') with self.assertRaises(Exception): d.byOffered(self.single_course, "true", '=') with self.assertRaises(Exception): d.byOffered(self.single_course, 1.0, '=')
def test_byLabHours_invalid(self): """ Tests that search throws exceptions for invalid input """ d = DescSearches() with self.assertRaises(Exception): d.byLabHours(self.single_course, -1.0) with self.assertRaises(Exception): d.byLabHours(self.single_course, 1) with self.assertRaises(Exception): d.byLabHours(self.single_course, 2.0, "A")
def test_bySemester_invalid(self): """Test that semester search fails nonconforming input.""" d = DescSearches() with self.assertRaises(Exception): d.bySemester(self.single_course, "W", '=') with self.assertRaises(Exception): d.bySemester(self.single_course, 4, '=')
def test_byWeight_invalid(self): """Test that weight search fails nonconforming input.""" d = DescSearches() with self.assertRaises(Exception): d.byWeight(self.single_course, -1, '=') with self.assertRaises(Exception): d.byWeight(self.single_course, "sdfdf", '=')
def test_byWeight_oorange(self): """Test that weight search fails out of range input.""" d = DescSearches() with self.assertRaises(Exception): d.byWeight(self.single_course, 105.3, '=') with self.assertRaises(Exception): d.byWeight(self.single_course, 0.22, '=')
def test_byLectureHours_none(self): """ Tests that each comparison (including default) returns no results for no matches """ d = DescSearches() self.assertTrue(len(d.byLectureHours(self.three_courses, 16.0)) == 0) # Default is "=" self.assertTrue(len(d.byLectureHours(self.three_courses, 1.0, "=")) == 0) self.assertTrue(len(d.byLectureHours(self.three_courses, 0.0, "<")) == 0) self.assertTrue(len(d.byLectureHours(self.three_courses, 2.9, "<=")) == 0) self.assertTrue(len(d.byLectureHours(self.three_courses, 0.0, "<=")) == 0) self.assertTrue(len(d.byLectureHours(self.three_courses, 3.5, ">")) == 0) self.assertTrue(len(d.byLectureHours(self.three_courses, 3.6, ">=")) == 0)
class TestIntegration(unittest.TestCase): @classmethod def setUpClass(self): self.search = DescSearches() converter = PDFConverter() converter.openPDF("./c12.pdf") parser = CourseParser() self.courses = parser.open_file("converted-pdf.txt") def test_findCIS4250(self): socsCourses = self.search.byDepartment(self.courses, "School of Computer Science", "=") cisCourses = self.search.byCourseCode(socsCourses, "CIS", "=") fourthYearCourses = self.search.byCourseLevel(cisCourses, "4", "=") cis4250 = self.search.byCourseNumber(fourthYearCourses,"4250", "=") self.assertTrue(cis4250[0].code == "CIS" and cis4250[0].number == "4250") def test_findENVS1060(self): oneCreditCourses = self.search.byWeight(self.courses, 0.5, "=") summerCourses = self.search.bySemester(oneCreditCourses, SemesterOffered.S, "=") soesCourses = self.search.byDepartment(summerCourses, "School of Environmental Sciences", "=") firstYearCourses = self.search.byCourseLevel(soesCourses, "1", "=") envsCourses = self.search.byCourseCode(firstYearCourses, "ENVS", "=") envs1060 = self.search.byCourseNumber(envsCourses, "1060", "=") self.assertTrue(envs1060[0].code == "ENVS" and envs1060[0].number == "1060") def test_languageKeyword(self): languageKeywordCourses = self.search.byKeyword(self.courses, "language", "=") englishKeywordCourses = self.search.byKeyword(languageKeywordCourses, "english", "=") frenchKeywordCourses = self.search.byKeyword(englishKeywordCourses, "french", "=") fallCourses = self.search.bySemester(frenchKeywordCourses, SemesterOffered.F, "=") self.assertTrue(fallCourses[0].code == "FREN" and fallCourses[0].number == "3500")