Exemplo n.º 1
0
 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())
Exemplo n.º 2
0
 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())
Exemplo n.º 3
0
 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())
Exemplo n.º 4
0
 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())
Exemplo n.º 5
0
 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())
Exemplo n.º 6
0
 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())