def test_example2(self): robot = Robot() robot.place(0, 0, "NORTH") self.assertEqual(robot.report(), "(0, 0, NORTH)") robot.left() self.assertEqual(robot.report(), "(0, 0, WEST)") robot.report() self.assertEqual(robot.report(), "(0, 0, WEST)")
def test_example1(self): robot = Robot() robot.place(0, 0, "NORTH") self.assertEqual(robot.report(), "(0, 0, NORTH)") robot.move() self.assertEqual(robot.report(), "(0, 1, NORTH)") robot.report() self.assertEqual(robot.report(), "(0, 1, NORTH)")
def test_movetest(self): robot = Robot() robot.place(1, 2, "WEST") robot.move() self.assertEqual(robot.report(), "(0, 2, WEST)") # shouldn't go more in west direction robot.move() self.assertEqual(robot.report(), "(0, 2, WEST)")
def test_placetest(self): robot = Robot() robot.place(2, 2, "EAST") self.assertEqual(robot.report(), "(2, 2, EAST)") # more than board bounds robot.place(1, 6, "NORTH") self.assertNotEqual(robot.report(), "(1, 6, NORTH)") robot.place(0, 0, "NORTH") self.assertEqual(robot.report(), "(0, 0, NORTH)")
def test_lefttest(self): robot = Robot() robot.place(4, 4, "EAST") # turn around full circle robot.left() self.assertEqual(robot.report(), "(4, 4, NORTH)") robot.left() self.assertEqual(robot.report(), "(4, 4, WEST)") robot.left() self.assertEqual(robot.report(), "(4, 4, SOUTH)") robot.left() self.assertEqual(robot.report(), "(4, 4, EAST)")
def test_righttest(self): robot = Robot() robot.place(0, 3, "EAST") # turn around full circle robot.right() self.assertEqual(robot.report(), "(0, 3, SOUTH)") robot.right() self.assertEqual(robot.report(), "(0, 3, WEST)") robot.right() self.assertEqual(robot.report(), "(0, 3, NORTH)") robot.right() self.assertEqual(robot.report(), "(0, 3, EAST)")
def test_example3(self): robot = Robot() robot.place(1, 2, "EAST") self.assertEqual(robot.report(), "(1, 2, EAST)") robot.move() self.assertEqual(robot.report(), "(2, 2, EAST)") robot.move() self.assertEqual(robot.report(), "(3, 2, EAST)") robot.left() self.assertEqual(robot.report(), "(3, 2, NORTH)") robot.move() self.assertEqual(robot.report(), "(3, 3, NORTH)") robot.report() self.assertEqual(robot.report(), "(3, 3, NORTH)") # Code by Niroo Arjuna
robot.place(xCoordinate, yCoordinate, direction) except ValueError: print( "Error: Invalid command parameters, please enter valid command parameters" ) else: print("Error: Invalid syntax, please enter valid syntax") elif words[0] == "MOVE": robot.move() elif words[0] == "LEFT": robot.left() elif words[0] == "RIGHT": robot.right() elif words[0] == "REPORT": robot.report() elif words[0] == "AVOID": if len(words) == 3: try: xCoordinate = int(words[1]) yCoordinate = int(words[2]) robot.avoid(xCoordinate, yCoordinate) except ValueError: print( "Error: Invalid command parameters, please enter valid command parameters" ) else: print("Error: Invalid syntax, please enter valid syntax") elif words[0] == "QUIT": condition = False else: