def test_inorder_non_recusive(self):
     s = Solution()
     mylist = s.inorder_non_recursive(self.root)
     print "\n---------------------------------"
     print "Inorder Non-recursive"
     print mylist
     print "---------------------------------"
 def test_inorder(self):
     s = Solution()
     mylist = s.inorder(self.root)
     print "\n---------------------------------"
     print "Inorder"
     print mylist
     print "---------------------------------"
 def test_inorder_tail_recursive(self):
     s = Solution()
     mylist = s.inorder_tail_recursive(self.root)
     print "\n---------------------------------"
     print "Inorder tail recursive"
     print mylist
     print "---------------------------------"
 def test_preorder_non_recusive2(self):
     print "\n---------------------------------"
     print "inorder Non-recursive2"
     s = Solution()
     mylist = s.inorder_non_recursive2(self.root)
     self.assertEqual(mylist, self.correct_answer)
     print mylist
     print "---------------------------------"
    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.inorder(self.root)
Example #6
0
 def test_1_2_returns_2_1(self):
     btree = [TreeNode(i) for i in range(1, 3)]
     btree[0].left = btree[1]
     self.assertEqual(Solution().inorder_traversal(btree[0]), [2, 1])
Example #7
0
 def test_1_null_2_returns_1_2(self):
     btree = [TreeNode(1), TreeNode(2)]
     btree[0].right = btree[1]
     self.assertEqual(Solution().inorder_traversal(btree[0]), [1, 2])
Example #8
0
 def test_1_null_2_3_returns_1_3_2(self):
     btree = list(TreeNode(i) for i in [1, 2, 3])
     btree[0].right = btree[1]
     btree[1].left = btree[-1]
     self.assertEqual(Solution().inorder_traversal(btree[0]), [1, 3, 2])
Example #9
0
 def test_1_returns_1(self):
     self.assertEqual(Solution().inorder_traversal(TreeNode(1)), [1])
Example #10
0
 def test_inorder(self):
     solution = Solution()
     tree = TreeNode(1, None, TreeNode(2, TreeNode(3)))