def test_add(self): tree = Tree() root = tree.add() self.assertEqual(tree.add(), root.left) self.assertEqual(tree.size(), 2) self.assertEqual(tree.max_depth(), 2) self.assertEqual(tree.add(), root.right) self.assertEqual(tree.size(), 3) self.assertEqual(tree.max_depth(), 2)
def test_root(self): tree = Tree() root = tree.add() self.assertEqual(root, tree.root) self.assertEqual(tree.size(), 1) self.assertEqual(tree.max_depth(), 1) self.assertEqual(list((n.node for n in tree)), [root]) self.assertEqual(list((n.node for n in tree.in_order())), [root]) self.assertFalse(root.left) self.assertFalse(root.right)
def test_empty_tree(self): tree = Tree() self.assertEqual(tree.size(), 0) self.assertEqual(tree.max_depth(), 0) self.assertEqual(list(tree), [])