Exemple #1
0
def test_tree_to_nodes():
    Node.reset()
    tree = {1:[2]}
    ntree = tree_to_nodes(tree, 1)
    assert ntree.id == 1
    assert len(ntree.children) == 1
    assert ntree.children[0].id == 2
    Node.reset()
    tree = {1: [2, 3], 2: [4], 4: [5], 5: [6, 7], 3: [8, 9, 10]}
    ntree = tree_to_nodes(tree, 1)
Exemple #2
0
def test_nodes_to_tree():
    Node.reset()
    tree = {1: [2, 3], 2: [4], 4: [5], 5: [6, 7], 3: [8, 9, 10]}
    root = 1
    ntree = tree_to_nodes(tree, root)
    nntree, nnroot =  nodes_to_tree(ntree)
    assert nntree == tree
    assert nnroot == root
Exemple #3
0
def test_various_manipulations():
    Node.reset()
    my_tree = {1: [2]}
    ntree = tree_to_nodes(my_tree, 1)
    assert set(Node.instances.keys()) == {1, 2}
    nttree, new_root = nodes_to_tree(ntree)
    assert len(nttree) == 1
    assert set(Node.instances.keys()) == {1, 2}
    assert nttree == my_tree
Exemple #4
0
from function import tree_tidy, Node, tree_to_nodes
tree = {1: [2, 3], 2: [4], 4: [5], 5: [6, 7], 3: [8, 9, 10]}
ntree = tree_to_nodes(tree, 1)
print("\n\n--- Raw ---", ntree.pretty(), sep='\n')
ntree.tidy()
print("\n\n--- Tidy ---", ntree.pretty(), sep='\n')

Node.reset()
ntree = tree_to_nodes({1: [2]}, 1)
print("\n\n--- Raw problem case ---", ntree.pretty(), sep='\n')
ntree.tidy()
print("\n\n--- Tidied problem case ---", ntree.pretty(), sep='\n')
Exemple #5
0
def test_degenerate_case():
    tree = tree_to_nodes({1: [2]}, 1)
    new_tree = tree.tidied()
    assert new_tree.id  == 2
    assert len(new_tree.iness) == 1
    assert new_tree.iness[0].id ==1