示例#1
0
文件: pov_test.py 项目: avbm/exercism
 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.path_to('nonexistent', 'x')
示例#2
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.path_to("nonexistent", "x")
示例#3
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.path_to('nonexistent', 'x')
示例#4
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.assertRaises(ValueError) as err:
            tree.path_to("nonexistent", "x")
        self.assertEqual(type(err.exception), ValueError)

        self.assertEqual(err.exception.args[0], "Tree could not be reoriented")
示例#5
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) as err:
            tree.path_to("x", "nonexistent")
        self.assertEqual(type(err.exception), ValueError)

        self.assertEqual(err.exception.args[0], "No path found")
示例#6
0
 def test_find_path_between_two_nodes(self):
     tree = Tree('parent', [
         Tree('x'),
         Tree('sibling')
     ])
     expected = ['x', 'parent']
     self.assertEqual(tree.path_to('x', 'parent'), expected)
示例#7
0
 def test_can_find_path_not_involving_root(self):
     tree = Tree(
         "grandparent",
         [Tree("parent", [Tree("x"), Tree("sibling-0"), Tree("sibling-1")])],
     )
     expected = ["x", "parent", "sibling-1"]
     self.assertEqual(tree.path_to("x", "sibling-1"), expected)
示例#8
0
文件: pov_test.py 项目: avbm/exercism
 def test_can_find_path_not_involving_root(self):
     tree = Tree('grandparent', [
         Tree('parent',
              [Tree('x'), Tree('sibling-0'),
               Tree('sibling-1')])
     ])
     expected = ['x', 'parent', 'sibling-1']
     self.assertEqual(tree.path_to('x', 'sibling-1'), expected)
示例#9
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.path_to('x', 'b'), expected)
示例#10
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.path_to('a', 'c'), expected)
示例#11
0
 def test_can_find_path_not_involving_root(self):
     tree = Tree('grandparent', [
         Tree('parent', [
             Tree('x'),
             Tree('sibling-0'),
             Tree('sibling-1')
         ])
     ])
     expected = ['x', 'parent', 'sibling-1']
     self.assertEqual(tree.path_to('x', 'sibling-1'), expected)
示例#12
0
文件: pov_test.py 项目: avbm/exercism
 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.path_to('x', 'cousin-1'), expected)
示例#13
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.path_to('x', 'cousin-1'), expected)
示例#14
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.path_to("x", "cousin-1"), expected)
示例#15
0
文件: pov_test.py 项目: avbm/exercism
 def test_find_path_between_two_nodes(self):
     tree = Tree('parent', [Tree('x'), Tree('sibling')])
     expected = ['x', 'parent']
     self.assertEqual(tree.path_to('x', 'parent'), expected)
示例#16
0
文件: pov_test.py 项目: avbm/exercism
 def test_can_get_path_without_reroot(self):
     tree = Tree('parent', [Tree('a'), Tree('x'), Tree('b'), Tree('c')])
     expected = ['parent', 'c']
     self.assertTreeEquals(tree.path_to('parent', 'c'), expected)
示例#17
0
文件: pov_test.py 项目: avbm/exercism
 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.path_to('a', 'c'), expected)
示例#18
0
文件: pov_test.py 项目: avbm/exercism
 def test_can_get_deeply_nested_path_without_reroot(self):
     tree = Tree('level-0', [
         Tree('level-1', [Tree('level-2', [Tree('level-3', [Tree('x')])])])
     ])
     expected = ['level-0', 'level-1', 'level-2', 'level-3', 'x']
     self.assertTreeEquals(tree.path_to('level-0', 'x'), expected)
示例#19
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.path_to("a", "c"), expected)
示例#20
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.path_to("x", "b"), expected)
示例#21
0
文件: pov_test.py 项目: avbm/exercism
 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.path_to('x', 'b'), expected)
示例#22
0
 def test_can_find_path_to_parent(self):
     tree = Tree("parent", [Tree("x"), Tree("sibling")])
     expected = ["x", "parent"]
     self.assertEquals(tree.path_to("x", "parent"), expected)