コード例 #1
0
def test_pop():
    stack = Stack()
    stack.push([1, 3, 4])
    assert stack.pop() == 4
    assert stack.items == [1, 3]
    stack = Stack()
    with pytest.raises(Exception):
        stack.pop()
コード例 #2
0
ファイル: Decoder.py プロジェクト: megajanlott/cbor-decoder
    def __decode(self, stream: CBORStream, handler):
        stack = Stack()
        stack.push(MajorType())

        while not stack.isEmpty():
            top = stack.pop()

            if type(top) == str and top == 'break':
                # should be ArrayInf, MapInfValue, MapInfKey
                # ByteStringInf, TextStringInf
                inf_type = stack.pop()
                self.close_inf(inf_type, handler)
            else:
                new_states = top.run(stream, handler)

                if new_states:
                    stack.push(new_states)
コード例 #3
0
def test_is_empty():
    stack = Stack()
    assert stack.isEmpty() is True
    stack = Stack()
    stack.push(10)
    assert stack.isEmpty() is False
コード例 #4
0
def test_size():
    stack = Stack()
    stack.push(5)
    assert stack.size() == 1
    stack.push([6, 7])
    assert stack.size() == 3
コード例 #5
0
def test_peek():
    stack = Stack()
    stack.push([1, 3, 4])
    assert stack.peek() == 4
    assert stack.items == [1, 3, 4]
コード例 #6
0
def test_init():
    stack = Stack()
    assert stack.items == []
コード例 #7
0
def test_push_array():
    stack = Stack()
    stack.push([3, 4])
    assert stack.items == [3, 4]
    stack.push(['test', [5, 6]])
    assert stack.items == [3, 4, 'test', [5, 6]]
コード例 #8
0
def test_push():
    stack = Stack()
    stack.push(5)
    assert stack.items == [5]
    stack.push('test')
    assert stack.items == [5, 'test']