Beispiel #1
0
def test_find_max_root_is_max():
  tree = BinarySearchTree()
  tree.root = Node(23)
  tree.root.left = Node(19)
  tree.root.right = Node(7)
  tree.root.left.left = Node(5)
  tree.root.left.right = Node(8)

  assert tree.find_max_val(tree.root) == 23
Beispiel #2
0
def test_add_a_left_child_and_righy_child_to_a_single_root_node():
  binary_tree = BinaryTree
  node1 = Node('A')
  node2 = Node('B')
  node3 = Node('C')
  binary_tree.root=node1
  node1.left = node2
  node1.right = node3
  assert node1.left.value == 'B'
  assert node1.right.value == 'C'
Beispiel #3
0
def test_return_maximum_value():
  binary_tree=BinaryTree()
  node1 = Node(1)
  node2 = Node(2)
  node3 = Node(8)
  node4 = Node(84)
  node5 = Node(66)
  node6 = Node(14)
  binary_tree.root=node1
  node1.left = node2
  node1.right = node3
  node2.left = node4
  node2.right = node5
  node3.left = node6
  assert binary_tree.max_value()==84
Beispiel #4
0
def test_instantiate_a_tree_with_a_single_root_node():
  binary_tree = BinaryTree
  node1 = Node('A')
  binary_tree.root=node1
  assert binary_tree.root.value == 'A'
Beispiel #5
0
def test_return_a_collection_from_a_postorder_traversal():
  binary_tree=BinaryTree()
  node1 = Node('A')
  node2 = Node('B')
  node3 = Node('C')
  node4 = Node('D')
  node5 = Node('E')
  node6 = Node('F')
  binary_tree.root=node1
  node1.left = node2
  node1.right = node3
  node2.left = node4
  node2.right = node5
  node3.left = node6
  post_order = binary_tree.post_order()
  assert post_order == ['D', 'E', 'B', 'F', 'C', 'A']
    bst.add(3)
    bst.add(-1)
    bst.add(50)
    bst.add(34)
    assert bst.contains(10) == True
    assert bst.post_order() == [-1, 3, 8, 34, 50, 23, 17, 10]
    assert bst.max_value() == 50


def test_contains():
    bin_tree = Binary_Search_Tree()
    bin_tree.add(10)
    assert bin_tree.contains(10) == True
    assert bin_tree.max_value() == 10


a = Node("A")
b = Node("B")
c = Node("C")
d = Node("D")
e = Node("E")
f = Node("F")

tree = Binary_Tree()
a.left = b
a.right = c
tree.root = a
b.left = d
b.right = e
c.left = f