def test_search(self): tree = BSTree(5) for kid in self.childs: tree.insert(kid) for kid in self.childs: self.assertTrue(tree.search(tree.root,kid)) self.assertFalse(tree.search(tree.root,500)) self.assertFalse(tree.search(tree.root,-1)) self.assertFalse(tree.search(tree.root,'abc')) self.assertFalse(tree.search(tree.root,None))
def test_insert_left_child(self): tree = BSTree(5) tree.insert(3) self.assertIsInstance(tree.root.left, Node) self.assertEqual(tree.root.left.data,3) self.assertIsNone(tree.root.left.left)
def test_insert_left_grandchild(self): tree = BSTree(5) tree.insert(3) tree.insert(1) self.assertEqual(tree.root.left.left.data,1) self.assertIsNone(tree.root.left.right)
def makeTree(self): tree = BSTree(5) for kid in self.childs: tree.insert(kid) return tree