Ejemplo n.º 1
0
 def test_errors_if_target_does_not_exist_in_large_tree(self):
     tree = Tree('parent', [
         Tree('x', [Tree('kid-0'), Tree('kid-1')]),
         Tree('sibling-0'),
         Tree('sibling-1')
     ])
     with self.assertRaisesWithMessage(ValueError):
         tree.from_pov('nonexistent')
Ejemplo n.º 2
0
 def test_errors_if_target_does_not_exist_in_large_tree(self):
     tree = Tree('parent', [
         Tree('x', [
             Tree('kid-0'),
             Tree('kid-1')
         ]),
         Tree('sibling-0'),
         Tree('sibling-1')
     ])
     with self.assertRaisesWithMessage(ValueError):
         tree.from_pov('nonexistent')
Ejemplo n.º 3
0
 def test_errors_if_target_does_not_exist_in_a_large_tree(self):
     tree = Tree(
         "parent",
         [
             Tree("x", [Tree("kid-0"), Tree("kid-1")]),
             Tree("sibling-0"),
             Tree("sibling-1"),
         ],
     )
     with self.assertRaisesWithMessage(ValueError):
         tree.from_pov("nonexistent")
Ejemplo n.º 4
0
 def test_errors_if_target_does_not_exist_in_a_large_tree(self):
     tree = Tree(
         "parent",
         [
             Tree("x", [Tree("kid-0"), Tree("kid-1")]),
             Tree("sibling-0"),
             Tree("sibling-1"),
         ],
     )
     with self.assertRaises(ValueError) as err:
         tree.from_pov("nonexistent")
     self.assertEqual(type(err.exception), ValueError)
     self.assertEqual(err.exception.args[0], "Tree could not be reoriented")
Ejemplo n.º 5
0
 def test_can_reroot_a_complex_tree_with_cousins(self):
     tree = Tree(
         "grandparent",
         [
             Tree(
                 "parent",
                 [
                     Tree("x", [Tree("kid-0"), Tree("kid-1")]),
                     Tree("sibling-0"),
                     Tree("sibling-1"),
                 ],
             ),
             Tree("uncle", [Tree("cousin-0"), Tree("cousin-1")]),
         ],
     )
     expected = Tree(
         "x",
         [
             Tree("kid-1"),
             Tree("kid-0"),
             Tree(
                 "parent",
                 [
                     Tree("sibling-0"),
                     Tree("sibling-1"),
                     Tree(
                         "grandparent",
                         [Tree("uncle", [Tree("cousin-0"), Tree("cousin-1")])],
                     ),
                 ],
             ),
         ],
     )
     self.assertTreeEquals(tree.from_pov("x"), expected)
Ejemplo n.º 6
0
 def test_can_reroot_complex_tree_with_cousins(self):
     tree = Tree('grandparent', [
         Tree('parent', [
             Tree('x', [
                 Tree('kid-0'),
                 Tree('kid-1')
             ]),
             Tree('sibling-0'),
             Tree('sibling-1')
         ]),
         Tree('uncle', [
             Tree('cousin-0'),
             Tree('cousin-1')
         ])
     ])
     expected = Tree('x', [
         Tree('kid-0'),
         Tree('kid-1'),
         Tree('parent', [
             Tree('sibling-0'),
             Tree('sibling-1'),
             Tree('grandparent', [
                 Tree('uncle', [
                     Tree('cousin-0'),
                     Tree('cousin-1')
                 ])
             ])
         ])
     ])
     self.assertTreeEquals(tree.from_pov('x'), expected)
Ejemplo n.º 7
0
 def test_can_reroot_a_tree_with_new_root_deeply_nested(self):
     tree = Tree('level-0', [
         Tree('level-1', [Tree('level-2', [Tree('level-3', [Tree('x')])])])
     ])
     expected = Tree('x', [
         Tree('level-3',
              [Tree('level-2', [Tree('level-1', [Tree('level-0')])])])
     ])
     self.assertTreeEquals(tree.from_pov('x'), expected)
Ejemplo n.º 8
0
 def test_can_reroot_a_tree_with_new_root_deeply_nested_in_tree(self):
     tree = Tree(
         "level-0",
         [Tree("level-1", [Tree("level-2", [Tree("level-3", [Tree("x")])])])],
     )
     expected = Tree(
         "x",
         [Tree("level-3", [Tree("level-2", [Tree("level-1", [Tree("level-0")])])])],
     )
     self.assertTreeEquals(tree.from_pov("x"), expected)
Ejemplo n.º 9
0
 def test_can_reroot_tree_with_parent_and_one_sibling(self):
     tree = Tree('parent', [
         Tree('x'),
         Tree('sibling')
     ])
     expected = Tree('x', [
         Tree('parent', [
             Tree('sibling')
         ])
     ])
     self.assertTreeEquals(tree.from_pov('x'), expected)
Ejemplo n.º 10
0
 def test_moves_children_of_new_root_to_same_level_as_former_parent(self):
     tree = Tree('parent', [
         Tree('x', [
             Tree('kid-0'),
             Tree('kid-1')
         ])
     ])
     expected = Tree('x', [
         Tree('parent'),
         Tree('kid-0'),
         Tree('kid-1')
     ])
     self.assertTreeEquals(tree.from_pov('x'), expected)
Ejemplo n.º 11
0
 def test_can_reroot_a_tree_with_new_root_deeply_nested(self):
     tree = Tree('level-0', [
         Tree('level-1', [
             Tree('level-2', [
                 Tree('level-3', [
                     Tree('x')
                 ])
             ])
         ])
     ])
     expected = Tree('x', [
         Tree('level-3', [
             Tree('level-2', [
                 Tree('level-1', [
                     Tree('level-0')
                 ])
             ])
         ])
     ])
     self.assertTreeEquals(tree.from_pov('x'), expected)
Ejemplo n.º 12
0
 def test_can_reroot_complex_tree_with_cousins(self):
     tree = Tree('grandparent', [
         Tree('parent', [
             Tree('x', [Tree('kid-0'), Tree('kid-1')]),
             Tree('sibling-0'),
             Tree('sibling-1')
         ]),
         Tree('uncle',
              [Tree('cousin-0'), Tree('cousin-1')])
     ])
     expected = Tree('x', [
         Tree('kid-0'),
         Tree('kid-1'),
         Tree('parent', [
             Tree('sibling-0'),
             Tree('sibling-1'),
             Tree('grandparent',
                  [Tree('uncle', [Tree('cousin-0'),
                                  Tree('cousin-1')])])
         ])
     ])
     self.assertTreeEquals(tree.from_pov('x'), expected)
Ejemplo n.º 13
0
 def test_can_reroot_a_tree_with_a_parent_and_many_siblings(self):
     tree = Tree("parent", [Tree("a"), Tree("x"), Tree("b"), Tree("c")])
     expected = Tree(
         "x", [Tree("parent",
                    [Tree("a"), Tree("b"), Tree("c")])])
     self.assertTreeEquals(tree.from_pov("x"), expected)
Ejemplo n.º 14
0
 def test_errors_if_target_does_not_exist_in_a_singleton_tree(self):
     tree = Tree("x")
     with self.assertRaises(ValueError) as err:
         tree.from_pov("nonexistent")
     self.assertEqual(type(err.exception), ValueError)
     self.assertEqual(err.exception.args[0], "Tree could not be reoriented")
Ejemplo n.º 15
0
 def test_can_reroot_tree_with_parent_and_many_siblings(self):
     tree = Tree('parent', [Tree('a'), Tree('x'), Tree('b'), Tree('c')])
     expected = Tree(
         'x', [Tree('parent',
                    [Tree('a'), Tree('b'), Tree('c')])])
     self.assertTreeEquals(tree.from_pov('x'), expected)
Ejemplo n.º 16
0
 def test_errors_if_target_does_not_exist_in_singleton_tree(self):
     tree = Tree('x')
     with self.assertRaisesWithMessage(ValueError):
         tree.from_pov('nonexistent')
Ejemplo n.º 17
0
 def test_moves_children_of_new_root_to_same_level_as_former_parent(self):
     tree = Tree('parent', [Tree('x', [Tree('kid-0'), Tree('kid-1')])])
     expected = Tree('x', [Tree('parent'), Tree('kid-0'), Tree('kid-1')])
     self.assertTreeEquals(tree.from_pov('x'), expected)
Ejemplo n.º 18
0
 def test_errors_if_target_does_not_exist_in_a_singleton_tree(self):
     tree = Tree("x")
     with self.assertRaisesWithMessage(ValueError):
         tree.from_pov("nonexistent")
Ejemplo n.º 19
0
 def test_results_in_the_same_tree_if_the_input_tree_is_a_singleton(self):
     tree = Tree("x")
     expected = Tree("x")
     self.assertTreeEquals(tree.from_pov("x"), expected)
Ejemplo n.º 20
0
 def test_singleton_returns_same_tree(self):
     tree = Tree('x')
     self.assertTreeEquals(tree.from_pov('x'), tree)
Ejemplo n.º 21
0
 def test_singleton_returns_same_tree(self):
     tree = Tree('x')
     self.assertTreeEquals(tree.from_pov('x'), tree)
Ejemplo n.º 22
0
 def test_moves_children_of_the_new_root_to_same_level_as_former_parent(
         self):
     tree = Tree("parent", [Tree("x", [Tree("kid-0"), Tree("kid-1")])])
     expected = Tree("x", [Tree("kid-0"), Tree("kid-1"), Tree("parent")])
     self.assertTreeEquals(tree.from_pov("x"), expected)