Пример #1
0
 def test_for_graph_with_one_node_with_arc_returns_empty(self):
     result = shortest_path_with_direction(
         graph={0: Node(position=Point(0, 0), arcs=[Arc(dst=0, weight=1)])},
         src=0,
         dst=0,
         initial_direction=Point(1, 0),
         forbidden={})
     assert_that(list(result), equal_to([]))
Пример #2
0
 def test_for_quadrant_from_left_top_to_right_top_with_direction_to_bottom_returns_path_direct_to_right_top(self):
     result = shortest_path_with_direction(graph={
         0: Node(position=Point(0, 0), arcs=[Arc(dst=1, weight=1),
                                             Arc(dst=2, weight=1)]),
         1: Node(position=Point(0, 1), arcs=[Arc(dst=3, weight=1)]),
         2: Node(position=Point(1, 0), arcs=[]),
         3: Node(position=Point(1, 1), arcs=[Arc(dst=2, weight=1)]),
     }, src=0, dst=2, initial_direction=Point(0, 1), forbidden={})
     assert_that(list(result), equal_to([2]))
Пример #3
0
 def test_for_graph_with_two_alternatives_with_initial_direction_to_right_top_returns_over_top(self):
     result = shortest_path_with_direction(graph={
         0: Node(position=Point(0, 1), arcs=[Arc(dst=1, weight=1),
                                             Arc(dst=2, weight=1)]),
         1: Node(position=Point(0, 0), arcs=[Arc(dst=3, weight=1)]),
         2: Node(position=Point(0, 2), arcs=[Arc(dst=4, weight=1)]),
         3: Node(position=Point(1, 0), arcs=[Arc(dst=5, weight=1)]),
         4: Node(position=Point(1, 2), arcs=[Arc(dst=5, weight=1)]),
         5: Node(position=Point(1, 1), arcs=[]),
     }, src=0, dst=5, initial_direction=Point(1, 1), forbidden={})
     assert_that(list(result), equal_to([2, 4, 5]))
Пример #4
0
 def test_for_graph_with_two_disconnected_nodes_returns_empty(self):
     result = shortest_path_with_direction(graph={
         0:
         Node(position=Point(0, 0), arcs=[]),
         1:
         Node(position=Point(1, 0), arcs=[]),
     },
                                           src=0,
                                           dst=1,
                                           initial_direction=Point(1, 0),
                                           forbidden={})
     assert_that(list(result), equal_to([]))
Пример #5
0
 def test_for_graph_2(self):
     result = shortest_path_with_direction(graph={
         0: Node(position=Point(0, 1), arcs=[Arc(dst=1, weight=1),
                                             Arc(dst=2, weight=1)]),
         1: Node(position=Point(0, 0), arcs=[Arc(dst=3, weight=1)]),
         2: Node(position=Point(0, 2), arcs=[Arc(dst=4, weight=1)]),
         3: Node(position=Point(1, 0), arcs=[Arc(dst=5, weight=1)]),
         4: Node(position=Point(1, 2), arcs=[Arc(dst=6, weight=1)]),
         5: Node(position=Point(1, 1), arcs=[Arc(dst=6, weight=1)]),
         6: Node(position=Point(2, 2), arcs=[]),
     }, src=0, dst=6, initial_direction=Point(1, 1), forbidden={})
     assert_that(list(result), equal_to([2, 4, 6]))
Пример #6
0
 def test_for_graph_3(self):
     result = shortest_path_with_direction(graph={
         0: Node(position=Point(0, 0), arcs=[]),
         1: Node(position=Point(0, 1), arcs=[Arc(dst=0, weight=1)]),
         2: Node(position=Point(0, 2), arcs=[Arc(dst=1, weight=1)]),
         3: Node(position=Point(0, 3), arcs=[Arc(dst=2, weight=1)]),
         4: Node(position=Point(0, 4), arcs=[Arc(dst=3, weight=1)]),
         5: Node(position=Point(0, 5), arcs=[Arc(dst=4, weight=1)]),
         6: Node(position=Point(1, 2), arcs=[Arc(dst=1, weight=pi / 2)]),
         7: Node(position=Point(1, 6), arcs=[Arc(dst=5, weight=pi / 2)]),
         8: Node(position=Point(2, 3), arcs=[Arc(dst=6, weight=pi / 2)]),
         9: Node(position=Point(2, 4), arcs=[Arc(dst=8, weight=1)]),
         10: Node(position=Point(2, 5), arcs=[Arc(dst=9, weight=1)]),
         11: Node(position=Point(2, 6), arcs=[Arc(dst=7, weight=1)]),
         12: Node(position=Point(3, 6), arcs=[Arc(dst=10, weight=pi / 2),
                                              Arc(dst=11, weight=1)]),
     }, src=12, dst=0, initial_direction=Point(-1, 0), forbidden={})
     assert_that(list(result), equal_to([11, 7, 5, 4, 3, 2, 1, 0]))
Пример #7
0
 def test_for_quadrant_from_left_top_to_right_top_with_direction_to_bottom_returns_path_direct_to_right_top(
         self):
     result = shortest_path_with_direction(graph={
         0:
         Node(position=Point(0, 0),
              arcs=[Arc(dst=1, weight=1),
                    Arc(dst=2, weight=1)]),
         1:
         Node(position=Point(0, 1), arcs=[Arc(dst=3, weight=1)]),
         2:
         Node(position=Point(1, 0), arcs=[]),
         3:
         Node(position=Point(1, 1), arcs=[Arc(dst=2, weight=1)]),
     },
                                           src=0,
                                           dst=2,
                                           initial_direction=Point(0, 1),
                                           forbidden={})
     assert_that(list(result), equal_to([2]))
Пример #8
0
 def test_for_graph_with_two_alternatives_with_initial_direction_to_right_top_returns_over_top(
         self):
     result = shortest_path_with_direction(graph={
         0:
         Node(position=Point(0, 1),
              arcs=[Arc(dst=1, weight=1),
                    Arc(dst=2, weight=1)]),
         1:
         Node(position=Point(0, 0), arcs=[Arc(dst=3, weight=1)]),
         2:
         Node(position=Point(0, 2), arcs=[Arc(dst=4, weight=1)]),
         3:
         Node(position=Point(1, 0), arcs=[Arc(dst=5, weight=1)]),
         4:
         Node(position=Point(1, 2), arcs=[Arc(dst=5, weight=1)]),
         5:
         Node(position=Point(1, 1), arcs=[]),
     },
                                           src=0,
                                           dst=5,
                                           initial_direction=Point(1, 1),
                                           forbidden={})
     assert_that(list(result), equal_to([2, 4, 5]))
Пример #9
0
 def test_for_graph_3(self):
     result = shortest_path_with_direction(graph={
         0:
         Node(position=Point(0, 0), arcs=[]),
         1:
         Node(position=Point(0, 1), arcs=[Arc(dst=0, weight=1)]),
         2:
         Node(position=Point(0, 2), arcs=[Arc(dst=1, weight=1)]),
         3:
         Node(position=Point(0, 3), arcs=[Arc(dst=2, weight=1)]),
         4:
         Node(position=Point(0, 4), arcs=[Arc(dst=3, weight=1)]),
         5:
         Node(position=Point(0, 5), arcs=[Arc(dst=4, weight=1)]),
         6:
         Node(position=Point(1, 2), arcs=[Arc(dst=1, weight=pi / 2)]),
         7:
         Node(position=Point(1, 6), arcs=[Arc(dst=5, weight=pi / 2)]),
         8:
         Node(position=Point(2, 3), arcs=[Arc(dst=6, weight=pi / 2)]),
         9:
         Node(position=Point(2, 4), arcs=[Arc(dst=8, weight=1)]),
         10:
         Node(position=Point(2, 5), arcs=[Arc(dst=9, weight=1)]),
         11:
         Node(position=Point(2, 6), arcs=[Arc(dst=7, weight=1)]),
         12:
         Node(position=Point(3, 6),
              arcs=[Arc(dst=10, weight=pi / 2),
                    Arc(dst=11, weight=1)]),
     },
                                           src=12,
                                           dst=0,
                                           initial_direction=Point(-1, 0),
                                           forbidden={})
     assert_that(list(result), equal_to([11, 7, 5, 4, 3, 2, 1, 0]))
Пример #10
0
 def test_for_graph_2(self):
     result = shortest_path_with_direction(graph={
         0:
         Node(position=Point(0, 1),
              arcs=[Arc(dst=1, weight=1),
                    Arc(dst=2, weight=1)]),
         1:
         Node(position=Point(0, 0), arcs=[Arc(dst=3, weight=1)]),
         2:
         Node(position=Point(0, 2), arcs=[Arc(dst=4, weight=1)]),
         3:
         Node(position=Point(1, 0), arcs=[Arc(dst=5, weight=1)]),
         4:
         Node(position=Point(1, 2), arcs=[Arc(dst=6, weight=1)]),
         5:
         Node(position=Point(1, 1), arcs=[Arc(dst=6, weight=1)]),
         6:
         Node(position=Point(2, 2), arcs=[]),
     },
                                           src=0,
                                           dst=6,
                                           initial_direction=Point(1, 1),
                                           forbidden={})
     assert_that(list(result), equal_to([2, 4, 6]))
Пример #11
0
 def test_for_graph_with_two_disconnected_nodes_returns_empty(self):
     result = shortest_path_with_direction(graph={
         0: Node(position=Point(0, 0), arcs=[]),
         1: Node(position=Point(1, 0), arcs=[]),
     }, src=0, dst=1, initial_direction=Point(1, 0), forbidden={})
     assert_that(list(result), equal_to([]))
Пример #12
0
 def test_for_graph_with_one_node_with_arc_returns_empty(self):
     result = shortest_path_with_direction(
         graph={0: Node(position=Point(0, 0), arcs=[Arc(dst=0, weight=1)])},
         src=0, dst=0, initial_direction=Point(1, 0), forbidden={})
     assert_that(list(result), equal_to([]))