예제 #1
0
파일: test.py 프로젝트: dacut/python-algae
    def test_adjacents(self):
        root = RedBlackTreeNode(5, 5)
        self.assertIsNone(root.predecessor)
        self.assertIsNone(root.successor)
        
        root.left = RedBlackTreeNode(2, 2)
        root.right = RedBlackTreeNode(8, 8)
        self.assertIs(root.predecessor, root.left)
        self.assertIs(root.successor, root.right)
        
        root.left.right = RedBlackTreeNode(3, 3)
        root.right.left = RedBlackTreeNode(7, 7)
        self.assertIs(root.predecessor, root.left.right)
        self.assertIs(root.successor, root.right.left)

        root.left.right.right = RedBlackTreeNode(4, 4)
        root.right.left.left = RedBlackTreeNode(6, 6)
        self.assertIs(root.predecessor, root.left.right.right)
        self.assertIs(root.successor, root.right.left.left)
        return
예제 #2
0
파일: test.py 프로젝트: dacut/python-algae
    def test_black_height(self):
        root = RedBlackTreeNode(5, 5)
        left = RedBlackTreeNode(0, 0)
        right = RedBlackTreeNode(10, 10)
        root.red = left.red = right.red = False
        root.left = left
        root.right = right
        left.parent = right.parent = root

        self.assertEqual(root.black_height, 2)
        left.red = right.red = True
        self.assertEqual(root.black_height, 1)
        right.red = False
        try:
            root.black_height
            self.fail("Expected AssertionError")
        except AssertionError:
            pass

        self.assertEquals(repr(root),
                          "RedBlackTreeNode(key=5, value=5, red=False)")
        return