コード例 #1
0
class TestToyRobotWithoutPosition(unittest.TestCase):
    def setUp(self):
        self.toy_robot = ToyRobot()

    def test_commands_while_position_is_not_set(self):
        self.toy_robot.move()
        self.toy_robot.rotate_right()
        self.toy_robot.rotate_left()
        self.assertIsNone(self.toy_robot.position)
コード例 #2
0
class TestToyRobotMovement(unittest.TestCase):
    def setUp(self):
        self.toy_robot = ToyRobot()
        self.toy_robot.set_position(0, 0, 'EAST')

    def test_move_and_rotate(self):
        self.toy_robot.move()
        self.toy_robot.move()
        self.toy_robot.rotate_left()
        self.toy_robot.move()
        self.toy_robot.move()
        self.assertEqual(self.toy_robot.position.x, 2)
        self.assertEqual(self.toy_robot.position.y, 2)
        self.assertEqual(self.toy_robot.position.direction, 'NORTH')
コード例 #3
0
 def test_move_prevents_robot_from_falling_west(self):
     robot = ToyRobot(0, 4, "WEST")
     robot.move()
     self.assertEqual(robot.x, 0)
     self.assertEqual(robot.y, 4)
     self.assertEqual(robot.direction, "WEST")
コード例 #4
0
 def test_move_prevents_robot_from_falling_south(self):
     robot = ToyRobot(2, 0, "SOUTH")
     robot.move()
     self.assertEqual(robot.x, 2)
     self.assertEqual(robot.y, 0)
     self.assertEqual(robot.direction, "SOUTH")
コード例 #5
0
 def test_move_robot_adds_1_step_towards_west(self):
     robot = ToyRobot(1, 3, "WEST")
     robot.move()
     self.assertEqual(robot.x, 0)
     self.assertEqual(robot.y, 3)
     self.assertEqual(robot.direction, "WEST")
コード例 #6
0
 def test_move_robot_adds_1_step_towards_east(self):
     robot = ToyRobot(0, 3, "EAST")
     robot.move()
     self.assertEqual(robot.x, 1)
     self.assertEqual(robot.y, 3)
     self.assertEqual(robot.direction, "EAST")
コード例 #7
0
 def test_move_robot_adds_1_step_towards_south(self):
     robot = ToyRobot(0, 3, "SOUTH")
     robot.move()
     self.assertEqual(robot.x, 0)
     self.assertEqual(robot.y, 2)
     self.assertEqual(robot.direction, "SOUTH")
コード例 #8
0
 def test_move_robot_adds_1_step_towards_north(self):
     robot = ToyRobot(0, 3, "NORTH")
     robot.move()
     self.assertEqual(robot.x, 0)
     self.assertEqual(robot.y, 4)
     self.assertEqual(robot.direction, "NORTH")
コード例 #9
0
	def test_move(self):
		toyRobot = ToyRobot()

		toyRobot.place(0, 0, Direction.NORTH)

		toyRobot.move()
		self.assertEqual(toyRobot.report(), "1, 0, NORTH")

		toyRobot.move()
		self.assertEqual(toyRobot.report(), "2, 0, NORTH")

		toyRobot.move()
		self.assertEqual(toyRobot.report(), "3, 0, NORTH")

		toyRobot.move()
		self.assertEqual(toyRobot.report(), "4, 0, NORTH")

		toyRobot.move()
		self.assertEqual(toyRobot.report(), "4, 0, NORTH")  # validate not going over the edge

		toyRobot.place(0, 0, Direction.EAST)

		toyRobot.move()
		self.assertEqual(toyRobot.report(), "0, 1, EAST")

		toyRobot.move()
		self.assertEqual(toyRobot.report(), "0, 2, EAST")

		toyRobot.move()
		self.assertEqual(toyRobot.report(), "0, 3, EAST")

		toyRobot.move()
		self.assertEqual(toyRobot.report(), "0, 4, EAST")

		toyRobot.move()
		self.assertEqual(toyRobot.report(), "0, 4, EAST")  # validate not going over the edge

		toyRobot.place(0, 0, Direction.WEST)

		toyRobot.move()
		self.assertEqual(toyRobot.report(), "0, 0, WEST")  # validate not going over the edge

		toyRobot.place(0, 0, Direction.SOUTH)

		toyRobot.move()
		self.assertEqual(toyRobot.report(), "0, 0, SOUTH")  # validate not going over the edge