コード例 #1
0
	def test_topCoordinates(self):
		roomObj = room(5, 5)
		self.assertEqual(roomObj.topCoordinates, (5, 5))
		clearSingleton()
		with self.assertRaises(Exception) as context:
			roomObj = room(5, -5)
		self.assertTrue('Improper Input' in str(context.exception))
		clearSingleton()
コード例 #2
0
	def test_navigate(self):
		roomObj = room(5, 5)

		insectObj1 = insect(room=roomObj, initialX=1, initialY=2, initialDirection="N")
		insectObj1.navigate("LFLFLFLFF")
		self.assertEqual(insectObj1.coordinates, (1, 3, "N"))

		with self.assertRaises(Exception) as context:
			insectObj2 = insect(room=roomObj, initialX=6, initialY=2, initialDirection="N")
		self.assertTrue('out of Bounds of Room' in str(context.exception))
コード例 #3
0
ファイル: run.py プロジェクト: hitesh-cd/robot-insect-problem
from robots import insect
from buildings import room

if __name__ == "__main__":
	try:
		roomX, roomY = map(int, raw_input().strip().split(" "))
		roomObj = room(roomX, roomY)
		while True:
			insectCoordinates = raw_input().strip().split(" ")
			if len(insectCoordinates) != 3:
				break
			insectInstructions = raw_input()
			if insectInstructions == "":
				break
			insectObj = insect(room=roomObj, initialX=int(insectCoordinates[0]),
							   initialY=int(insectCoordinates[1]), initialDirection=insectCoordinates[2])
			insectObj.navigate(insectInstructions)
			finalCoordinates = insectObj.coordinates
			print finalCoordinates[0], finalCoordinates[1], finalCoordinates[2]
	except Exception as e:
		print e, " some problem"  # just log it
コード例 #4
0
	def test_bottomCoordinates(self):
		roomObj = room(5, 5)
		self.assertEqual(roomObj.bottomCoordinates, (0, 0))
		clearSingleton()
コード例 #5
0
	def test_coordinates(self):
		roomObj = room(5, 5)
		insectObj1 = insect(room=roomObj, initialX=1, initialY=2, initialDirection="N")
		self.assertEqual(insectObj1.coordinates, (1, 2, "N"))