Пример #1
0
def test_wrong_removal():
    A = (
        Node('a')
          .addkid(Node('b'))
          .addkid(Node('c'))
    )
    B = Node("a")
    dist = simple_distance(A, B)
    assert dist == 2
Пример #2
0
def test_wrong_index_regression():
    A = Node('r')
    B = (
        Node("a")
          .addkid(Node("b")
            .addkid(Node("c"))
            .addkid(Node("d"))
          )
          .addkid(Node("e")
            .addkid(Node("f"))
            .addkid(Node("g"))
          )
     )
    def insert(n):
        return ord(n.label[0])
    def remove(n):
        return ord(n.label[0])
    def update(a,b):
        return 10000*strdist(a.label, b.label)
    dist = distance(A, B,
        get_children=(lambda n: n.children),
        insert_cost=insert,
        remove_cost=remove,
        update_cost=update,
    )
    assert dist == 814
Пример #3
0
def test_incorrect_behavior_regression():
    A = (
     Node("a")
       .addkid(Node("b")
         .addkid(Node("x"))
         .addkid(Node("y"))
       )
     )
    B = (
     Node("a")
       .addkid(Node("x"))
       .addkid(Node("b")
         .addkid(Node("y"))
       )
     )
    dist = simple_distance(A, B)
    print(dist)
    sub_dist = A - B
    assert dist == 2
    assert dist == sub_dist
Пример #4
0
def test_simplelabelchange():
    A = (Node("f").addkid(
        Node("a").addkid(Node("h")).addkid(Node("c").addkid(
            Node("l")))).addkid(Node("e")))
    B = (Node("f").addkid(
        Node("a").addkid(Node("d")).addkid(Node("r").addkid(
            Node("b")))).addkid(Node("e")))
    dist = simple_distance(A, B)
    print(dist)
    assert dist == 3
Пример #5
0
def test_paper_tree():
    A = (Node("f").addkid(
        Node("d").addkid(Node("a")).addkid(Node("c").addkid(
            Node("b")))).addkid(Node("e")))
    B = (Node("f").addkid(
        Node("c").addkid(Node("d").addkid(Node("a")).addkid(
            Node("b")))).addkid(Node("e")))
    #print A
    #print
    #print B
    dist = simple_distance(A, B)
    assert dist == 2
Пример #6
0
def test_empty_tree_distance():
    assert simple_distance(Node(''), Node('')) == 0
    assert simple_distance(Node('a'), Node('')) == 1
    assert simple_distance(Node(''), Node('b')) == 1