示例#1
0
def test_forward_position(orientation, dst_position):
    position = Position(1, 2)
    orientation = Orientation(orientation)

    with mock.patch.object(position, 'restrict_to_grid') as restrict_to_grid:
        position.forward(orientation, grid_size=(100, 100))
        restrict_to_grid.assert_called_once()

    assert (position.x, position.y) == dst_position
示例#2
0
def test_mower_initialization():
    position = Position(8, 9)

    with mock.patch.object(position, 'restrict_to_grid') as restrict_to_grid:
        mower = Mower(position, Orientation('W'), grid_size=(10, 10))
        restrict_to_grid.assert_called_once()

    assert (mower.x, mower.y) == (8, 9)
    assert mower.orientation == 'W'
示例#3
0
def test_step_mower(move, rotate_left_calls, rotate_right_calls,
                    forward_calls):
    position = Position(8, 9)
    orientation = Orientation('W')
    mower = Mower(position, orientation, grid_size=(10, 10))

    with mock.patch.object(orientation, 'rotate_left') as rotate_left:
        with mock.patch.object(orientation, 'rotate_right') as rotate_right:
            with mock.patch.object(position, 'forward') as forward:
                mower.step(move)

                assert rotate_left.call_count == rotate_left_calls
                assert rotate_right.call_count == rotate_right_calls
                assert forward.call_count == forward_calls
示例#4
0
def _parse_mower_line(line: str, grid_size: Tuple[int, int]) -> Mower:
    """
    Parse and validate initial position (2 space-separated ints) and orientation (N/S/W/E char)
    of mower.
    """
    try:
        x, y, orientation = line.split(' ')
        x, y = _parse_point(x, y)
        position = Position(x, y)
        orientation = Orientation(orientation)
    except ValueError:
        raise ValueError(f'Invalid initial position and orientation: "{line}"')
    else:
        mower = Mower(position, orientation, grid_size)
        return mower
示例#5
0
def test_init_position():
    position = Position(-7, 8)
    assert position.cplx_position == complex(-7, 8)
    assert (position.x, position.y) == (-7, 8)
示例#6
0
def test_restrict_position_to_grid(src_position, grid_size, dst_position):
    position = Position(*src_position)
    position.restrict_to_grid(grid_size)
    assert (position.x, position.y) == dst_position
示例#7
0
def test_str_position():
    assert str(Position(1, -2)) == '1 -2'
示例#8
0
def test_str_mower():
    mower = Mower(Position(8, 9), Orientation('W'), grid_size=(10, 10))
    assert str(mower) == '8 9 W'