def test__assign_tuple_with_elements(): with operation(): c = C() c.x = (1, 2) d = C() d.x = (3, 4) assert c.x == (1, 2) assert d.x == (3, 4) with operation(c, d) as (c1, d1): c1.x = (c, d, d1) assert c.x == (1, 2) assert d.x == (3, 4) assert d1.x == (3, 4) assert tuple(e.x for e in c1.x) == ((1, 2), (3, 4), (3, 4)) with operation(c1, d1) as (c2, d2): d2.x = (5, 6) assert c.x == (1, 2) assert d.x == (3, 4) assert d1.x == (3, 4) assert tuple(e.x for e in c1.x) == ((1, 2), (3, 4), (3, 4)) assert d2.x == (5, 6) assert tuple(e.x for e in c2.x) == ((1, 2), (3, 4), (5, 6))
def sortedlist_addremove_one_op(element_count): with operation(): l = WrappedSortedList(random.sample(range(element_count), element_count)) with operation(l) as ll: def fn(): y = random.randrange(element_count) ll.add(y) ll.discard(y) yield fn
def test__version_list(): with operation(): c1 = C() c1.lst = [] with operation(c1) as c2: c2.lst.append(5) assert c1.lst == [] assert c2.lst == [5]
def test__independent_confluence(): with operation(): c = C() with operation(): d = C() assert c.a == 1 assert c.b is None assert d.a == 1 assert d.b is None
def test__reference_nested_mutate_operation(c, d): with operation(c) as c: c.b = d with operation(d) as d: d.b = c d.b.b.a = 5 assert c.a == 1 assert c.b.a == 1 assert c.b.b == None assert d.a == 1 assert d.b.b.a == 5 assert d.b.b.b is None
def test__sorted_list_discard(): with operation(): w = WrappedSortedList([5, 1, 2, 3, 4]) assert list(w) == [1, 2, 3, 4, 5] assert list(w) == [1, 2, 3, 4, 5] with operation(w) as ww: ww.discard(2) assert list(ww) == [1, 3, 4, 5] assert list(w) == [1, 2, 3, 4, 5] assert list(w) == [1, 2, 3, 4, 5] assert list(ww) == [1, 3, 4, 5]
def test__append_iterate(): with operation(): n = ListNode() assert list(lens(n)) == [] assert list(n._iter_from(0)) == [] n.append(1) assert list(lens(n)) == [1] assert list(n._iter_from(0)) == [1] n.append(2) assert list(lens(n)) == [2, 1] assert list(n._iter_from(0)) == [1, 2] n.append(3) assert list(lens(n)) == [3, 2, 1] assert list(n._iter_from(0)) == [1, 2, 3] n.append(4) assert list(lens(n)) == [4, 3, 2, 1] assert list(n._iter_from(0)) == [1, 2, 3, 4] n.append(5) assert list(lens(n)) == [5, 4, 3, 2, 1] assert list(n._iter_from(0)) == [1, 2, 3, 4, 5] assert list(n._iter_from(0)) == [1, 2, 3, 4, 5] assert list(n._iter_from(3)) == [4, 5] assert list(n._iter_from(5)) == []
def test__list_modify_after_assign(): with operation(): c1 = C() l = [] c1.lst = l l.append(5) assert c1.lst == [5]
def test__list_element_is_node(): with operation(): c1 = C() c1.lst = [] with operation(c1) as c2: c2.lst.append(c1) with operation(c1) as c22: c22.lst.append(5) with operation(c2) as c3: c3.lst[0].lst.append(2) assert c1.lst == [] assert c2.lst[0].lst == [] assert len(c2.lst) == 1 assert c3.lst[0].lst == [2]
def test__self_referential(): with operation(): d = D() d.x = (1, d) c = D() c.d = d # it's a cycle, did we crash? assert c.d.x[0] == 1 and c.d.x[1].x[0] == 1
def sortedlist_addremove_many_ops(element_count): with operation(): l = WrappedSortedList(random.sample(range(element_count), element_count)) def fn(): nonlocal l with operation(l) as l: y, z = random.randrange(element_count), random.randrange(element_count) l.add(y) l.discard(z) yield fn
def test__converting_assignment(): with operation(): c1 = C() d = D() d.y = 4 c1.d = d d.x = 3 assert (c1.d.x, c1.d.y) == (3, 4) d.x = 8 assert (c1.d.x, c1.d.y) == (3, 4) with operation(c1) as c2: c2.d.x = 5 assert (c1.d.x, c1.d.y) == (3, 4) assert (c2.d.x, c2.d.y) == (5, 4)
def test__sorted_list_add(): with operation(): w = WrappedSortedList([5, 1, 2, 3, 4]) assert list(w) == [1, 2, 3, 4, 5] with operation(w) as ww: ww.add(22) assert list(w) == [1, 2, 3, 4, 5] assert list(ww) == [1, 2, 3, 4, 5, 22] with operation(w) as www: www.add(2.5) assert list(w) == [1, 2, 3, 4, 5] assert list(ww) == [1, 2, 3, 4, 5, 22] assert list(www) == [1, 2, 2.5, 3, 4, 5]
def test__basic_reference(c, d): c0 = c with operation(c) as c: c.b = d assert c0.a == 1 assert c0.b is None assert c.a == 1 assert c.b.a == 1 assert c.b.b == None assert d.a == 1 assert d.b == None
def test__pop(LN): with operation(): n = LN([1, 2, 3, 4, 5]) assert n.pop() == 5 assert list(n) == [1, 2, 3, 4] assert n.pop(2) == 3 assert list(n) == [1, 2, 4] assert list(n) == [1, 2, 4] with operation(n) as nn: nn.pop(1) assert list(nn) == [1, 4] assert list(n) == [1, 2, 4] assert list(nn) == [1, 4] assert list(n) == [1, 2, 4]
def test__past_self_append(): with operation(): lst = LinkedList([1]) assert list(lst) == [1] with operation(lst) as lst2: lst2.append(lst) assert list(lst2) == [1, 1] with operation(lst2) as lst3: lst3.append(lst2) assert list(lst3) == [1, 1, 1, 1] with operation(lst) as lst22: lst22[0] = 5 lst22.append(lst3) assert list(lst22) == [5, 1, 1, 1, 1]
def test__reference_mutate_indirect(c, d): c0 = c with operation(c) as c: c.b = d c.b.a = 2 assert c.a == 1 assert c.b.a == 2 assert c.b.b == None assert d.a == 1 assert d.b is None assert c0.a == 1 assert c0.b is None
def test__self_reference(c): c0 = c with operation(c) as c: c.b = c0 c.a = 6 assert c.a == 6 assert c.b.a == 1 assert c.b.b is None assert c0.a == 1 assert c0.b is None
def test__getitem(LN): with operation(): n = LN([1]) assert list(n[i] for i in range(len(n))) == [1] n.append(2) assert list(n[i] for i in range(len(n))) == [1, 2] n.append(3) assert list(n[i] for i in range(len(n))) == [1, 2, 3] n.append(4) assert list(n[i] for i in range(len(n))) == [1, 2, 3, 4] n.append(5) assert list(n[i] for i in range(len(n))) == [1, 2, 3, 4, 5] assert list(n[i] for i in range(len(n))) == [1, 2, 3, 4, 5]
def test__tuple_of_tuples_wrapped(): with operation(): c = C() c.x = () print(c.x) c.x = (4, c.x) print(c.x) c.x = (3, c.x) print(c.x) c.x = (2, c.x) print(c.x) c.x = (1, c.x) print(c.x) assert c.x == (1, (2, (3, (4, ())))) assert c.x == (1, (2, (3, (4, ()))))
def test__reassignment(): with operation(): c = C() c.a = 1 cc = c c = C() c.a = 2 c.x = cc cc = c c = C() c.a = 3 c.x = cc assert c.a == 3 assert c.x.a == 2 assert c.x.x.a == 1 assert c.a == 3 assert c.x.a == 2 assert c.x.x.a == 1
def test__tuple_of_tuples(): with operation(): c = C() c.x = (1, (2, (3, (4, ())))) assert c.x == (1, (2, (3, (4, ()))))
def test__assign_tuple(): with operation(): c = C() c.tpl = () assert c.tpl == ()
def test__basic_confluence(): with operation(): c = C() assert c.a == 1 assert c.b is None
def d(): with operation(): return C()
def fn(): nonlocal l with operation(l) as l: y, z = random.randrange(element_count), random.randrange(element_count) l.add(y) l.discard(z)