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

ObstacleDetection implemented and tested

parent 92b930b1
No related branches found
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": "Rover Obstacle Detection",
"scenario": "The rover must stop when it detects an obstacle in its path.",
"actors": "MissionControl",
"preconditions": "Rover is landed on the plateau at position (0,0)",
"steps": [
"MissionControl sends a movement command to the rover",
"Rover checks each step for obstacles using its obstacle detection system (ODS)",
"If an obstacle is detected, the rover stops before moving into it",
"Remaining commands in the sequence are ignored",
"Rover returns only the successfully executed commands"
]
}
## Testcase
[
{
"name": "Rover Stops at First Obstacle",
"description": "Verify that the rover stops immediately when the first obstacle is detected",
"input": {
"command": "FFRFF"
},
"expected": {
"outcome": "Obstacle detected; rover stopped",
"executedCommands": "FF"
}
},
{
"name": "Rover Avoids Obstacle and Continues",
"description": "Verify that rover only moves until just before the obstacle",
"input": {
"command": "FRFRF"
},
"expected": {
"outcome": "Obstacle detected mid-sequence",
"executedCommands": "FRF"
}
},
{
"name": "Rover Encounters No Obstacles",
"description": "Verify that the rover executes all commands when no obstacles are present",
"input": {
"command": "FFLFF"
},
"expected": {
"outcome": "Rover moved successfully",
"executedCommands": "FFLFF"
}
}
]
# Adds obstacle detection to rover1.py
DIRECTIONS = ['N', 'E', 'S', 'W']
MOVES = {
'N': (0, 1),
'E': (1, 0),
'S': (0, -1),
'W': (-1, 0)
}
class Rover:
def __init__(self, obstacles=None):
self.x = 0
self.y = 0
self.heading = 0
self.obstacles = obstacles if obstacles else set()
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
next_x = self.x + dx
next_y = self.y + dy
if (next_x, next_y) in self.obstacles:
break
self.x = next_x
self.y = next_y
elif cmd == 'L':
self.heading = (self.heading - 1) % 4
elif cmd == 'R':
self.heading = (self.heading + 1) % 4
else:
break
executed += cmd
return executed
def get_position(self):
return (self.x, self.y)
def get_heading(self):
return DIRECTIONS[self.heading]
from backuprover2 import Rover
def test_stops_at_first_obstacle():
rover = Rover(obstacles={(0, 2)})
result = rover.drive("FFRFF")
assert result == "F"
assert rover.get_position() == (0, 1)
def test_mid_sequence_obstacle():
rover = Rover(obstacles={(1, 1)})
result = rover.drive("FRFRF")
assert result == "FR"
assert rover.get_position() == (0, 1)
def test_no_obstacles_full_execution():
rover = Rover()
result = rover.drive("FFLFF")
assert result == "FFLFF"
assert rover.get_position() == (-2, 2)
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