def setUp(self): self.root = TreeNode(0) self.node1 = TreeNode(1) self.node2 = TreeNode(2) self.node3 = TreeNode(3) self.node4 = TreeNode(4) self.node5 = TreeNode(5) self.node5 = TreeNode(5) self.node6 = TreeNode(6) self.root.left = self.node1 self.root.right = self.node2 self.node1.left = self.node3 self.node1.right = self.node4 self.node2.left = self.node5 self.node2.right = self.node6 s = Solution() s.mylist = [] self.correct_answer = s.postorder(self.root)
def test_1_null_2_returns_2_1(self): btree = [TreeNode(1), TreeNode(2)] btree[0].right = btree[1] self.assertEqual(Solution().postorder_traversal(btree[0]), [2, 1])
def test_1_null_2_3_returns_3_2_1(self): btree = list(TreeNode(i) for i in range(1, 4)) btree[0].right = btree[1] btree[1].left = btree[2] self.assertEqual(Solution().postorder_traversal(btree[0]), [3, 2, 1])
def test_1_returns_1(self): self.assertEqual(Solution().postorder_traversal(TreeNode(1)), [1])
def test_postorder_non_recusive2(self): s = Solution() mylist = s.postorder_non_recursive2(self.root) self.assertListEqual(mylist, self.correct_answer)
def test_postorder(self): s = Solution() mylist = s.postorder(self.root) self.assertEqual(mylist, self.correct_answer)