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

implementation of a turn_right-function in order to make it possible for the...

implementation of a turn_right-function in order to make it possible for the MissionControl to make the rover turn right
parent 7ff37d26
No related branches found
No related tags found
No related merge requests found
Pipeline #20364 passed
...@@ -103,6 +103,10 @@ class Rover: ...@@ -103,6 +103,10 @@ class Rover:
current_index = self.directions.index(self.direction) current_index = self.directions.index(self.direction)
self.direction = self.directions[(current_index - 1) % len(self.directions)] self.direction = self.directions[(current_index - 1) % len(self.directions)]
def turn_right(self):
current_index = self.directions.index(self.direction)
self.direction = self.directions[(current_index + 1) % len(self.directions)]
def drive(self, cmd: str) -> str: def drive(self, cmd: str) -> str:
for c in cmd: for c in cmd:
if c == 'F': if c == 'F':
...@@ -111,6 +115,8 @@ class Rover: ...@@ -111,6 +115,8 @@ class Rover:
self.move_backward() self.move_backward()
elif c == 'L': elif c == 'L':
self.turn_left() self.turn_left()
elif c == 'R':
self.turn_right()
class Mars: class Mars:
...@@ -230,5 +236,34 @@ class TestRover(unittest.TestCase): ...@@ -230,5 +236,34 @@ class TestRover(unittest.TestCase):
control.execute_command('L') control.execute_command('L')
self.assertEqual(rover.direction, 'SW') self.assertEqual(rover.direction, 'SW')
# Test Turn Right in Different Directions
def test_turn_right_north(self):
rover = Rover(0, 0, 'N')
control = MissionControl(rover)
control.execute_command('R')
self.assertEqual(rover.direction, 'NE')
def test_turn_right_south(self):
rover = Rover(0, 0, 'S')
control = MissionControl(rover)
control.execute_command('R')
self.assertEqual(rover.direction, 'SW')
def test_turn_right_east(self):
rover = Rover(0, 0, 'E')
control = MissionControl(rover)
control.execute_command('R')
self.assertEqual(rover.direction, 'SE')
def test_turn_right_west(self):
rover = Rover(0, 0, 'W')
control = MissionControl(rover)
control.execute_command('R')
self.assertEqual(rover.direction, 'NW')
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment