Exemplo n.º 1
0
 def test_false(self):
     bt = BinaryTree()
     for x in [4, 2, 6, 8, 1, 5]:
         bt.add(x)
     self.assertEqual(bt.contains(3), False)
     self.assertEqual(bt.contains(7), False)
     self.assertEqual(bt.contains(9), False)
Exemplo n.º 2
0
 def test_true(self):
     bt = BinaryTree()
     for x in [4, 2, 6, 8, 1, 5]:
         bt.add(x)
     self.assertEqual(bt.contains(4), True)
     self.assertEqual(bt.contains(5), True)
     self.assertEqual(bt.contains(6), True)
     self.assertEqual(bt.contains(8), True)
def run_tests():
	print("Running tests for Binary Search Tree")
	bst = BinaryTree()
	bst.insert(10)
	bst.insert(5)
	bst.insert(15)
	bst.insert(2)
	bst.insert(20)
	bst.insert(12)
	bst.insert(7)
	print(bst)

	assert(bst.contains(10))
	assert(bst.contains(20))
	assert(not bst.contains(50))
	assert(not bst.contains(3))
	assert(bst.contains(2))
	assert(not bst.contains(1))

	print("All tests passed!")
Exemplo n.º 4
0
def main():
    my_binary_tree = BinaryTree('A')
    print(my_binary_tree)
    print(repr(my_binary_tree))

    my_binary_tree.add_val_l('B')
    print(my_binary_tree)
    print(repr(my_binary_tree))

    my_binary_tree.add_val_l('C')
    print(my_binary_tree)
    print(repr(my_binary_tree))

    my_binary_tree.add_val_l('D')
    print(my_binary_tree)
    print(repr(my_binary_tree))

    my_binary_tree.add_val_r('E')
    print(my_binary_tree)
    print(repr(my_binary_tree))

    my_binary_tree.add_val_r('F')
    print(my_binary_tree)
    print(repr(my_binary_tree))

    if my_binary_tree.contains('E'):
        # This should be the case:
        print("This tree contains 'E'")
    else:
        print("This tree does not contain 'E'")

    if my_binary_tree.contains('J'):
        print("This tree contains 'J'")
    else:
        # This should be the case:
        print("This tree does not contain 'J'")
Exemplo n.º 5
0
 def test_empty(self):
     bt = BinaryTree()
     self.assertEqual(bt.contains(3), False)