Esempio n. 1
0
class TestIo(unittest.TestCase):
    def setUp(self):
        self.stack = Stack()
        self.heap = Heap(self.stack)
        self.io = ws_io(self.stack)

    @patch('builtins.input', side_effect='TEST'.split())
    def test_i_chr(self, input):
        self.stack.push('1')  # Heap address used for stack.pop()
        self.stack.push('1')  # Heap address for storing input
        self.io.i_chr(self.heap)
        self.heap.get()
        assert self.stack.pop() == 'TEST'

    @patch('builtins.input', side_effect='1')
    def test_i_int(self, input):
        self.stack.push('1')  # Heap address used for stack.pop()
        self.stack.push('1')  # Heap address for storing input
        self.io.i_int(self.heap)
        self.heap.get()
        assert self.stack.pop() == 1

    def test_o_int(self):
        self.stack.push('1')
        with patch('sys.stdout') as fake_stdout:
            self.io.o_int()
        (fake_stdout.asset_has_calls[call.buffer.write(b'1')])

    def test_o_chr(self):
        self.stack.push(65)
        with patch('sys.stdout') as fake_stdout:
            self.io.o_chr()
        (fake_stdout.asset_has_calls[call.buffer.write(b'A')])
Esempio n. 2
0
 def test_get(self):
     stack = Stack(['addr', 'item'])
     heap = Heap(stack)
     heap.set()
     stack.push('addr')
     heap.get()
     assert stack.pop() == 'item'
Esempio n. 3
0
 def test_stack_opper_swap_subtract(self):
     stack = Stack()
     stack.append(5)
     stack.append(10)
     stack.swap()
     stack.math.subtract()
     assert len(stack) is 1 and stack[-1] is 5
Esempio n. 4
0
 def setUp(self):
     self.stack = Stack()
     self.heap = Heap(self.stack)
     self.io = ws_io(self.stack)
Esempio n. 5
0
 def test_stack_opper_dup_add(self):
     stack = Stack()
     stack.append(1)
     stack.dup()
     stack.math.add()
     assert len(stack) is 1 and stack[-1] is 2
Esempio n. 6
0
 def test_isempty(self):
     stack = Stack()
     assert stack.isempty() is True
Esempio n. 7
0
 def test_modulo(self):
     stack = Stack([5, 3])
     stack.math.modulo()
     assert len(stack) is 1 and stack[-1] is 2
Esempio n. 8
0
 def test_duplicate_empty(self):
     stack = Stack()
     stack.dup()
     assert stack.isempty() is True
Esempio n. 9
0
 def test_multiply(self):
     stack = Stack([3, 2])
     stack.math.multiply()
     assert len(stack) is 1 and stack[-1] is 6
Esempio n. 10
0
 def test_subtract(self):
     stack = Stack([3, 1])
     stack.math.subtract()
     assert len(stack) is 1 and stack[-1] is 2
Esempio n. 11
0
 def test_add(self):
     stack = Stack([1, 1])
     stack.math.add()
     assert len(stack) is 1 and stack[-1] is 2
Esempio n. 12
0
 def test_discard(self):
     stack = Stack('abc')
     stack.discard()
     assert len(stack) is 2 and stack[-1] is 'b'
Esempio n. 13
0
 def test_swap(self):
     stack = Stack('abc')
     stack.swap()
     assert stack[-1] is 'b' and stack[-2] is 'c'
Esempio n. 14
0
 def test_dupicate_nonempty(self):
     stack = Stack([True])
     stack.dup()
     assert len(stack) is 2 and stack[-1]
Esempio n. 15
0
 def test_divide(self):
     stack = Stack([6, 2])
     stack.math.divide()
     assert len(stack) is 1 and stack[-1] is 3
Esempio n. 16
0
 def test_set(self):
     stack = Stack(['addr', 'item'])
     heap = Heap(stack)
     heap.set()
     assert heap['addr'] == 'item'
Esempio n. 17
0
 def test_push(self):
     stack = Stack()
     stack.push(True)
     assert stack[-1]