def test_check():
    # subj1001
    subj1001 = course.Course('SUBJ', '1001', 'Subject1', 6, [t1, t2, t3, t4, t5, t6, t7, t8, t9], faculty)

    # subj1003, prereq subj1001 and final year
    prereq_final = yearReq.YearReq(year=-1)
    prereq1001 = subjectReq.SubjectReq(subj1001)

    req1001_and_final = andReq.AndReq([prereq1001, prereq_final])
    subj1003 = course.Course('SUBJ', '1003', 'Subject3', 6, [t1, t2, t3, t4, t5, t6, t7, t8, t9], faculty, req1001_and_final)

    subj1004 = course.Course('SUBJ', '1004', 'Subject4', 6, [t1, t2, t3, t4, t5, t6, t7, t8, t9], faculty)

    filter1001 = specificCourseFilter.SpecificCourseFilter(subj1001)
    filter1003 = specificCourseFilter.SpecificCourseFilter(subj1003)
    filter1004 = specificCourseFilter.SpecificCourseFilter(subj1004)

    # subj1002, prereq 6 uoc from subj1003, 1004
    or_filter = orFilter.OrFilter([filter1003, filter1004])
    prereq_6uoc = uocReq.UOCReq(6, or_filter)
    assert prereq_6uoc.filter is not None
    subj1002 = course.Course('SUBJ', '1002', 'Subject2', 6, [t1, t2, t3, t4, t5, t6, t7, t8, t9], faculty, prereq_6uoc)

    filter1002 = specificCourseFilter.SpecificCourseFilter(subj1002)

    uni.reset_courses([subj1001, subj1002, subj1003, subj1004])

    req1001 = minDegreeReq.MinDegreeReq(filter1001, 6)
    req1002 = minDegreeReq.MinDegreeReq(filter1002, 6)
    req1003 = minDegreeReq.MinDegreeReq(filter1003, 6)

    degree1 = degree.Degree(1, 'Bachelor of Testing', 2019, 3, faculty, [req1001, req1002, req1003], 'BAT1')

    gen = generator.Generator(degree1, uni)
    prog = gen.generate()

    assert len(prereq_6uoc.check(prog, t9)) == 0
    assert len(prereq_6uoc.check(prog, t8)) == 0
    assert len(prereq_6uoc.check(prog, t7)) == 1
    assert prereq_6uoc.check(prog, t7)[0] == '6 UoC fulfilling [(SUBJ1003) OR (SUBJ1004)]'

    prereq_12uoc = uocReq.UOCReq(12)
    assert len(prereq_12uoc.check(prog, t9)) == 0
    assert len(prereq_12uoc.check(prog, t8)) == 0
    assert len(prereq_12uoc.check(prog, t7)) == 1
    assert prereq_12uoc.check(prog, t7)[0] == '12 UoC'
    def test_insert_empty_uoc_req(self):
        uoc = 20
        requirement = uocReq.UOCReq(uoc, None)

        self.dbGenerator.insert_requirements(self.first_course_id, requirement,
                                             None, [], [])

        course = self.uni.find_course(self.first_course.course_code)
        prereq = course.prereqs
        assert prereq is not None
        assert prereq.requirement_name == 'UocRequirement'
        assert prereq.uoc == uoc
        assert prereq.filter is None
    def test_insert_uoc_req_with_gen_ed_filter(self):
        input_filter = genEdFilter.GenEdFilter()

        uoc = 20
        requirement = uocReq.UOCReq(uoc, input_filter)

        self.dbGenerator.insert_requirements(self.first_course_id, requirement,
                                             None, [], [])

        course = self.uni.find_course(self.first_course.course_code)
        prereq = course.prereqs
        assert prereq is not None
        assert prereq.filter is not None
        filter = prereq.filter
        assert filter.filter_name == input_filter.filter_name
def test_with_filter():
    # subj1001
    subj1001 = course.Course('SUBJ', '1001', 'Subject1', 6, [t1, t2, t3, t4, t5, t6, t7, t8, t9], faculty)

    # subj1003, prereq subj1001 and final year
    prereq_final = yearReq.YearReq(year=-1)
    prereq1001 = subjectReq.SubjectReq(subj1001)

    req1001_and_final = andReq.AndReq([prereq1001, prereq_final])
    subj1003 = course.Course('SUBJ', '1003', 'Subject3', 6, [t1, t2, t3, t4, t5, t6, t7, t8, t9], faculty, req1001_and_final)

    subj1004 = course.Course('SUBJ', '1004', 'Subject4', 6, [t1, t2, t3, t4, t5, t6, t7, t8, t9], faculty)

    filter1001 = specificCourseFilter.SpecificCourseFilter(subj1001)
    filter1003 = specificCourseFilter.SpecificCourseFilter(subj1003)
    filter1004 = specificCourseFilter.SpecificCourseFilter(subj1004)

    # subj1002, prereq 6 uoc from subj1003, 1004
    or_filter = orFilter.OrFilter([filter1003, filter1004])
    prereq_6uoc = uocReq.UOCReq(6, or_filter)
    assert prereq_6uoc.filter is not None
    subj1002 = course.Course('SUBJ', '1002', 'Subject2', 6, [t1, t2, t3, t4, t5, t6, t7, t8, t9], faculty, prereq_6uoc)

    filter1002 = specificCourseFilter.SpecificCourseFilter(subj1002)

    uni.reset_courses([subj1001, subj1002, subj1003, subj1004])

    req1001 = minDegreeReq.MinDegreeReq(filter1001, 6)
    req1002 = minDegreeReq.MinDegreeReq(filter1002, 6)
    req1003 = minDegreeReq.MinDegreeReq(filter1003, 6)

    degree1 = degree.Degree(1, 'Bachelor of Testing', 2019, 3, faculty, [req1001, req1002, req1003], 'BAT1')

    gen = generator.Generator(degree1, uni)
    prog = gen.generate()

    assert prog.enrolled(subj1001)
    assert prog.enrolled(subj1002)
    assert prog.enrolled(subj1003)

    assert prog.term_taken(subj1001) == t1
    assert prog.term_taken(subj1002) == t8
    assert prog.term_taken(subj1003) == t7
    def test_insert_uoc_req_with_or_filter(self):
        input_sub_filter = freeElectiveFilter.FreeElectiveFilter()

        input_filter = orFilter.OrFilter([input_sub_filter])

        uoc = 20
        requirement = uocReq.UOCReq(uoc, input_filter)

        self.dbGenerator.insert_requirements(self.first_course_id, requirement,
                                             None, [], [])

        course = self.uni.find_course(self.first_course.course_code)
        prereq = course.prereqs
        assert prereq is not None
        assert prereq.filter is not None
        filter = prereq.filter
        assert filter.filter_name == input_filter.filter_name
        assert len(filter.filters) == 1
        sub_filter = filter.filters[0]
        assert sub_filter.filter_name == input_sub_filter.filter_name
def test_no_filter():
    # Make some courses
    # subj1001
    subj1001 = course.Course('SUBJ', '1001', 'Subject1', 6, [t1, t2, t3, t4, t5, t6, t7, t8, t9], faculty)

    # subj1002, prereq subj1001
    prereq1001 = subjectReq.SubjectReq(subj1001)
    prereq_12uoc = uocReq.UOCReq(12)
    subj1002 = course.Course('SUBJ', '1002', 'Subject2', 6, [t1, t2, t3, t4, t5, t6, t7, t8, t9], faculty, prereq_12uoc)

    # subj1003, prereq subj1001 and final year
    prereq_final = yearReq.YearReq(year=-1)
    req1001_and_final = andReq.AndReq([prereq1001, prereq_final])
    subj1003 = course.Course('SUBJ', '1003', 'Subject3', 6, [t1, t2, t3, t4, t5, t6, t7, t8, t9], faculty, req1001_and_final)

    uni.reset_courses([subj1001, subj1002, subj1003])


    filter1001 = specificCourseFilter.SpecificCourseFilter(subj1001)
    filter1002 = specificCourseFilter.SpecificCourseFilter(subj1002)
    filter1003 = specificCourseFilter.SpecificCourseFilter(subj1003)
    req1001 = minDegreeReq.MinDegreeReq(filter1001, 6)
    req1002 = minDegreeReq.MinDegreeReq(filter1002, 6)
    req1003 = minDegreeReq.MinDegreeReq(filter1003, 6)

    degree1 = degree.Degree(1, 'Bachelor of Testing', 2019, 3, faculty, [req1001, req1002, req1003], 'BAT1')

    gen = generator.Generator(degree1, uni)
    prog = gen.generate()

    assert prog.enrolled(subj1001)
    assert prog.enrolled(subj1002)
    assert prog.enrolled(subj1003)

    assert prog.term_taken(subj1001) == t1
    assert prog.term_taken(subj1002) == t8
    assert prog.term_taken(subj1003) == t7
Exemple #7
0
    def make_single_course_req(self,
                               string: str) -> Optional['courseReq.CourseReq']:
        split = string.split()

        if split[0] == 'unparsed':
            return unparsedReq.UnparsedReq(" ".join(split[1:]))
        # subject requirements
        elif self.is_course_code(split[0]):
            if len(split) == 1:
                return scrapedSubjectReq.ScrapedSubjectReq(split[0])
            elif len(split) == 2:
                course, mark = split
                mark_num = self.make_int(mark)
                if mark_num is None:
                    return None
                if mark.isdigit():
                    return scrapedSubjectReq.ScrapedSubjectReq(
                        course, mark_num)

        # WAM requirements
        elif 'wam' in split:
            if split[0] == 'wam' and split[1].isdigit() and len(split) == 2:
                return wamReq.WAMReq(int(split[1]))
            elif split[1] == 'wam' and split[0].isdigit() and len(split) == 2:
                return wamReq.WAMReq(int(split[0]))
            else:
                print('COULD NOT PARSE WAM REQ')
                return None

        # year requirements
        elif split[0] == 'year' and len(split) == 2:
            return yearReq.YearReq(int(split[1]))

        # UOC requirements
        elif 'uoc' in split:
            print(split)
            if split[0] == 'uoc' and split[1].isdigit() and int(
                    split[1]) % 6 == 0:
                units = int(split[1])
            elif split[1] == 'uoc' and split[0].isdigit() and int(
                    split[0]) % 6 == 0:
                units = int(split[0])
            else:
                # could not parse req
                print('COULD NOT PARSE UOC REQ')
                return None

            if len(split) > 2:
                filter = self.parse_uoc_req_filter(split)
                if filter is None:
                    # could not parse filter
                    print('COULD NOT PARSE COURSE FILTER')
                    return None
                else:
                    return uocReq.UOCReq(units, filter)
            else:
                return uocReq.UOCReq(units)

        # enrollment requirements
        elif split[0] == 'enrol' and len(split) == 2:
            # Degree ids have both a number and letter code with a space between them, but we'll put
            # underscores instead in the extra requirements
            degree = split[1]
            degree = degree.replace('_', ' ')
            degree = degree.upper()
            return scrapedEnrollmentReq.ScrapedEnrollmentReq(degree)

        # something has gone wrong
        print('ERROR: could not parse course req')
        print(string)
        return None