-
Notifications
You must be signed in to change notification settings - Fork 1
/
util_test.py
61 lines (46 loc) · 2.15 KB
/
util_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import pytest
from util import prereqs_parser
def test_null():
assert prereqs_parser('') == []
def test_invalid():
with pytest.raises(ValueError):
prereqs_parser('a and b or c')
with pytest.raises(ValueError):
prereqs_parser('a or b and c')
with pytest.raises(ValueError):
prereqs_parser('(a and b or c')
def test_single():
# use Hypothesis testing
assert prereqs_parser('a') == [['a']]
assert prereqs_parser('b') == [['b']]
def test_simple_or():
assert prereqs_parser('a or b') == [['a'], ['b']]
assert prereqs_parser('a or b or c') == [['a'], ['b'], ['c']]
def test_simple_and():
assert prereqs_parser('a and b') == [['a', 'b']]
assert prereqs_parser('a and b and c') == [['a', 'b', 'c']]
def test_unnecessary_bracket():
assert prereqs_parser('(a and b) and c') == [['a', 'b', 'c']]
assert prereqs_parser('a and (b and c)') == [['a', 'b', 'c']]
assert prereqs_parser('(a or b) or c') == [['a'], ['b'], ['c']]
assert prereqs_parser('a or (b or c)') == [['a'], ['b'], ['c']]
def test_simple_combination():
assert prereqs_parser('(a and b) or c') == [['a', 'b'], ['c']]
assert prereqs_parser('a and (b or c)') == [['a', 'b'], ['a', 'c']]
# assert prereqs_parser('a and (b or c)') == prereqs_parser('(a and b) or (a and c)') == [['a', 'b'], ['a', 'c']]
assert prereqs_parser('(a and b) or (c and d)') == [['a', 'b'], ['c', 'd']]
def test_complex_combination():
assert len(prereqs_parser('(a or b or c or d) and (e or f)')) == 4 * 2
assert len(prereqs_parser('(a or b) and (c or d) and (e or f)')) == 2 * 2 * 2
assert len(prereqs_parser('(a or b) and (c or d) and e and f')) == 2 * 2
assert len(prereqs_parser('(a or b) and (c and d) and (e or f)')) == 2 * 2
def test_courses():
# comp1511
cs1511 = prereqs_parser('COMP1511 or DPST1091 or COMP1911 or COMP1917')
assert cs1511 == [['comp1511'], ['dpst1091'], ['comp1911'], ['comp1917']]
# with my courses filter => [['comp1511']]
cs9417 = prereqs_parser('(comp2521 and comp1531) or comp2521') == [['comp2521', 'comp1531'], ['comp2521']]
def test_duplicate():
pass
def test_relevant_filter():
pass