def test_wrong_removal(): A = ( Node('a') .addkid(Node('b')) .addkid(Node('c')) ) B = Node("a") dist = simple_distance(A, B) assert dist == 2
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
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
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
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
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