def test_prior_studies_simple():
    prior = [subj1001, subj1002]

    # Make some degree requirements
    # 1001 and 1002 and 1003
    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, 2, faculty,
                            [req1001, req1002, req1003], 'BAT1')

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

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

    assert prog.term_taken(subj1003) == t1
    assert prog.term_taken(subj1001) == None
    assert prog.term_taken(subj1002) == None

    assert prog.unit_count_total() == 18
    assert degree1.complete(prog)
def test_exclusion():
    # make an exclusion subject
    subj1005 = course.Course('SUBJ',
                             '1005',
                             'Subject5',
                             6, [t1, t3, t4, t6],
                             faculty,
                             prereqs=prereq1001,
                             exclusions=['SUBJ1002'])
    uni.add_course(subj1005)

    # Make some degree requirements
    # 1001 and 1002 and 1003
    filter1001 = specificCourseFilter.SpecificCourseFilter(subj1001)
    filter1002 = specificCourseFilter.SpecificCourseFilter(subj1002)
    filter1005 = specificCourseFilter.SpecificCourseFilter(subj1005)

    req1001 = minDegreeReq.MinDegreeReq(filter1001, 6)
    req1002 = minDegreeReq.MinDegreeReq(filter1002, 6)
    req1005 = minDegreeReq.MinDegreeReq(filter1005, 6)

    degree1 = degree.Degree(1, 'Bachelor of Testing', 2019, 2, faculty,
                            [req1001, req1002, req1005], 'TESTA1')

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

    assert prog.enrolled(subj1001)
    assert prog.enrolled(subj1002)
    assert not prog.enrolled(subj1005)

    assert prog.term_taken(subj1001) == t1
    assert prog.term_taken(subj1002) == t3
def test_simple_or_requirement():
    # Make some degree requirements
    # 1001 and 1002 and 1003
    filter1001 = specificCourseFilter.SpecificCourseFilter(subj1001)
    filter1002 = specificCourseFilter.SpecificCourseFilter(subj1002)
    filter1003 = specificCourseFilter.SpecificCourseFilter(subj1003)
    filter1004 = specificCourseFilter.SpecificCourseFilter(subj1004)
    or_filter = orFilter.OrFilter([filter1002, filter1004])

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

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

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

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

    assert prog.term_taken(subj1001) == t1
    assert prog.term_taken(subj1002) == t3
    assert prog.term_taken(subj1003) == t4
def test_check():
    # 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)
    subj1002 = course.Course('SUBJ', '1002', 'Subject2', 6,
                             [t1, t2, t3, t4, t5, t6, t7, t8, t9], faculty,
                             prereq1001)

    # subj1003, prereq subj1001 and 1002
    subj1003 = course.Course('SUBJ', '1003', 'Subject3', 6,
                             [t1, t2, t3, t4, t5, t6, t7, t8, t9], faculty,
                             prereq1001)

    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, 2, faculty,
                            [req1001, req1002, req1003], 'BAT1')

    enrol1001 = courseEnrollment.CourseEnrollment(subj1001, t1)
    enrol1002 = courseEnrollment.CourseEnrollment(subj1002, t2)
    enrol1003 = courseEnrollment.CourseEnrollment(subj1003, t7)

    prog = program.Program(degree1, [enrol1001, enrol1002, enrol1003], [])

    req = yearReq.YearReq(2)
    assert len(req.check(prog, t1)) == 1
    assert len(req.check(prog, t2)) == 1
    assert len(req.check(prog, t3)) == 1
    assert len(req.check(prog, t4)) == 0
    assert len(req.check(prog, t5)) == 0
    assert len(req.check(prog, t6)) == 0
    assert len(req.check(prog, t7)) == 0
    assert len(req.check(prog, t8)) == 0
    assert len(req.check(prog, t9)) == 0
    assert req.check(prog, t3)[0] == 'Year 2 in your degree'

    req = yearReq.YearReq(-1)
    assert len(req.check(prog, t1)) == 1
    assert len(req.check(prog, t2)) == 1
    assert len(req.check(prog, t3)) == 1
    assert len(req.check(prog, t4)) == 1
    assert len(req.check(prog, t5)) == 1
    assert len(req.check(prog, t6)) == 1
    assert len(req.check(prog, t7)) == 0
    assert len(req.check(prog, t8)) == 0
    assert len(req.check(prog, t9)) == 0
    assert req.check(prog, t3)[0] == 'Final year in your degree'
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_one():
    # 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_year2 = yearReq.YearReq(year=2)
    assert prereq_year2.year == 2
    req1001_and_year2 = andReq.AndReq([prereq1001, prereq_year2])
    subj1002 = course.Course('SUBJ', '1002', 'Subject2', 6,
                             [t1, t2, t3, t4, t5, t6, t7, t8, t9], faculty,
                             req1001_and_year2)

    # subj1003, prereq subj1001 and 1002
    prereq_final = yearReq.YearReq(year=-1)
    assert prereq_final.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) == t4
    assert prog.term_taken(subj1003) == t7
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_requirement_ordering():
    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, 2, faculty,
                            [req1003, req1002, req1001], 'TESTA1')

    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) == t3
    assert prog.term_taken(subj1003) == t4
def test_single_course_requirements():
    # Make some degree requirements
    # 1001 and 1002 and 1003
    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, 2, 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) == t3
    assert prog.term_taken(subj1003) == t4
def test_term_cap_enrollment():
    # make a coreq subject
    subj1005 = course.Course('SUBJ', '1005', 'Subject5', 6, [t1, t4], faculty)
    subj1006 = course.Course('SUBJ', '1006', 'Subject6', 6, [t1, t2], faculty)
    subj1007 = course.Course('SUBJ', '1007', 'Subject7', 6, [t1, t2], faculty)

    uni.add_course(subj1005)
    uni.add_course(subj1006)
    uni.add_course(subj1007)

    # Make some degree requirements
    # 1001 and 1002 and 1003
    filter1001 = specificCourseFilter.SpecificCourseFilter(subj1001)
    filter1005 = specificCourseFilter.SpecificCourseFilter(subj1005)
    filter1006 = specificCourseFilter.SpecificCourseFilter(subj1006)
    filter1007 = specificCourseFilter.SpecificCourseFilter(subj1007)

    req1001 = minDegreeReq.MinDegreeReq(filter1001, 6)
    req1005 = minDegreeReq.MinDegreeReq(filter1005, 6)
    req1006 = minDegreeReq.MinDegreeReq(filter1006, 6)
    req1007 = minDegreeReq.MinDegreeReq(filter1007, 6)

    degree1 = degree.Degree(1, 'Bachelor of Testing', 2019, 2, faculty,
                            [req1001, req1005, req1006, req1007], 'TESTA1')

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

    assert prog.enrolled(subj1001)
    assert prog.enrolled(subj1005)
    assert prog.enrolled(subj1006)
    assert prog.enrolled(subj1007)

    assert prog.term_taken(subj1001) == t1
    assert prog.term_taken(subj1005) == t1
    assert prog.term_taken(subj1006) == t1
    assert prog.term_taken(subj1007) == t2
def test_equivalent():
    # make an equivalent subject
    subj1005 = course.Course('SUBJ',
                             '1005',
                             'Subject5',
                             6, [],
                             faculty,
                             equivalents=['SUBJ1001'])
    subj1001.add_equivalent('SUBJ1005')

    subj1006 = course.Course('SUBJ', '1006', 'Subject5', 6, [t2, t3, t5, t6],
                             faculty)

    uni.add_course(subj1005)
    uni.add_course(subj1006)

    # Make some degree requirements
    # 1006 requires 1005 but 1001 is an equivalent
    filter1005 = specificCourseFilter.SpecificCourseFilter(subj1005)
    filter1006 = specificCourseFilter.SpecificCourseFilter(subj1006)

    req1005 = minDegreeReq.MinDegreeReq(filter1005, 6)
    req1006 = minDegreeReq.MinDegreeReq(filter1006, 6)

    degree1 = degree.Degree(1, 'Bachelor of Testing', 2019, 2, faculty,
                            [req1005, req1006], 'TESTA1')

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

    assert prog.enrolled(subj1001)
    assert prog.enrolled(subj1006)
    assert not prog.enrolled(subj1005)

    assert prog.term_taken(subj1001) == t1
    assert prog.term_taken(subj1006) == t2