本文整理汇总了Python中pyrsistent.v.evolver函数的典型用法代码示例。如果您正苦于以下问题:Python evolver函数的具体用法?Python evolver怎么用?Python evolver使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了evolver函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_pvectors_produced_from_the_same_evolver_do_not_interfere
def test_pvectors_produced_from_the_same_evolver_do_not_interfere(pvector):
original_list = list(range(40))
v = pvector(original_list)
e = v.evolver()
e.extend([1, 2, 3])
e[2] = 20
e[35] = 350
v1 = e.persistent()
v1_expected = original_list + [1, 2, 3]
v1_expected[2] = 20
v1_expected[35] = 350
e.extend([-1, -2, -3])
e[3] = -30
e[36] = -360
v2 = e.persistent()
v2_expected = v1_expected + [-1, -2, -3]
v2_expected[3] = -30
v2_expected[36] = -360
assert list(v1) == v1_expected
assert list(v2) == v2_expected
示例2: test_evolver_simple_update_in_tree
def test_evolver_simple_update_in_tree(pvector):
v = pvector(range(35))
e = v.evolver()
e[10] = -10
assert e[10] == -10
assert e.persistent()[10] == -10
示例3: test_evolver_extend
def test_evolver_extend(pvector):
v = pvector([1000])
e = v.evolver()
e.extend([2000, 3000])
e[2] = 20000
assert list(e.persistent()) == [1000, 2000, 20000]
assert list(v) == [1000]
示例4: test_evolver_simple_update_just_outside_vector
def test_evolver_simple_update_just_outside_vector(pvector):
v = pvector()
e = v.evolver()
e[0] = 1
assert e[0] == 1
assert e.persistent()[0] == 1
assert len(v) == 0
示例5: test_evolver_simple_update_in_tail
def test_evolver_simple_update_in_tail(pvector):
v = pvector(range(35))
e = v.evolver()
e[33] = -33
assert e[33] == -33
assert e.persistent()[33] == -33
assert v[33] == 33
示例6: test_evolver_assign_and_read_with_negative_indices
def test_evolver_assign_and_read_with_negative_indices(pvector):
v = pvector([1, 2, 3])
e = v.evolver()
e[-1] = 4
e.extend([11, 12, 13])
e[-1] = 33
assert e[-1] == 33
assert list(e.persistent()) == [1, 2, 4, 11, 12, 33]
示例7: test_evolver_append
def test_evolver_append(pvector):
v = pvector()
e = v.evolver()
e.append(1000)
assert e[0] == 1000
e[0] = 2000
assert e[0] == 2000
assert list(e.persistent()) == [2000]
assert list(v) == []
示例8: test_no_dependencies_between_evolvers_from_the_same_pvector
def test_no_dependencies_between_evolvers_from_the_same_pvector(pvector):
original_list = list(range(40))
v = pvector(original_list)
e1 = v.evolver()
e2 = v.evolver()
e1.extend([1, 2, 3])
e1[2] = 20
e1[35] = 350
e2.extend([-1, -2, -3])
e2[2] = -20
e2[35] = -350
e1_expected = original_list + [1, 2, 3]
e1_expected[2] = 20
e1_expected[35] = 350
assert list(e1.persistent()) == e1_expected
e2_expected = original_list + [-1, -2, -3]
e2_expected[2] = -20
e2_expected[35] = -350
assert list(e2.persistent()) == e2_expected
示例9: test_evolver_multi_level_multi_update_in_tree
def test_evolver_multi_level_multi_update_in_tree(pvector):
# This test is mostly to detect memory/ref count issues in the native implementation
v = pvector(range(3500))
e = v.evolver()
# Update differs between first and second time since the
# corresponding node will be marked as dirty the first time only.
e[10] = -10
e[11] = -11
e[10] = -1000
# Update in neighbour node
e[50] = -50
e[50] = -5000
# Update in node in other half of vector
e[3000] = -3000
e[3000] = -30000
# Before freezing
assert e[10] == -1000
assert e[11] == -11
assert e[50] == -5000
assert e[3000] == -30000
# Run a GC to provoke any potential misbehavior
import gc
gc.collect()
v2 = e.persistent()
assert v2[10] == -1000
assert v2[50] == -5000
assert v2[3000] == -30000
# Run a GC to provoke any potential misbehavior
gc.collect()
# After freezing
assert e[10] == -1000
assert e[11] == -11
assert e[50] == -5000
assert e[3000] == -30000
# Original stays the same
assert v[10] == 10
assert v[50] == 50
assert v[3000] == 3000
示例10: test_evolver_returns_itself_on_evolving_operations
def test_evolver_returns_itself_on_evolving_operations(pvector):
# Does this to be able to chain operations
v = pvector([1, 2])
assert v.evolver().append(3).extend([4, 5]).set(1, 6).persistent() == pvector([1, 6, 3, 4, 5])
示例11: test_evolver_with_no_updates_returns_same_pvector
def test_evolver_with_no_updates_returns_same_pvector(pvector):
v = pvector([1, 2])
assert v.evolver().persistent() is v
示例12: test_evolver_set_out_of_range
def test_evolver_set_out_of_range(pvector):
v = pvector([0])
e = v.evolver()
with pytest.raises(IndexError) as error:
e[10] = 1
assert str(error.value) == "Index out of range: 10"
示例13: test_evolver_deallocate_dirty_evolver
def test_evolver_deallocate_dirty_evolver(pvector):
# Ref count handling in native implementation
v = pvector(range(3220))
e = v.evolver()
e[10] = -10
e[3220] = -3220
示例14: test_evolver_no_update
def test_evolver_no_update(pvector):
# This is mostly a test against memory leaks in the C implementation
v = pvector(range(40))
assert v.evolver().persistent() == v