-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathtest_ST.py
executable file
·47 lines (40 loc) · 1.12 KB
/
test_ST.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
#!/usr/bin/env python3
"""Test basic symbol table"""
from AlgsSedgewickWayne.ST import ST
def test_symbol_table():
"""Unit tests the ST data type."""
st = ST()
st.put("A", 1)
st.put("B", 1)
st.put("B", 2)
st.put("B", 3)
st.put("B", 4)
def test_symbol_table_01_08_01a():
"""Test sequence at 17:52 of 'Symbol Table APIs'"""
seq_in = "SEARCHEXAMPLE"
exp_out = [
("A", 8),
("C", 4),
("E", 12),
("H", 5),
("L", 11),
("M", 9),
("P", 10),
("R", 3),
("S", 0),
("X", 7),
]
_run(seq_in, exp_out)
def _run(seq_in, exp_out):
"""Run test: Fill Symbol Table; Compare with expected results"""
symtbl = ST()
for idx, letter in enumerate(seq_in):
symtbl.put(letter, idx)
for act_letter, (exp_letter, exp_val) in zip(symtbl.get_keys(), exp_out):
act_val = symtbl.get(act_letter)
print(f'("{act_letter}", {act_val}),')
assert act_letter == exp_letter
assert act_val == exp_val
if __name__ == '__main__':
#test_symbol_table()
test_symbol_table_01_08_01a()