-
Notifications
You must be signed in to change notification settings - Fork 0
/
_inter_made.py
65 lines (52 loc) · 2.09 KB
/
_inter_made.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import unittest
class Robot:
def __init__(self, location, bearing):
self.location = location
self.bearing = bearing
def move_robot_forward(self):
self.location[1] += 1
def change_location_to_left(self):
if self.bearing == 'North':
self.bearing = 'West'
elif self.bearing == 'West':
self.bearing = 'South'
elif self.bearing == 'South':
self.bearing = 'East'
elif self.bearing == 'East':
self.bearing = 'North'
class TestRobot(unittest.TestCase):
def test_check_initial_coordinates(self):
robot = Robot([0, 0], 'North')
self.assertEqual(robot.location, [0, 0])
self.assertEqual(robot.bearing, 'North')
def test_check_robot_move(self):
robot = Robot([0, 0], 'North')
robot.move_robot_forward()
self.assertEqual(robot.location, [0, 1])
self.assertEqual(robot.bearing, 'North')
def test_check_robot_move_twice(self):
robot = Robot([0, 0], 'North')
robot.move_robot_forward()
robot.move_robot_forward()
self.assertEqual(robot.location, [0, 2])
self.assertEqual(robot.bearing, 'North')
def test_change_location_to_left_from_north(self):
robot = Robot([0, 0], 'North')
robot.change_location_to_left()
self.assertEqual(robot.location, [0, 0])
self.assertEqual(robot.bearing, 'West')
def test_change_location_to_left_from_west(self):
robot = Robot([0, 0], 'West')
robot.change_location_to_left()
self.assertEqual(robot.location, [0, 0])
self.assertEqual(robot.bearing, 'South')
def test_change_location_to_left_from_south(self):
robot = Robot([0, 0], 'South')
robot.change_location_to_left()
self.assertEqual(robot.location, [0, 0])
self.assertEqual(robot.bearing, 'East')
def test_change_location_to_left_from_east(self):
robot = Robot([0, 0], 'East')
robot.change_location_to_left()
self.assertEqual(robot.location, [0, 0])
self.assertEqual(robot.bearing, 'North')