예제 #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')])
예제 #2
0
파일: test_heap.py 프로젝트: yasn77/whitepy
 def test_get(self):
     stack = Stack(['addr', 'item'])
     heap = Heap(stack)
     heap.set()
     stack.push('addr')
     heap.get()
     assert stack.pop() == 'item'
예제 #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
예제 #4
0
 def setUp(self):
     self.stack = Stack()
     self.heap = Heap(self.stack)
     self.io = ws_io(self.stack)
예제 #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
예제 #6
0
 def test_isempty(self):
     stack = Stack()
     assert stack.isempty() is True
예제 #7
0
 def test_modulo(self):
     stack = Stack([5, 3])
     stack.math.modulo()
     assert len(stack) is 1 and stack[-1] is 2
예제 #8
0
 def test_duplicate_empty(self):
     stack = Stack()
     stack.dup()
     assert stack.isempty() is True
예제 #9
0
 def test_multiply(self):
     stack = Stack([3, 2])
     stack.math.multiply()
     assert len(stack) is 1 and stack[-1] is 6
예제 #10
0
 def test_subtract(self):
     stack = Stack([3, 1])
     stack.math.subtract()
     assert len(stack) is 1 and stack[-1] is 2
예제 #11
0
 def test_add(self):
     stack = Stack([1, 1])
     stack.math.add()
     assert len(stack) is 1 and stack[-1] is 2
예제 #12
0
 def test_discard(self):
     stack = Stack('abc')
     stack.discard()
     assert len(stack) is 2 and stack[-1] is 'b'
예제 #13
0
 def test_swap(self):
     stack = Stack('abc')
     stack.swap()
     assert stack[-1] is 'b' and stack[-2] is 'c'
예제 #14
0
 def test_dupicate_nonempty(self):
     stack = Stack([True])
     stack.dup()
     assert len(stack) is 2 and stack[-1]
예제 #15
0
 def test_divide(self):
     stack = Stack([6, 2])
     stack.math.divide()
     assert len(stack) is 1 and stack[-1] is 3
예제 #16
0
파일: test_heap.py 프로젝트: yasn77/whitepy
 def test_set(self):
     stack = Stack(['addr', 'item'])
     heap = Heap(stack)
     heap.set()
     assert heap['addr'] == 'item'
예제 #17
0
 def test_push(self):
     stack = Stack()
     stack.push(True)
     assert stack[-1]