def test_binary_search_insert(self): # 5 # / \ # 3 8 # / \ / # 2 4 6 root = BinarySearchNode(5) self.assertTrue(test_binary_node(root, 5, None, None, None)) root.insert(3) self.assertTrue(test_binary_node(root, 5, 3, None, None)) self.assertTrue(test_binary_node(root[3], 3, None, None, 5)) root.insert(8) self.assertTrue(test_binary_node(root, 5, 3, 8, None)) self.assertTrue(test_binary_node(root[3], 3, None, None, 5)) self.assertTrue(test_binary_node(root[8], 8, None, None, 5)) root.insert(4) self.assertTrue(test_binary_node(root, 5, 3, 8, None)) self.assertTrue(test_binary_node(root[3], 3, None, 4, 5)) self.assertTrue(test_binary_node(root[8], 8, None, None, 5)) self.assertTrue(test_binary_node(root[4], 4, None, None, 3)) root.insert(2) self.assertTrue(test_binary_node(root, 5, 3, 8, None)) self.assertTrue(test_binary_node(root[3], 3, 2, 4, 5)) self.assertTrue(test_binary_node(root[8], 8, None, None, 5)) self.assertTrue(test_binary_node(root[2], 2, None, None, 3)) self.assertTrue(test_binary_node(root[4], 4, None, None, 3)) root.insert(6) self.assertTrue(test_binary_node(root, 5, 3, 8, None)) self.assertTrue(test_binary_node(root[3], 3, 2, 4, 5)) self.assertTrue(test_binary_node(root[8], 8, 6, None, 5)) self.assertTrue(test_binary_node(root[2], 2, None, None, 3)) self.assertTrue(test_binary_node(root[4], 4, None, None, 3)) self.assertTrue(test_binary_node(root[6], 6, None, None, 8))
def binary_search_tree(): # 5 # / \ # 3 8 # / \ / # 2 4 6 # / \ # 1 7 node5 = BinarySearchNode(5) node5.insert(3) node5.insert(8) node5.insert(4) node5.insert(2) node5.insert(6) node5.insert(1) node5.insert(7) return node5