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

Implementation of move_forward-function - function implementation and 4 tests...

Implementation of move_forward-function - function implementation and 4 tests ran in order to see if the function works without any issues
parent 04eb7f87
No related branches found
No related tags found
No related merge requests found
Pipeline #20351 passed
......@@ -77,10 +77,22 @@ class Rover:
self.x = x
self.y = y
self.direction = direction
self.directions = ['N', 'E', 'S', 'W']
def move_forward(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:
pass
for c in cmd:
if c == 'F':
self.move_forward()
class Mars:
......@@ -105,3 +117,32 @@ class Map:
class MissionControl:
def __init__(self):
pass
class TestRover(unittest.TestCase):
# Test Move Forward in Different Directions
def test_move_forward_north(self):
rover = Rover(0, 0, 'N')
rover.move_forward()
self.assertEqual((rover.x, rover.y), (0,1))
def test_move_forward_south(self):
rover = Rover(0, 1, 'S')
rover.move_forward()
self.assertEqual((rover.x, rover.y), (0,0))
def test_move_forward_east(self):
rover = Rover(0, 0, 'E')
rover.move_forward()
self.assertEqual((rover.x, rover.y), (1,0))
def test_move_forward_west(self):
rover = Rover(1, 0, 'W')
rover.move_forward()
self.assertEqual((rover.x, rover.y), (0,0))
if __name__ == '__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 register or to comment