Ejemplo n.º 1
0
 def test_tree_with_many_items(self):
     preorder = ["a", "i", "x", "f", "r"]
     inorder = ["i", "a", "f", "x", "r"]
     expected = {
         "v": "a",
         "l": {
             "v": "i",
             "l": {},
             "r": {}
         },
         "r": {
             "v": "x",
             "l": {
                 "v": "f",
                 "l": {},
                 "r": {}
             },
             "r": {
                 "v": "r",
                 "l": {},
                 "r": {}
             }
         }
     }
     self.assertEqual(tree_from_traversals(preorder, inorder), expected)
Ejemplo n.º 2
0
 def test_tree_with_one_item(self):
     preorder = ["a"]
     inorder = ["a"]
     expected = {
         "v": "a",
         "l": {},
         "r": {}
     }
     self.assertEqual(tree_from_traversals(preorder, inorder), expected)
Ejemplo n.º 3
0
 def test_empty_tree(self):
     preorder = []
     inorder = []
     expected = {}
     self.assertEqual(tree_from_traversals(preorder, inorder), expected)
Ejemplo n.º 4
0
 def test_reject_traverals_with_repeated_items(self):
     preorder = ["a", "b", "a"]
     inorder = ["b", "a", "a"]
     with self.assertRaisesWithMessage(ValueError):
         tree_from_traversals(preorder, inorder)
Ejemplo n.º 5
0
 def test_reject_inconsistent_traversals_of_same_length(self):
     preorder = ["x", "y", "z"]
     inorder = ["a", "b", "c"]
     with self.assertRaisesWithMessage(ValueError):
         tree_from_traversals(preorder, inorder)
Ejemplo n.º 6
0
 def test_reject_traverals_of_different_length(self):
     preorder = ["a", "b"]
     inorder = ["b", "a", "r"]
     with self.assertRaisesWithMessage(ValueError):
         tree_from_traversals(preorder, inorder)