def test_rightonly(self): """Test a tree with only a right side.""" s = "42[-100(12(10)[11(17)])[32]]" root = mfs(s, BTN) inord = root.inordertraversal() preord = root.preordertraversal() postord = root.postordertraversal() root2 = mft(BTN, inord, postorder=postord) inord2 = root2.inordertraversal() preord2 = root2.preordertraversal() postord2 = root2.postordertraversal() self.assertEqual(inord, inord2) self.assertEqual(preord, preord2) self.assertEqual(postord, postord2)
def test_bothchildren(self): """Test a tree which has both children.""" s = "42(-100(12)[28])[100[111]]" root = mfs(s, BTN) inord = root.inordertraversal() preord = root.preordertraversal() postord = root.postordertraversal() root2 = mft(BTN, inord, preorder=preord) inord2 = root2.inordertraversal() preord2 = root2.preordertraversal() postord2 = root2.postordertraversal() self.assertEqual(inord, inord2) self.assertEqual(preord, preord2) self.assertEqual(postord, postord2)
def test_singlecase(self): """Test a tree with just a root.""" s = "42" root = mfs(s, BTN) inord = root.inordertraversal() preord = root.preordertraversal() postord = root.postordertraversal() root2 = mft(BTN, inord, postorder=postord) inord2 = root2.inordertraversal() preord2 = root2.preordertraversal() postord2 = root2.postordertraversal() self.assertEqual(inord, inord2) self.assertEqual(preord, preord2) self.assertEqual(postord, postord2)
def test_leftonly(self): """Test a tree with only a left side.""" s = "42(-100(12(10)[11[17]])[23])" root = mfs(s, BTN) inord = root.inordertraversal() preord = root.preordertraversal() postord = root.postordertraversal() root2 = mft(BTN, inord, preorder=preord) inord2 = root2.inordertraversal() preord2 = root2.preordertraversal() postord2 = root2.postordertraversal() self.assertEqual(inord, inord2) self.assertEqual(preord, preord2) self.assertEqual(postord, postord2)