Exemplo n.º 1
0
    def test_givenPathWithPosition_whenAddVerticallyNonAdjacentPosition_thenThrowInvalidPositionException(
        self, ):
        path = Path([Position(1, 3)])
        a_position = Position(1, 1)

        with self.assertRaises(PositionNotAdjacentException):
            path.add(a_position)
Exemplo n.º 2
0
    def test_givenEmptyPath_whenAdd_thenPositionIsAddedToPath(self):
        path = Path([])
        a_position = Position(1, 1)

        path.add(a_position)

        self.assertEqual(a_position, path[0])
Exemplo n.º 3
0
    def test_givenPathWithPosition_whenAddAdjacentPosition_thenPositionIsAddedToPath(
        self, ):
        path = Path([Position(1, 2)])
        a_position = Position(1, 1)

        path.add(a_position)

        self.assertEqual(a_position, path[1])
Exemplo n.º 4
0
    def _split_path_in_sub_paths(self, full_path: Path) -> List[Path]:
        sub_paths = list()
        if not self._path_has_turn(full_path):
            sub_paths.append(full_path)
            return sub_paths

        current_position = 1
        path_length = len(full_path) + 1
        current_path = Path([])
        while current_position < path_length - 1:
            is_current_direction_vertical = self._are_positions_moving_vertically(
                full_path[current_position - 1], full_path[current_position])
            if is_current_direction_vertical:
                while is_current_direction_vertical and current_position < path_length:
                    current_path.add(full_path[current_position - 1])
                    is_current_direction_vertical = self._is_current_direction_vertical(
                        is_current_direction_vertical,
                        current_position,
                        path_length,
                        full_path,
                    )
                    current_position += 1
            else:
                while (not is_current_direction_vertical
                       and current_position < path_length):
                    current_path.add(full_path[current_position - 1])
                    is_current_direction_vertical = self._is_current_direction_vertical(
                        is_current_direction_vertical,
                        current_position,
                        path_length,
                        full_path,
                    )
                    current_position += 1

            sub_paths.append(current_path)
            current_path = Path([])

        return sub_paths