Exemplo n.º 1
0
    def test_postorder_single_node(self):
        bst = BinarySearchTree(data=5)

        stdout_org = sys.stdout
        stdout_mock = StdOutMock()
        try:
            sys.stdout = stdout_mock
            bst.postorder(bst.root)
        finally:
            sys.stdout = stdout_org

        self.assertEqual(str(stdout_mock), '5')
Exemplo n.º 2
0
    def test_postorder(self):
        bst = BinarySearchTree(data=5)
        bst.insert(3)
        bst.insert(7)
        bst.insert(1)
        bst.insert(2)
        bst.insert(9)
        bst.insert(6)

        stdout_org = sys.stdout
        stdout_mock = StdOutMock()
        try:
            sys.stdout = stdout_mock
            bst.postorder(bst.root)
        finally:
            sys.stdout = stdout_org

        self.assertEqual(str(stdout_mock), '2136975')