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')])
def test_get(self): stack = Stack(['addr', 'item']) heap = Heap(stack) heap.set() stack.push('addr') heap.get() assert stack.pop() == 'item'
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
def setUp(self): self.stack = Stack() self.heap = Heap(self.stack) self.io = ws_io(self.stack)
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
def test_isempty(self): stack = Stack() assert stack.isempty() is True
def test_modulo(self): stack = Stack([5, 3]) stack.math.modulo() assert len(stack) is 1 and stack[-1] is 2
def test_duplicate_empty(self): stack = Stack() stack.dup() assert stack.isempty() is True
def test_multiply(self): stack = Stack([3, 2]) stack.math.multiply() assert len(stack) is 1 and stack[-1] is 6
def test_subtract(self): stack = Stack([3, 1]) stack.math.subtract() assert len(stack) is 1 and stack[-1] is 2
def test_add(self): stack = Stack([1, 1]) stack.math.add() assert len(stack) is 1 and stack[-1] is 2
def test_discard(self): stack = Stack('abc') stack.discard() assert len(stack) is 2 and stack[-1] is 'b'
def test_swap(self): stack = Stack('abc') stack.swap() assert stack[-1] is 'b' and stack[-2] is 'c'
def test_dupicate_nonempty(self): stack = Stack([True]) stack.dup() assert len(stack) is 2 and stack[-1]
def test_divide(self): stack = Stack([6, 2]) stack.math.divide() assert len(stack) is 1 and stack[-1] is 3
def test_set(self): stack = Stack(['addr', 'item']) heap = Heap(stack) heap.set() assert heap['addr'] == 'item'
def test_push(self): stack = Stack() stack.push(True) assert stack[-1]