-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterpreter_test.py
62 lines (52 loc) · 2.42 KB
/
interpreter_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
60
61
62
import unittest
from garbage_collection_simulator.interpreter import Interpreter
class InterpreterTest(unittest.TestCase):
def test_print_command(self):
i = Interpreter(100)
i.execute_command("L1 = ((a)(b((c)d))ef(g(h)))")
i.execute_command("Print L1")
def test_delete_command(self):
i = Interpreter(100)
i.execute_command("salam = ((a)(b((c)d))ef(g(h)))")
i.execute_command("Delete salam from (**")
i.execute_command("Print salam")
def test_empty_list_command(self):
i = Interpreter(100)
i.execute_command("salam = ()")
i.execute_command("Print salam")
def test_make_child_command(self):
i = Interpreter(100)
i.execute_command("a = ((((Z)Y)X)TM(A(B(C))))")
i.execute_command("b = ((V)PQ(R(S)))")
i.execute_command("Make (ABC) Child of b at (***(** Without Root")
i.execute_command("Print b")
i.execute_command("Make b Child of a at (*** Without Root")
i.execute_command("Print a")
def test_make_child_with_root_command(self):
i = Interpreter(100)
i.execute_command("b = ((V)PQ(R(S)))")
i.execute_command("Make (ABC) Child of b at (***(** With Root")
i.execute_command("Print b")
def test_different_variable_name(self):
i = Interpreter(100)
i.execute_command("d222_good_var3 = (((((A(C)B)))))") # testing variable names with numbers
i.execute_command("Print d222_good_var3")
def test_invalid_list_expression_raising_syntax_error(self):
i = Interpreter(100)
self.assertRaises(SyntaxError, i.execute_command, "salam = ((*)(*))(8))") # Invalid list expression raises error
def test_garbage_collect(self):
i = Interpreter(100)
i.execute_command("a = ((((Z)Y)X)TM(A(B(C))))")
i.execute_command("b = ((V)PQ(R(S)))")
i.execute_command("c = (123(8)45(6(7)))")
i.execute_command("Print c")
i.execute_command("Make (ABC) Child of b at (***(** Without Root")
i.execute_command("Print b")
i.execute_command("Make b Child of a at (*** Without Root")
i.execute_command("Print a")
i.execute_command("b = (D(E)(F(H))(G))")
i.execute_command("Print b")
i.execute_command("c = (B)")
i.execute_command("Garbage-Collect") # We can see that list c was garbage collected and returned to memory
if __name__ == '__main__':
unittest.main()