Skip to content
Snippets Groups Projects
Commit e40a1b2b authored by Daniel Rafeh's avatar Daniel Rafeh
Browse files

New function added - implementation of a move_backward-function in order to...

New function added - implementation of a move_backward-function in order to make the rover move backward too, creation of 4 testcases in order to proof that the MissionControl is able to make the rover move backwards
parent d426fb6c
Branches feature/move_backwards
No related tags found
No related merge requests found
Pipeline #20357 passed
......@@ -89,10 +89,22 @@ class Rover:
elif self.direction == 'W':
self.x -= 1
def move_backward(self):
if self.direction == 'N':
self.y -= 1
elif self.direction == 'S':
self.y += 1
elif self.direction == 'E':
self.x -= 1
elif self.direction == 'W':
self.x += 1
def drive(self, cmd: str) -> str:
for c in cmd:
if c == 'F':
self.move_forward()
elif c == 'B':
self.move_backward()
class Mars:
......@@ -153,6 +165,37 @@ class TestRover(unittest.TestCase):
control.execute_command('F')
self.assertEqual((rover.x, rover.y), (0,0))
# Test Move Backward in Different Directions
def test_move_backward_north(self):
rover = Rover(0, 1, 'N')
control = MissionControl(rover)
control.execute_command('B')
self.assertEqual((rover.x, rover.y), (0,0))
def test_move_backward_south(self):
rover = Rover(0, 0, 'S')
control = MissionControl(rover)
control.execute_command('B')
self.assertEqual((rover.x, rover.y), (0,1))
def test_move_backward_east(self):
rover = Rover(1, 0, 'E')
control = MissionControl(rover)
control.execute_command('B')
self.assertEqual((rover.x, rover.y), (0,0))
def test_move_backward_west(self):
rover = Rover(0, 0, 'W')
control = MissionControl(rover)
control.execute_command('B')
self.assertEqual((rover.x, rover.y), (1,0))
if __name__ == '__main__':
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment