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([]))
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([]))
def test_for_two_double_connected_nodes_returns_with_three_nodes(self): result = split_arcs( graph={ 0: Node(position=Point(0, 0), arcs=[Arc(dst=1, weight=1)]), 1: Node(position=Point(0, 1), arcs=[Arc(dst=0, weight=1)]), }) assert_that( result, equal_to({ 0: Node(position=Point(0, 0), arcs=[Arc(dst=2, weight=0.5)]), 1: Node(position=Point(0, 1), arcs=[Arc(dst=2, weight=0.5)]), 2: Node(position=Point(0, 0.5), arcs=[Arc(dst=0, weight=0.5), Arc(dst=1, weight=0.5)]), }))
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]))
def test_for_two_horizontal_between_empty(self): result = make_graph(tiles=[ [TileType.EMPTY], [TileType.HORIZONTAL], [TileType.HORIZONTAL], [TileType.EMPTY], ], ) assert_that( result, equal_to({ 0: Node(position=Point(0, 0), arcs=[]), 1: Node(position=Point(1, 0), arcs=[Arc(dst=0, weight=1), Arc(dst=2, weight=1)]), 2: Node(position=Point(2, 0), arcs=[Arc(dst=1, weight=1), Arc(dst=3, weight=1)]), 3: Node(position=Point(3, 0), arcs=[]), }))
def test_for_two_vertical_between_empty(self): result = make_graph(tiles=[ [ TileType.EMPTY, TileType.VERTICAL, TileType.VERTICAL, TileType.EMPTY ], ], ) assert_that( result, equal_to({ 0: Node(position=Point(0, 0), arcs=[]), 1: Node(position=Point(0, 1), arcs=[Arc(dst=0, weight=1), Arc(dst=2, weight=1)]), 2: Node(position=Point(0, 2), arcs=[Arc(dst=1, weight=1), Arc(dst=3, weight=1)]), 3: Node(position=Point(0, 3), arcs=[]), }))
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]))
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]))
def test_for_split_quadrant_from_left_top_to_right_bottom_add_eight_new_arcs( self): result = add_diagonal_arcs( graph={ 0: Node(position=Point(x=0, y=0), arcs=[Arc(dst=4, weight=0.5), Arc(dst=5, weight=0.5)]), 1: Node(position=Point(x=0, y=1), arcs=[Arc(dst=4, weight=0.5), Arc(dst=6, weight=0.5)]), 2: Node(position=Point(x=1, y=0), arcs=[Arc(dst=5, weight=0.5), Arc(dst=7, weight=0.5)]), 3: Node(position=Point(x=1, y=1), arcs=[Arc(dst=6, weight=0.5), Arc(dst=7, weight=0.5)]), 4: Node(position=Point(x=0.0, y=0.5), arcs=[Arc(dst=0, weight=0.5), Arc(dst=1, weight=0.5)]), 5: Node(position=Point(x=0.5, y=0.0), arcs=[Arc(dst=0, weight=0.5), Arc(dst=2, weight=0.5)]), 6: Node(position=Point(x=0.5, y=1.0), arcs=[Arc(dst=1, weight=0.5), Arc(dst=3, weight=0.5)]), 7: Node(position=Point(x=1.0, y=0.5), arcs=[Arc(dst=2, weight=0.5), Arc(dst=3, weight=0.5)]), }) assert_that( result, equal_to({ 0: Node(position=Point(x=0, y=0), arcs=[Arc(dst=4, weight=0.5), Arc(dst=5, weight=0.5)]), 1: Node(position=Point(x=0, y=1), arcs=[Arc(dst=4, weight=0.5), Arc(dst=6, weight=0.5)]), 2: Node(position=Point(x=1, y=0), arcs=[Arc(dst=5, weight=0.5), Arc(dst=7, weight=0.5)]), 3: Node(position=Point(x=1, y=1), arcs=[Arc(dst=6, weight=0.5), Arc(dst=7, weight=0.5)]), 4: Node(position=Point(x=0.0, y=0.5), arcs=[ Arc(dst=0, weight=0.5), Arc(dst=1, weight=0.5), Arc(dst=5, weight=pi / 2 / 2), Arc(dst=6, weight=pi / 2 / 2) ]), 5: Node(position=Point(x=0.5, y=0.0), arcs=[ Arc(dst=0, weight=0.5), Arc(dst=2, weight=0.5), Arc(dst=4, weight=pi / 2 / 2), Arc(dst=7, weight=pi / 2 / 2) ]), 6: Node(position=Point(x=0.5, y=1.0), arcs=[ Arc(dst=1, weight=0.5), Arc(dst=3, weight=0.5), Arc(dst=4, weight=pi / 2 / 2), Arc(dst=7, weight=pi / 2 / 2) ]), 7: Node(position=Point(x=1.0, y=0.5), arcs=[ Arc(dst=2, weight=0.5), Arc(dst=3, weight=0.5), Arc(dst=5, weight=pi / 2 / 2), Arc(dst=6, weight=pi / 2 / 2) ]), }))
def test_for_quadrant_from_left_top_to_right_bottom_returns_with_new_four_nodes( self): result = split_arcs( 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=[Arc(dst=3, weight=1)]), 3: Node(position=Point(1, 1), arcs=[]), }) assert_that( result, equal_to({ 0: Node(position=Point(x=0, y=0), arcs=[Arc(dst=4, weight=0.5), Arc(dst=5, weight=0.5)]), 1: Node(position=Point(x=0, y=1), arcs=[Arc(dst=4, weight=0.5), Arc(dst=6, weight=0.5)]), 2: Node(position=Point(x=1, y=0), arcs=[Arc(dst=5, weight=0.5), Arc(dst=7, weight=0.5)]), 3: Node(position=Point(x=1, y=1), arcs=[Arc(dst=6, weight=0.5), Arc(dst=7, weight=0.5)]), 4: Node(position=Point(x=0.0, y=0.5), arcs=[Arc(dst=0, weight=0.5), Arc(dst=1, weight=0.5)]), 5: Node(position=Point(x=0.5, y=0.0), arcs=[Arc(dst=0, weight=0.5), Arc(dst=2, weight=0.5)]), 6: Node(position=Point(x=0.5, y=1.0), arcs=[Arc(dst=1, weight=0.5), Arc(dst=3, weight=0.5)]), 7: Node(position=Point(x=1.0, y=0.5), arcs=[Arc(dst=2, weight=0.5), Arc(dst=3, weight=0.5)]), }))
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]))