|
| 1 | +{-| |
| 2 | +Description: Filter Req Data module tests. |
| 3 | +
|
| 4 | +Module that contains the tests for the filtering of Req within the DynamicGraphs module. |
| 5 | +
|
| 6 | +-} |
| 7 | + |
| 8 | +module RequirementTests.FilterReqTests |
| 9 | +( test_filterReqs ) where |
| 10 | + |
| 11 | +import Database.Requirement (Req (..)) |
| 12 | +import DynamicGraphs.GraphGenerator (filterReq) |
| 13 | +import DynamicGraphs.GraphOptions (GraphOptions (..)) |
| 14 | +import Test.Tasty (TestTree, testGroup) |
| 15 | +import Test.Tasty.HUnit (assertEqual, testCase) |
| 16 | + |
| 17 | +-- Test GraphOptions |
| 18 | +graphOptionsSimple :: GraphOptions |
| 19 | +graphOptionsSimple = |
| 20 | + GraphOptions { taken = [], |
| 21 | + departments = [], |
| 22 | + excludedDepth = 0, |
| 23 | + maxDepth = -1, |
| 24 | + courseNumPrefix = [], |
| 25 | + distribution = [], |
| 26 | + location = [], |
| 27 | + includeRaws = True, |
| 28 | + includeGrades = True |
| 29 | + } |
| 30 | + |
| 31 | +graphOptionsWithDepartmentsAndTaken :: GraphOptions |
| 32 | +graphOptionsWithDepartmentsAndTaken = |
| 33 | + GraphOptions { taken = ["CSC108H1"], |
| 34 | + departments = ["CSC", "STA"], |
| 35 | + excludedDepth = 0, |
| 36 | + maxDepth = -1, |
| 37 | + courseNumPrefix = [], |
| 38 | + distribution = [], |
| 39 | + location = [], |
| 40 | + includeRaws = True, |
| 41 | + includeGrades = True |
| 42 | + } |
| 43 | + |
| 44 | +graphOptionsWithTaken :: GraphOptions |
| 45 | +graphOptionsWithTaken = |
| 46 | + GraphOptions { taken = ["CSC108H1"], |
| 47 | + departments = [], |
| 48 | + excludedDepth = 0, |
| 49 | + maxDepth = -1, |
| 50 | + courseNumPrefix = [], |
| 51 | + distribution = [], |
| 52 | + location = [], |
| 53 | + includeRaws = True, |
| 54 | + includeGrades = True |
| 55 | + } |
| 56 | + |
| 57 | +-- | List of (description, input requirements, input GraphOptions, expected filtered result) |
| 58 | +filterReqTestCases :: [(String, Req, GraphOptions, Req)] |
| 59 | +filterReqTestCases = |
| 60 | + [("Removes already taken courses", |
| 61 | + ReqAnd [J "CSC207H1" "", J "CSC148H1" "", J "CSC108H1" ""], |
| 62 | + graphOptionsWithDepartmentsAndTaken, |
| 63 | + ReqAnd [J "CSC207H1" "", J "CSC148H1" ""] |
| 64 | + ), |
| 65 | + ("Does not filer out valid departments", |
| 66 | + ReqAnd [J "CSC148H1" "", J "STA257H1" ""], |
| 67 | + graphOptionsWithDepartmentsAndTaken, |
| 68 | + ReqAnd [J "CSC148H1" "", J "STA257H1" ""] |
| 69 | + ), |
| 70 | + ("Filters out courses not in a valid department", |
| 71 | + ReqAnd [J "MAT137Y1" "", J "CSC207H1" ""], |
| 72 | + graphOptionsWithDepartmentsAndTaken, |
| 73 | + J "CSC207H1" "" |
| 74 | + ), |
| 75 | + ("Handles ReqAnd", |
| 76 | + ReqAnd [J "CSC207H1" "", J "CSC148H1" "", J "CSC108H1" ""], |
| 77 | + graphOptionsWithDepartmentsAndTaken, |
| 78 | + ReqAnd [J "CSC207H1" "", J "CSC148H1" ""] |
| 79 | + ), |
| 80 | + ("Handles None input", |
| 81 | + None, |
| 82 | + graphOptionsWithDepartmentsAndTaken, |
| 83 | + None |
| 84 | + ), |
| 85 | + ("Returns None when both in an or should be removed", |
| 86 | + ReqOr [J "MAT137Y1" "", J "MAT237Y1" ""], |
| 87 | + graphOptionsWithDepartmentsAndTaken, |
| 88 | + None |
| 89 | + ), |
| 90 | + ("Removes OR when only one req remains", |
| 91 | + ReqOr [J "MAT137Y1" "", ReqAnd [J "CSC207H1" "", J "CSC148H1" "", J "CSC108H1" ""]], |
| 92 | + graphOptionsWithDepartmentsAndTaken, |
| 93 | + ReqAnd [J "CSC207H1" "", J "CSC148H1" ""] |
| 94 | + ), |
| 95 | + ("Removes Nothing from dept filter if departments is empty in GraphOptions", |
| 96 | + ReqOr [J "MAT137Y1" "", J "MAT237Y1" ""], |
| 97 | + graphOptionsWithTaken, |
| 98 | + ReqOr [J "MAT137Y1" "", J "MAT237Y1" ""] |
| 99 | + ), |
| 100 | + ("Removes nothing from a height of > 1 tree with no departments", |
| 101 | + ReqAnd [J "CSC369H1" "", ReqAnd [J "CSC209H1" "", ReqAnd [J "CSC207H1" "", J "CSC148H1" "", J "CSC108H1" ""], J "CSC236H1" ""]], |
| 102 | + graphOptionsSimple, |
| 103 | + ReqAnd [J "CSC369H1" "", ReqAnd [J "CSC209H1" "", ReqAnd [J "CSC207H1" "", J "CSC148H1" "", J "CSC108H1" ""], J "CSC236H1" ""]] |
| 104 | + ), |
| 105 | + ("Removes only CSC108H1 at the bottom of a height > 1 tree and empty department", |
| 106 | + ReqAnd [J "CSC369H1" "", ReqAnd [J "CSC209H1" "", ReqAnd [J "CSC207H1" "", J "CSC148H1" "", J "CSC108H1" ""], J "CSC236H1" ""]], |
| 107 | + graphOptionsWithTaken, |
| 108 | + ReqAnd [J "CSC369H1" "", ReqAnd [J "CSC209H1" "", ReqAnd [J "CSC207H1" "", J "CSC148H1" ""], J "CSC236H1" ""]] |
| 109 | + ) |
| 110 | + ] |
| 111 | + |
| 112 | +-- | Helper to run a single test case |
| 113 | +runFilterReqTest :: String -> Req -> GraphOptions -> Req -> TestTree |
| 114 | +runFilterReqTest description input options expected = |
| 115 | + testCase description $ |
| 116 | + assertEqual ("Failed test: " ++ description) |
| 117 | + expected |
| 118 | + (filterReq options input) |
| 119 | + |
| 120 | +-- | Generate all tests from the list above |
| 121 | +runFilterReqTests :: [TestTree] |
| 122 | +runFilterReqTests = |
| 123 | + [runFilterReqTest name input options expected | (name, input, options, expected) <- filterReqTestCases] |
| 124 | + |
| 125 | +-- | Test suite for FilterReq |
| 126 | +test_filterReqs :: TestTree |
| 127 | +test_filterReqs = testGroup "FilterReq Tests" runFilterReqTests |
0 commit comments