Beispiel #1
0
 def test_place_with_valid_coordinates_and_direction_places_robot_in_valid_place(
         self):
     robot = ToyRobot()
     robot.place(3, 3, "NORTH")
     self.assertEqual(robot.x, 3)
     self.assertEqual(robot.y, 3)
     self.assertEqual(robot.direction, "NORTH")
Beispiel #2
0
	def test_place(self):
		toyRobot = ToyRobot()
		toyRobot.place(0, 0, Direction.NORTH)
		self.assertEqual(toyRobot.report(), "0, 0, NORTH")

		toyRobot.place(1, 1, Direction.WEST)
		self.assertEqual(toyRobot.report(), "1, 1, WEST")

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

		toyRobot.place(1, 2, Direction.SOUTH)
		self.assertEqual(toyRobot.report(), "1, 2, SOUTH")

		toyRobot.place(-1, 2, Direction.SOUTH)
		self.assertNotEqual(toyRobot.report(), "-1, 2, SOUTH")
Beispiel #3
0
	def test_right(self):
		toyRobot = ToyRobot()

		toyRobot.right() # right must not work before place
		self.assertEqual(toyRobot.report(), None)

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

		toyRobot.right()
		self.assertEqual(toyRobot.report(), "0, 0, EAST")

		toyRobot.right()
		self.assertEqual(toyRobot.report(), "0, 0, SOUTH")

		toyRobot.right()
		self.assertEqual(toyRobot.report(), "0, 0, WEST")

		toyRobot.right()
		self.assertEqual(toyRobot.report(), "0, 0, NORTH")
Beispiel #4
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
Beispiel #5
0
 def test_place_with_invalid_direction_raises_error(self):
     robot = ToyRobot()
     with self.assertRaises(InputError):
         robot.place(0, 3, "DOWN")
Beispiel #6
0
 def test_place_with_invalid_coordinates_raises_error(self):
     robot = ToyRobot()
     with self.assertRaises(InputError):
         robot.place(6, 3, "WEST")
Beispiel #7
0
	def test__is_placed(self):
		toyRobot = ToyRobot()
		self.assertFalse(toyRobot._is_placed)

		toyRobot.place(0, 0, Direction.NORTH)
		self.assertTrue(toyRobot._is_placed)