Пример #1
0
def test_diff_repl():
    a = cmod.FileRepr([0, 1, 2])
    b = cmod.FileRepr([0, 3, 2])
    c = list(cmod.Change.from_diff(a, b))
    assert c == [cmod.Delete(1), cmod.Insert(0, [3], 2)]
    a = cmod.FileRepr([0, 1, 2])
    b = cmod.FileRepr([0, 1, 3])
    c = list(cmod.Change.from_diff(a, b))
    assert c == [cmod.Delete(2), cmod.Insert(1, [3], Nodes.end)]
    a = cmod.FileRepr([0, 1, 2])
    b = cmod.FileRepr([3, 1, 2])
    c = list(cmod.Change.from_diff(a, b))
    assert c == [cmod.Delete(0), cmod.Insert(Nodes.start, [3], 1)]
    a = cmod.FileRepr([0, 1, 2])
    b = cmod.FileRepr([0, 3, 4, 2])
    c = list(cmod.Change.from_diff(a, b))
    assert c == [cmod.Delete(1), cmod.Insert(0, [3, 4], 2)]
    a = cmod.FileRepr([0, 1, 2])
    b = cmod.FileRepr([0, 3])
    c = list(cmod.Change.from_diff(a, b))
    assert c == [
        cmod.Delete(1),
        cmod.Delete(2),
        cmod.Insert(0, [3], Nodes.end)
    ]
Пример #2
0
def test_complex_insert():
    a = cmod.FileRepr([0, 1, 2])
    b = cmod.State.from_file(a)
    assert b.nodes == [True, True, True]
    assert b.edges == {(Nodes.start, 0), (0, 1), (1, 2), (2, Nodes.end)}

    c = cmod.Insert(0, [3], 2)
    d = c.apply(b)
    assert d.nodes == [True, True, True, True]
    assert d.edges == {
        (Nodes.start, 0),
        (0, 1),
        (1, 2),
        (0, 3),
        (3, 2),
        (2, Nodes.end),
    }

    c = cmod.Insert(Nodes.start, [3], 2)
    d = c.apply(b)
    assert d.nodes == [True, True, True, True]
    assert d.edges == {
        (Nodes.start, 0),
        (0, 1),
        (1, 2),
        (Nodes.start, 3),
        (3, 2),
        (2, Nodes.end),
    }
Пример #3
0
def test_complex_del():
    a = cmod.FileRepr([0, 1, 2])
    b = cmod.State.from_file(a)
    c = cmod.Insert(Nodes.start, [3], 2)
    d = c.apply(b)
    assert d.nodes == [True, True, True, True]
    assert d.edges == {
        (Nodes.start, 0),
        (0, 1),
        (1, 2),
        (Nodes.start, 3),
        (3, 2),
        (2, Nodes.end),
    }
    e = cmod.Delete(0)
    f = e.apply(d)
    assert f.nodes == [False, True, True, True]
    assert f.edges == {
        (Nodes.start, 0),
        (0, 1),
        (1, 2),
        (Nodes.start, 3),
        (3, 2),
        (2, Nodes.end),
    }
Пример #4
0
def test_diff_add():
    a = cmod.FileReprEdit.from_size(3)
    b = a.insert(0, 1)
    assert b.node_list == [3, 0, 1, 2]
    assert len(b) == 4
    c = list(cmod.Change.from_diff(a, b))
    assert c == [cmod.Insert(Nodes.start, [3], 0)]
    b = a.insert(1, 1)
    assert b.node_list == [0, 3, 1, 2]
    c = list(cmod.Change.from_diff(a, b))
    assert c == [cmod.Insert(0, [3], 1)]
    b = a.insert(2, 2)
    assert b.node_list == [0, 1, 3, 4, 2]
    c = list(cmod.Change.from_diff(a, b))
    assert c == [cmod.Insert(1, [3, 4], 2)]
    b = a.insert(3, 2)
    assert b.node_list == [0, 1, 2, 3, 4]
    c = list(cmod.Change.from_diff(a, b))
    assert c == [cmod.Insert(2, [3, 4], Nodes.end)]
Пример #5
0
def test_insert_with_hole():
    a = cmod.FileRepr([0, 2, 3])
    b = cmod.State.from_file(a)
    assert b.nodes == [True, False, True, True]
    assert b.edges == {(Nodes.start, 0), (0, 2), (2, 3), (3, Nodes.end)}

    c = cmod.Insert(1, [3], 2)
    with pytest.raises(AssertionError):
        d = c.apply(b)

    # TODO This is inconsistent. Fix it with a consistency check. I don't want to blow
    # up the complexity for this
    c = cmod.Insert(1, [4], 2)
    d = c.apply(b)
    assert d.nodes == [True, False, True, True, True]
    assert d.edges == {
        (Nodes.start, 0),
        (0, 2),
        (1, 4),
        (4, 2),
        (2, 3),
        (3, Nodes.end),
    }
Пример #6
0
def test_collect_problem():
    a = cmod.FileReprEdit.from_size(2)
    b = cmod.State.from_file(a)
    c = cmod.Delete(0).apply(b)
    assert c.nodes == [False, True]
    d = cmod.Insert(Nodes.start, [2], 1).apply(c)
    assert d.edges == {
        (Nodes.start, 0),
        (0, 1),
        (1, Nodes.end),
        (Nodes.start, 2),
        (2, 1),
    }
    e = cmod.collect_deleted_nodes(d.edges, d.nodes)
Пример #7
0
def test_collect():
    a = cmod.FileRepr([0, 1, 2])
    b = cmod.State.from_file(a)
    c = cmod.Delete(1)
    d = c.apply(b)
    e = cmod.collect_deleted_nodes(d.edges, d.nodes)
    assert e == {(Nodes.start, 0), (0, 2), (2, Nodes.end)}

    c = cmod.Insert(0, [3], 2)
    d = c.apply(b)
    e = cmod.Delete(2)
    f = e.apply(d)
    g = cmod.collect_deleted_nodes(f.edges, f.nodes)
    assert g == {(Nodes.start, 0), (0, 1), (0, 3), (1, Nodes.end),
                 (3, Nodes.end)}