本文整理汇总了Python中pyrsistent.pdeque函数的典型用法代码示例。如果您正苦于以下问题:Python pdeque函数的具体用法?Python pdeque怎么用?Python pdeque使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pdeque函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_iterable
def test_iterable():
"""
PDeques can be created from iterables even though they can't be len()
hinted.
"""
assert pdeque(iter("a")) == pdeque(iter("a"))
示例2: test_comparison
def test_comparison():
small = pdeque([1, 2])
large = pdeque([1, 2, 3])
assert small < large
assert large > small
assert not small > large
assert not large < small
assert large != small
# Not equal to other types
assert small != [1, 2]
示例3: test_indexing
def test_indexing():
assert pdeque([1, 2, 3])[0] == 1
assert pdeque([1, 2, 3])[1] == 2
assert pdeque([1, 2, 3])[2] == 3
assert pdeque([1, 2, 3])[-1] == 3
assert pdeque([1, 2, 3])[-2] == 2
assert pdeque([1, 2, 3])[-3] == 1
示例4: test_indexing_out_of_range
def test_indexing_out_of_range():
with pytest.raises(IndexError):
pdeque([1, 2, 3])[-4]
with pytest.raises(IndexError):
pdeque([1, 2, 3])[3]
with pytest.raises(IndexError):
pdeque([2])[-2]
示例5: test_popleft
def test_popleft():
x = pdeque([1, 2, 3, 4]).popleft()
assert x.left == 2
assert x.right == 4
x = x.popleft()
assert x.left == 3
assert x.right == 4
x = x.popleft()
assert x.right == 4
assert x.left == 4
x = x.popleft()
assert x == pdeque()
x = pdeque([1, 2]).popleft()
assert x == pdeque([2])
x = x.popleft()
assert x == pdeque()
assert pdeque().append(1).popleft() == pdeque()
assert pdeque().appendleft(1).popleft() == pdeque()
示例6: test_left_on_empty_deque
def test_left_on_empty_deque():
with pytest.raises(IndexError):
pdeque().left
示例7: test_pop_multiple
def test_pop_multiple():
assert pdeque([1, 2, 3, 4]).pop(3) == pdeque([1])
assert pdeque([1, 2]).pop(3) == pdeque()
示例8: test_literalish
def test_literalish():
assert dq(1, 2, 3) == pdeque([1, 2, 3])
示例9: test_hashing
def test_hashing():
assert hash(pdeque([1, 2, 3])) == hash(pdeque().append(1).append(2).append(3))
示例10: test_indexing_invalid_type
def test_indexing_invalid_type():
with pytest.raises(TypeError) as e:
pdeque([1, 2, 3])['foo']
assert 'cannot be interpreted' in str(e)
示例11: test_count
def test_count():
x = pdeque([1, 2, 3, 2, 1])
assert x.count(1) == 2
assert x.count(2) == 2
示例12: test_extendleft_with_maxlen
def test_extendleft_with_maxlen():
assert pdeque([1, 2], maxlen=3).extendleft([3, 4]) == pdeque([4, 3, 1])
assert pdeque([1, 2], maxlen=2).extendleft([3, 4]) == pdeque([4, 3])
assert pdeque([], maxlen=2).extendleft([1, 2]) == pdeque([2, 1])
assert pdeque([], maxlen=0).extendleft([1, 2]) == pdeque([])
示例13: test_extendleft
def test_extendleft():
assert pdeque([2, 1]).extendleft([3, 4]) == pdeque([4, 3, 2, 1])
示例14: test_extend_with_maxlen
def test_extend_with_maxlen():
assert pdeque([1, 2], maxlen=3).extend([3, 4]) == pdeque([2, 3, 4])
assert pdeque([1, 2], maxlen=2).extend([3, 4]) == pdeque([3, 4])
assert pdeque([], maxlen=2).extend([1, 2]) == pdeque([1, 2])
assert pdeque([], maxlen=0).extend([1, 2]) == pdeque([])
示例15: test_extend
def test_extend():
assert pdeque([1, 2]).extend([3, 4]) == pdeque([1, 2, 3, 4])