Skip to content
Snippets Groups Projects
Commit 92b930b1 authored by Alma Berisha's avatar Alma Berisha
Browse files

basic movement implempented and tested

parents
Branches feature/basic-movement
No related tags found
1 merge request!1Develop
You are a tester tasked with creating comprehensive test cases for a given usecase description.
## Usecase description
{
"name": "Driving the Rover on Mars",
"scenario": "MissionControl sends drive commands to move the rover across the plateau.",
"actors": "MissionControl",
"preconditions": "Rover is landed on the plateau at position (0,0)",
"steps": [
"MissionControl sends command string (e.g. 'FFRLF') to the rover",
"Rover interprets each character and updates position/heading accordingly",
"Before each move, Rover checks for obstacles or plateau boundaries",
"If an obstacle or edge is detected, Rover stops and ignores remaining commands",
"Rover returns the string of successfully executed commands"
]
}
## Testcase
[
{
"name": "Rover Moves Successfully with No Obstacles",
"description": "Verify that the rover moves as expected with valid input and no obstacles",
"input": {
"command": "FFRFF"
},
"expected": {
"outcome": "Rover moved successfully",
"executedCommands": "FFRFF"
}
},
{
"name": "Rover Stops at Obstacle",
"description": "Verify that the rover stops when an obstacle is detected and remaining commands are ignored",
"input": {
"command": "FFRFF"
},
"expected": {
"outcome": "Rover stopped due to obstacle",
"executedCommands": "FFR"
}
},
{
"name": "Invalid Command Input",
"description": "Verify that the rover handles invalid commands gracefully",
"input": {
"command": "FXZ"
},
"expected": {
"outcome": "Invalid command encountered",
"executedCommands": "F"
}
}
]
# RoverMovement: (F, B, L, R)
# ObstacleDetection : (ODS)
DIRECTIONS = ['N', 'E', 'S', 'W']
MOVES = {
'N': (0, 1),
'E': (1, 0),
'S': (0, -1),
'W': (-1, 0)
}
class Rover:
def __init__(self):
self.x = 0
self.y = 0
self.heading = 0
def drive(self, command_string):
executed = ""
for cmd in command_string:
if cmd in ['F', 'B']:
dx, dy = MOVES[DIRECTIONS[self.heading]]
if cmd == 'B':
dx, dy = -dx, -dy
self.x += dx
self.y += dy
elif cmd == 'L':
self.heading = (self.heading - 1) % 4
elif cmd == 'R':
self.heading = (self.heading + 1) % 4
else:
break # stop on invalid command
executed += cmd
return executed
def get_position(self):
return (self.x, self.y)
def get_heading(self):
return DIRECTIONS[self.heading]
from backuprover1 import Rover
# FEATURE 1: Basic Movement
def test_basic_forward_movement():
rover = Rover()
result = rover.drive("FFRFF")
assert result == "FFRFF"
assert rover.get_position() == (2, 2)
def test_invalid_command_stops_execution():
rover = Rover()
result = rover.drive("FXZ")
assert result == "F"
def test_rotation_behavior():
rover = Rover()
rover.drive("LL")
assert rover.get_heading() == 'S'
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment