Finished
11# Globals for the directions
22# Change the values as you see fit
3EAST = None
4NORTH = None
5WEST = None
6SOUTH = None
3EAST = 0
4NORTH = 1
5WEST = 2
6SOUTH = 3
77
88
99class Robot:
1010 def __init__(self, direction=NORTH, x_pos=0, y_pos=0):
11 pass
11 self.direction = direction
12 self.x = x_pos
13 self.y = y_pos
14 self.directions = [(1, 0), (0, 1), (-1, 0), (0, -1)] # East, North, West, South
15
16 def move(self, instructions):
17 # Edge Case: Empty instruction string
18 if not instructions:
19 return
20
21 # Edge Case: Invalid instruction characters
22 valid_instructions = set('RLA')
23 if not all(char in valid_instructions for char in instructions):
24 raise ValueError("Invalid instruction")
25
26 for instruction in instructions:
27 if instruction == 'R':
28 self.turn_right()
29 elif instruction == 'L':
30 self.turn_left()
31 elif instruction == 'A':
32 self.advance()
33
34 def turn_right(self):
35 self.direction = (self.direction - 1) % 4
36
37 def turn_left(self):
38 self.direction = (self.direction + 1) % 4
39
40 def advance(self):
41 dx, dy = self.directions[self.direction]
42 self.x += dx
43 self.y += dy
44
45 @property
46 def coordinates(self):
47 return (self.x, self.y)
48
49 # Handled Edge Cases: Empty instruction string, Invalid instruction characters
Test NameStatus
test_at_negative_position_facing_south
Pass
test_at_origin_facing_north
Pass
test_changes_east_to_north
Pass
test_changes_east_to_south
Pass
test_changes_north_to_east
Pass
test_changes_north_to_west
Pass
test_changes_south_to_east
Pass
test_changes_south_to_west
Pass
test_changes_west_to_north
Pass
test_changes_west_to_south
Pass
test_facing_east_increments_x
Pass
test_facing_north_increments_y
Pass
test_facing_south_decrements_y
Pass
test_facing_west_decrements_x
Pass
test_moving_east_and_north
Pass
test_moving_east_and_north_from_readme
Pass
test_moving_west_and_north
Pass
test_moving_west_and_south
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.