|
@@ -0,0 +1,123 @@
|
|
1
|
+import unittest
|
|
2
|
+from unittest import skip
|
|
3
|
+
|
|
4
|
+from gte.turmit import Turmit
|
|
5
|
+
|
|
6
|
+class TurmitTestCase(unittest.TestCase):
|
|
7
|
+
|
|
8
|
+ def test_init_class(self):
|
|
9
|
+ ''' Test Turmit class __init__ '''
|
|
10
|
+ t = Turmit(42)
|
|
11
|
+ self.assertEqual(len(t._stack), 42)
|
|
12
|
+ self.assertEqual(t.shead, 0)
|
|
13
|
+ self.assertEqual(len(t._stack) - 1 , t._cur)
|
|
14
|
+
|
|
15
|
+ def test_push(self):
|
|
16
|
+ ''' Test Turmit _push() method '''
|
|
17
|
+ t = Turmit()
|
|
18
|
+ t._push(1)
|
|
19
|
+ self.assertEqual(t.shead, 1)
|
|
20
|
+ t._push(2)
|
|
21
|
+ self.assertEqual(t.shead, 2)
|
|
22
|
+
|
|
23
|
+ def test_add(self):
|
|
24
|
+ ''' Test turmit add method '''
|
|
25
|
+ t = Turmit()
|
|
26
|
+
|
|
27
|
+ t._push(42)
|
|
28
|
+ t._push(8)
|
|
29
|
+ t.add()
|
|
30
|
+ self.assertEqual(t._cur, 0)
|
|
31
|
+ self.assertEqual(t.shead, 50)
|
|
32
|
+
|
|
33
|
+ t._push(42)
|
|
34
|
+ t._push(8)
|
|
35
|
+ t.add()
|
|
36
|
+ self.assertEqual(t._cur, 1)
|
|
37
|
+ self.assertEqual(t.shead, 50)
|
|
38
|
+
|
|
39
|
+ t.add()
|
|
40
|
+
|
|
41
|
+ self.assertEqual(t._cur, 0)
|
|
42
|
+ self.assertEqual(t.shead, 100)
|
|
43
|
+
|
|
44
|
+ def test_mem_sz(self):
|
|
45
|
+ ''' Test turmit mem_sz() operation '''
|
|
46
|
+ t = Turmit(8)
|
|
47
|
+ self.assertEqual(len(t._stack), 8)
|
|
48
|
+
|
|
49
|
+ t._push(42)
|
|
50
|
+ t.mem_sz()
|
|
51
|
+ self.assertEqual(len(t._stack), 42)
|
|
52
|
+ self.assertEqual(t._cur, 7)
|
|
53
|
+
|
|
54
|
+ t._push(42)
|
|
55
|
+ t._push(8)
|
|
56
|
+ t.mem_sz()
|
|
57
|
+ self.assertEqual(t._cur, 0)
|
|
58
|
+ self.assertEqual(t.shead, 42)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+ @skip('Need implementation')
|
|
62
|
+ def test_sub(self):
|
|
63
|
+ ''' Test turmit sub() method '''
|
|
64
|
+ t = Turmit()
|
|
65
|
+
|
|
66
|
+ t._push(50)
|
|
67
|
+ t._push(8)
|
|
68
|
+
|
|
69
|
+ t.sub()
|
|
70
|
+ self.assertEqual(t._cur, 0)
|
|
71
|
+ self.assertEqual(t.shead, 42)
|
|
72
|
+
|
|
73
|
+ t._push(50)
|
|
74
|
+ t._push(8)
|
|
75
|
+ t.sub()
|
|
76
|
+ self.assertEqual(t._cur, 1)
|
|
77
|
+ self.assertEqual(t.shead, 42)
|
|
78
|
+
|
|
79
|
+ t.sub()
|
|
80
|
+ self.assertEqual(t._cur, 0)
|
|
81
|
+ self.assertEqual(t.shead, 0)
|
|
82
|
+
|
|
83
|
+ @skip('Need implementation')
|
|
84
|
+ def test_mul(self):
|
|
85
|
+ ''' Test turmit mul() method '''
|
|
86
|
+ t = Turmit()
|
|
87
|
+
|
|
88
|
+ t._push(7)
|
|
89
|
+ t._push(6)
|
|
90
|
+
|
|
91
|
+ t.mul()
|
|
92
|
+ self.assertEqual(t._cur, 0)
|
|
93
|
+ self.assertEqual(t.shead, 42)
|
|
94
|
+
|
|
95
|
+ t._push(7)
|
|
96
|
+ t._push(6)
|
|
97
|
+ t.mul()
|
|
98
|
+ self.assertEqual(t._cur, 1)
|
|
99
|
+ self.assertEqual(t.shead, 42)
|
|
100
|
+
|
|
101
|
+ t.mul()
|
|
102
|
+ self.assertEqual(t._cur, 0)
|
|
103
|
+ self.assertEqual(t.shead, 42 *42)
|
|
104
|
+
|
|
105
|
+ @skip('Need implementation')
|
|
106
|
+ def test_mod(self):
|
|
107
|
+ ''' Test turmit mod() method '''
|
|
108
|
+ t = Turmit()
|
|
109
|
+ t._push(42)
|
|
110
|
+ t._push(4)
|
|
111
|
+
|
|
112
|
+ t.mod()
|
|
113
|
+ self.assertEqual(t._cur, 0)
|
|
114
|
+ self.assertEqual(t.shead, 2)
|
|
115
|
+
|
|
116
|
+ @skip('Need implementation')
|
|
117
|
+ def test_dup(self):
|
|
118
|
+ ''' Test turmit dup() method '''
|
|
119
|
+ t = Turmit()
|
|
120
|
+ t._push(42)
|
|
121
|
+ t.dup()
|
|
122
|
+ self.assertEqual(t._cur, 1)
|
|
123
|
+ sefl.assertEqual(t.shead, 42)
|