Bugfix on tests + turmit.pop ++

This commit is contained in:
doc 2018-04-24 23:52:38 +02:00
commit 283c2abcfa
2 changed files with 70 additions and 8 deletions

View file

@ -18,11 +18,12 @@ class Turmit(object):
return self._stack[self._cur]
def _pop(self):
''' @brief Pop a value from the stack
''' @brief Pops a value from the stack
If stack head is 0, set the stack head to len(self._stack) - 1
@note If stack head is 0, set the stack head to len(self._stack)
- 1
@return poped value
@return popped value
'''
res = self._stack[self._cur]
if self._cur == 0:
@ -32,9 +33,11 @@ class Turmit(object):
return res
def _push(self, val):
''' @brief Push a value on the stack
''' @brief Pushes a value on the stack
If no size left on the stack, the head is set to 0
@note If no space left on the stack, the head is set to 0
@param val int : value to push
'''
self._cur += 1
if self._cur >= len(self._stack):
@ -55,21 +58,80 @@ class Turmit(object):
@RpnOp
def add(self, a, b):
''' @brief Adds one value to another
@param a int : value
@param b int : value to add to a
@return a + b
'''
return a + b
@RpnOp
def sub(self, a, b):
''' @brief Substitutes a value to another
@param a int : value
@param b int : value to substitute to a
@return a - b
'''
return a - b
@RpnOp
def bin_and(self, a, b):
return a & b
''' @brief Binary and
@param a int : value
@param b int : value
@return a & b
'''
return a & b
@RpnOp
def dup(self, a):
''' @brief Duplicates stack head
@param a int : value
@return a
'''
self._push(a)
return a
@RpnOp
def lshift(self, a, b):
''' @brief Left shifts a of b
@param a int : value
@param b int : value
@return a << b
'''
return a << b
@RpnOp
def mod(self, a, b):
''' @brief Gives a modulo b
@param a int : value
@param b int : value
@return a % b
'''
return a % b
@RpnOp
def mul(self, a, b):
''' @brief Multiplies a with b
@param a int : value
@param b int : value
@return a * b
'''
return a * b
@RpnOp
def bin_or(self, a, b):
''' @brief Binary or
@param a int : value
@param b int : value
@return a | b
'''
return a | b
@RpnOp
def pop(self, a):
''' @brief Pops a, head of the stack
@param a int : value
'''
pass

View file

@ -237,13 +237,13 @@ class TurmitTestCase(unittest.TestCase):
def test_pop(self):
''' Test turmit pop() method '''
self._rpn('pop', 0)
self._rpn('pop', 1)
t = Turmit()
t._push(10)
t._push(2)
t.pop()
self.assertEqual(t._cur, 0)
self.asertEqual(t.shead, 10)
self.assertEqual(t.shead, 10)
t.pop()
self.assertEqual(t._cur, len(t._stack) - 1)