
% run as: swipl -q -s tests.pl -t run_tests

:- use_module(library(test_cover)).

:- begin_tests(planner).
:- [planner].

test(generateBlankSemesters) :-
    generateBlankSemesters(2017, [(2017,fall,[free,free,free,free]),
                                  (2018,spring,[free,free,free,free]),
                                  (2018,fall,[free,free,free,free]),
                                  (2019,spring, [free,free,free,free]),
                                  (2019,fall,[free,free,free,free]),
                                  (2020,spring,[free,free,free,free]),
                                  (2020,fall,[free,free,free,free]),
                                  (2021,spring,[free,free,free,free])]).

test(planFromBlank, [nondet]) :-
    generateBlankSemesters(2017, Semesters),
    % one possible plan
    finishDegree(Semesters, [(2017,fall,[free,free,free,free]),
                             (2018,spring,[csci141,free,free,free]),
                             (2018,fall,[free,free,free,free]),
                             (2019,spring,[free,free,free,free]),
                             (2019,fall,[csci142,free,free,free]),
                             (2020,spring,[csci221,free,free,math141]),
                             (2020,fall,[csci201,csci211,csci321,free]),
                             (2021,spring,[csci301,csci311,free,free])]).

test(planFromBlankAllPossibilities) :-
    generateBlankSemesters(2017, Semesters),
    % may take 20-30 seconds
    setof(PlannedSemesters, finishDegree(Semesters, PlannedSemesters), Result),
    length(Result, 2240).

test(manuallySetSemesterCourse) :-
    generateBlankSemesters(2017, BlankSemesters),
    manuallySetSemesterCourse(BlankSemesters, 2019, fall, csci321, Semesters),
    Semesters = [(2017,fall,[free,free,free,free]),
                 (2018,spring,[free,free,free,free]),
                 (2018,fall,[free,free,free,free]),
                 (2019,spring,[free,free,free,free]),
                 (2019,fall,[csci321,free,free,free]),
                 (2020,spring,[free,free,free,free]),
                 (2020,fall,[free,free,free,free]),
                 (2021,spring,[free,free,free,free])].

test(manuallySetSemesterCoursePlan, [nondet]) :-
    generateBlankSemesters(2017, BlankSemesters),
    manuallySetSemesterCourse(BlankSemesters, 2019, fall, csci321, Semesters),
    setMissingSemester(Semesters, 2018, spring, NewSemesters),
    % one possible plan
    finishDegree(NewSemesters, [(2017,fall,[csci141,free,free,free]),
                                (2018,spring,[x,x,x,x]),
                                (2018,fall,[csci142,free,free,free]),
                                (2019,spring,[csci221,free,free,free]),
                                (2019,fall,[csci321,free,free,free]),
                                (2020,spring,[free,free,free,math141]),
                                (2020,fall,[csci201,csci211,free,free]),
                                (2021,spring,[csci301,csci311,free,free])]).

test(manuallySetSemesterCoursePlanAllPossibilities) :-
    setof(PlannedSemesters,
        (generateBlankSemesters(2017, BlankSemesters),
         manuallySetSemesterCourse(BlankSemesters, 2019, fall, csci321, Semesters),
         setMissingSemester(Semesters, 2018, spring, NewSemesters),
         finishDegree(NewSemesters, PlannedSemesters)),
        Result),
    length(Result, 84).

test(freqOfferings) :-
    % may take 20-30 seconds
    setof(PlannedSemesters,
        (generateBlankSemesters(2017, BlankSemesters),
         finishDegree(BlankSemesters, PlannedSemesters)),
        Result),
    extractFreqPossibleCourseOfferings(Result, csci221, FreqOfferings),
    FreqOfferings = [((2018,fall),360),((2019,spring),720),((2019,fall),656),((2020,spring),504)].

test(manuallySetSemesterFreqOfferings) :-
    % may take 20-30 seconds
    setof(PlannedSemesters,
        (generateBlankSemesters(2017, BlankSemesters),
         manuallySetSemesterCourse(BlankSemesters, 2019, fall, csci321, Semesters),
         finishDegree(Semesters, PlannedSemesters)),
        Result),
    extractFreqPossibleCourseOfferings(Result, csci221, FreqOfferings),
    FreqOfferings = [((2018,fall),180),((2019,spring),360)].

:- end_tests(planner).

