def test_postorder_iteration(): nt.ok_( list(val_iter(ipostorder(REF_TREE))) == [111, 112, 11, 12111, 12112, 1211, 121, 122, 12, 0]) nt.ok_(list(val_iter(ipostorder(REF_TREE.children[0]))) == [111, 112, 11]) nt.ok_( list(val_iter(ipostorder(REF_TREE.children[1]))) == [12111, 12112, 1211, 121, 122, 12])
def test_deep_iteration(): root = t = Tree(0) for i in range(1, sys.getrecursionlimit() + 2): child = Tree(i) t.add_child(child) t = child list(ipreorder(root)) list(ipostorder(root)) list(iupstream(t))
def _check_trees(trees): for t in trees: nt.ok_(len(list(tree.ileaf(t))) == 11) nt.ok_(len(list(tree.iforking_point(t))) == 10) nt.ok_(len(list(tree.ipreorder(t))) == 211) nt.ok_(len(list(tree.ipostorder(t))) == 211) nt.ok_(len(list(tree.isegment(t))) == 210) leaves = [l for l in tree.ileaf(t)] # path length from each leaf to root node. branch_order = [21, 31, 41, 51, 61, 71, 81, 91, 101, 111, 111] for i, l in enumerate(leaves): nt.ok_(len(list(tree.iupstream(l))) == branch_order[i])
def test_postorder_iteration(): nt.ok_(list(val_iter(ipostorder(REF_TREE))) == [111, 112, 11, 12111, 12112, 1211, 121, 122, 12, 0]) nt.ok_(list(val_iter(ipostorder(REF_TREE.children[0]))) == [111, 112, 11]) nt.ok_(list(val_iter(ipostorder(REF_TREE.children[1]))) == [12111, 12112, 1211, 121, 122, 12])