def test_simple(self): node = AVLNode(3) node.weight = -2 node.left = AVLNode(2) node.left.weight = -1 node.left.left = AVLNode(1) new = node.rotate_right() self.assertEqual(2, new.key) self.assertEqual(0, new.weight) self.assertEqual(0, node.weight) self.assertTrue(new.is_valid())
def test_normal(self): node = AVLNode(4) node.weight = -1 node.left = AVLNode(2) node.right = AVLNode(5) node.left.left = AVLNode(1) node.left.right = AVLNode(3) new = node.rotate_right() self.assertEqual(2, new.key) self.assertEqual(node, new.right) self.assertEqual(1, new.weight) self.assertEqual(0, node.weight) self.assertTrue(new.is_valid())
def test_left(self): node = AVLNode(2) node.left = AVLNode(1) node.weight = 1 node.right = AVLNode(4) node.right.weight = -1 node.right.left = AVLNode(3) new = node.rotate_left() self.assertEqual(4, new.key) self.assertEqual(node, new.left) self.assertEqual(0, node.weight) self.assertEqual(-2, new.weight) self.assertFalse(new.is_valid())
def test_right(self): node = AVLNode(2) node.left = AVLNode(1) node.weight = 1 node.right = AVLNode(3) node.right.weight = 1 node.right.right = AVLNode(4) new = node.rotate_left() self.assertEqual(3, new.key) self.assertEqual(node, new.left) self.assertEqual(None, node.right) self.assertEqual(-1, node.weight) self.assertEqual(-1, new.weight) self.assertTrue(new.is_valid())