コード例 #1
0
ファイル: test_ws_io_test.py プロジェクト: yasn77/whitepy
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
ファイル: test_ws_io_test.py プロジェクト: yasn77/whitepy
 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]