예제 #1
0
class GridTestCase(unittest.TestCase):

	def setUp(self):
		self.robot = Robot(Position('3', '2', 'N'))
		self.robot.processInstruction = MagicMock()

		self.grid = Grid([3,2])

	def test_initGrid(self):
		self.assertEqual(self.grid.size, [3,2])

	def test_isOutOfBounds(self):
		outOfBounds = self.grid.isOutOfBounds(Position('4', '2', 'N'))

		self.assertTrue(outOfBounds)

	def test_processRobotInstruction(self):
		self.grid.processRobot(self.robot, 'RFRF')

		self.assertEqual(self.robot.processInstruction.call_count, 4)

	def test_robotOutOfBounds(self):
		self.robot.position = Position(4, 2, 'N')

		self.grid.processRobot(self.robot, 'F')

		self.assertTrue(self.grid.lastRobotLost)
		self.assertEqual(len(self.grid.lostPositions), 1)
예제 #2
0
def readInput(path):
	fileInput = open(path)

	gridSize = [int(i) for i in (fileInput.readline().split())]
	grid = Grid(gridSize)

	while True:
		nextRobotInput = list(islice(fileInput, 3))
		if not nextRobotInput:
			break
		
		robotPosition = Position(*nextRobotInput[0].split())
		robotInstructions = nextRobotInput[1]

		grid.processRobot(Robot(robotPosition), robotInstructions)

		if grid.lastRobotLost:
			print "%s LOST" % grid.lastRobotPosition
		else:
			print grid.lastRobotPosition