def test_top_right(self): tree = TreeSet((2, 1, 4, 3)) tree.discard(2) self.assertEqual(3, tree.root.key) self.assertEqual(0, tree.root.weight) self.assertEqual(2, tree.height()) self.assertTrue(tree.is_valid())
def test_top_left(self): tree = TreeSet((3, 4, 2, 1)) tree.discard(3) self.assertEqual(2, tree.root.key) self.assertEqual(0, tree.root.weight) self.assertEqual(2, tree.height()) self.assertTrue(tree.is_valid())
def test_low_right(self): tree = TreeSet((4, 3, 5, 1, 2)) tree.discard(3) self.assertEqual(-1, tree.root.weight) self.assertEqual(2, tree.root.left.key) self.assertEqual(-1, tree.root.left.weight) self.assertTrue(tree.is_valid())
def test_7(self): for i in itertools.permutations(range(1, 8)): tree = TreeSet(i) if 3 == tree.height(): self.assertEqual(4, tree.root.key) self.assertEqual(0, tree.root.weight) self.assertEqual((1, 2, 3, 4, 5, 6, 7), tuple(tree)) self.assertTrue(tree.is_valid())
def test_3(self): for i in itertools.permutations(range(1, 4)): tree = TreeSet(i) self.assertEqual(2, tree.root.key) self.assertEqual(0, tree.root.weight) self.assertEqual(2, tree.height()) self.assertEqual((1, 2, 3), tuple(tree)) self.assertTrue(tree.is_valid())
def test_rotate_right(self): tree = TreeSet() for _ in (5, 3, 6, 2, 4, 7, 1): tree.add(_) self.assertEqual(-1, tree.root.weight) tree.discard(6) self.assertEqual(3, tree.root.key) self.assertEqual(0, tree.root.weight) self.assertTrue(tree.is_valid())
def test_rotate_left(self): tree = TreeSet() for _ in (3, 2, 5, 1, 4, 6, 7): tree.add(_) self.assertEqual(1, tree.root.weight) tree.discard(1) self.assertEqual(5, tree.root.key) self.assertEqual(0, tree.root.weight) self.assertTrue(tree.is_valid())
def test_low_left(self): tree = TreeSet() for _ in (4, 3, 5, 1, 2): tree.add(_) tree.discard(1) self.assertEqual(-1, tree.root.weight) self.assertEqual(2, tree.root.left.key) self.assertEqual(1, tree.root.left.weight) self.assertTrue(tree.is_valid())