def test_breadth_first_one_node(): tree = BinaryTree() a = Node('A') tree.root = a actual = tree.breadth_first() expected = ['A'] assert actual == expected
def test_one_node(): tree = BinaryTree() node1 = Node(5) tree.root = node1 actual = tree.breadth_first() expected = [5] assert actual == expected
def test_ret_in_order(): tree = BinaryTree() tree.root = Node(1) tree.root.left = Node(2) tree.root.right = Node(3) tree.root.left.left = Node(4) tree.root.left.right = Node(5) actual = BinaryTree.breadth_first(tree) expected = [1, 2, 3, 4, 5] assert actual == expected
def test_return_breadth_list(): tree = BinaryTree() node1 = Node(1) node2 = Node(9) node3 = Node(5) node1.left = node2 node1.right = node3 tree.root = node1 actual = tree.breadth_first() expected = [1, 9, 5] assert actual == expected
def test_breadth_first(): grok = BinaryTree() groot = Node('Groot') i = Node('I') am = Node('am') starlord = Node('Iowa') rocket = Node('Trash Panda') grok.root = i grok.root.left = am grok.root.right = groot grok.root.left.left = starlord grok.root.left.right = rocket expected = ['I', 'am', 'Groot', 'Iowa', 'Trash Panda'] assert grok.breadth_first() == expected
def test_breadth_first_even(): tree = BinaryTree() a = Node('A') b = Node('B') c = Node('C') d = Node('D') e = Node('E') f = Node('F') tree.root = a a.left = b a.right = c b.left = d b.right = e c.left = f actual = tree.breadth_first() expected = ['A', 'B', 'C', 'D', 'E', 'F'] assert actual == expected
def test_expect_failure(): tree = BinaryTree() with pytest.raises(ValueError): tree.breadth_first()
def test_binary_breadth(): assert BinaryTree.breadth_first()