def test_add_four_nodes(): tree = BinaryTree() tree.add('apples') tree.add('bananas') tree.add('cucumbers') tree.add('dates') assert tree._root.value == 'apples' assert tree._root.left.value == 'bananas' assert tree._root.right.value == 'cucumbers' assert tree._root.left.left.value == 'dates' assert tree._root.left.right == None
def test_add_four(): new_tree = BinaryTree() new_tree.add(2) assert new_tree.root.value == 2 new_tree.add(7) assert new_tree.root.left.value == 7 new_tree.add(5) assert new_tree.root.right.value == 5 new_tree.add(2) assert new_tree.root.left.left.value == 2 assert new_tree.root.left.right == None
def test_breadth_first(): tree = BinaryTree() tree.add(1) tree.add(2) tree.add(3) tree.add(4) tree.add(5) expected = [1, 2, 3, 4, 5] actual = tree.breadth_first() assert actual == expected
def test_add_three_to_tree(): new_tree = BinaryTree() new_tree.add(2) assert new_tree.root.value == 2 new_tree.add(7) assert new_tree.root.left.value == 7 new_tree.add(5) assert new_tree.root.right.value == 5
def test_breadth_first(): tree = BinaryTree() tree.add(1) tree.add(2) tree.add(3) tree.add(4) tree.add(5) assert breadth_first(tree._root) == [[1], [2, 3], [4,5]]
def test_breadth_four(): new_tree, expected = BinaryTree(), [2, 7, 5, 2] new_tree.add(2) new_tree.add(7) new_tree.add(5) new_tree.add(2) assert new_tree.breadth_first() == expected
def test_add_one_to_tree(): new_tree = BinaryTree() new_tree.add(2) assert new_tree.root.value == 2
def test_breadth_first_nine(): new_tree = BinaryTree() expected = [2, 7, 5, 2, 6, 9, 5, 11, 4] new_tree.add(2) new_tree.add(7) new_tree.add(5) new_tree.add(2) new_tree.add(6) new_tree.add(9) new_tree.add(5) new_tree.add(11) new_tree.add(4) assert new_tree.breadth_first() == expected
def test_breadth_first_empty(): tree = BinaryTree() expected = [] actual = tree.breadth_first() assert actual == expected
def test_binery_tree(): assert BinaryTree()
def test_add_one_member(): tree = BinaryTree() tree.add('james_bond') assert tree._root.value == 'james_bond'
def test_negative_max_value(): new_tree = BinaryTree() expected = -2 new_tree.add(-2) new_tree.add(-3) new_tree.add(-7) new_tree.add(-5) new_tree.add(-2) new_tree.add(-6) new_tree.add(-9) new_tree.add(-5) new_tree.add(-11) new_tree.add(-4) assert new_tree.find_maximum_value() == expected
def test_maximum_value(): new_tree = BinaryTree() expected = 11 new_tree.add(2) new_tree.add(7) new_tree.add(5) new_tree.add(2) new_tree.add(6) new_tree.add(9) new_tree.add(5) new_tree.add(11) new_tree.add(4) assert new_tree.find_maximum_value() == expected