Exemple #1
0
 def test_errors_if_source_does_not_exist(self):
     tree = Tree('parent', [
         Tree('x', [Tree('kid-0'), Tree('kid-1')]),
         Tree('sibling-0'),
         Tree('sibling-1')
     ])
     with self.assertRaisesWithMessage(ValueError):
         tree.pathTo('nonexistent', 'x')
Exemple #2
0
 def test_errors_if_destination_does_not_exist(self):
     tree = Tree('parent', [
         Tree('x', [
             Tree('kid-0'),
             Tree('kid-1')
         ]),
         Tree('sibling-0'),
         Tree('sibling-1')
     ])
     with self.assertRaises(ValueError):
         tree.pathTo('x', 'nonexistent')
Exemple #3
0
 def test_find_path_between_two_nodes(self):
     tree = Tree('parent', [
         Tree('x'),
         Tree('sibling')
     ])
     expected = ['x', 'parent']
     self.assertEqual(tree.pathTo('x', 'parent'), expected)
Exemple #4
0
 def test_can_find_path_from_nodes_other_than_x(self):
     tree = Tree('parent', [
         Tree('a'),
         Tree('x'),
         Tree('b'),
         Tree('c')
     ])
     expected = ['a', 'parent', 'c']
     self.assertEqual(tree.pathTo('a', 'c'), expected)
Exemple #5
0
 def test_can_find_path_to_sibling(self):
     tree = Tree('parent', [
         Tree('a'),
         Tree('x'),
         Tree('b'),
         Tree('c')
     ])
     expected = ['x', 'parent', 'b']
     self.assertEqual(tree.pathTo('x', 'b'), expected)
Exemple #6
0
 def test_can_find_path_to_cousin(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 = ['x', 'parent', 'grandparent', 'uncle', 'cousin-1']
     self.assertEqual(tree.pathTo('x', 'cousin-1'), expected)