예제 #1
0
 def testName05(self):
     """ Testing move around lower left border"""
     toy_robot = ToyRobot()
     toy_robot.place(1, 1, 'SOUTH')
     self.assertEqual(coord(toy_robot), (1, 1, 'SOUTH'))
     toy_robot.move()
     self.assertEqual(coord(toy_robot), (1, 0, 'SOUTH'))
     toy_robot.move()
     self.assertEqual(coord(toy_robot), (1, 0, 'SOUTH'))
     toy_robot.rotate_right()
     self.assertEqual(coord(toy_robot), (1, 0, 'WEST'))
     toy_robot.move()
     self.assertEqual(coord(toy_robot), (0, 0, 'WEST'))
     toy_robot.move()
     self.assertEqual(coord(toy_robot), (0, 0, 'WEST'))
예제 #2
0
 def testName04(self):
     """ Testing move around upper right border """
     toy_robot = ToyRobot()
     toy_robot.place(4, 4, 'NORTH')
     self.assertEqual(coord(toy_robot), (4, 4, 'NORTH'))
     toy_robot.move()
     self.assertEqual(coord(toy_robot), (4, 5, 'NORTH'))
     toy_robot.move()
     self.assertEqual(coord(toy_robot), (4, 5, 'NORTH'))
     toy_robot.rotate_right()
     self.assertEqual(coord(toy_robot), (4, 5, 'EAST'))
     toy_robot.move()
     self.assertEqual(coord(toy_robot), (5, 5, 'EAST'))
     toy_robot.move()
     self.assertEqual(coord(toy_robot), (5, 5, 'EAST'))
예제 #3
0
    def test_movetest(self):
        robot = ToyRobot()

        robot.place(3, 2, "WEST")

        robot.move()
        self.assertEqual(robot.report(), "(2, 2, WEST)")

        robot.move()
        self.assertEqual(robot.report(), "(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)")
예제 #4
0
파일: start.py 프로젝트: tmatkovic/ToyRobot
    text_upper = text_entered.upper()
    # split user input to a list
    words = text_upper.split()

    # first word should contain command
    if words[0] == "PLACE":
        # command + three parameters - PLACE X Y FACING
        if len(words) == 4:
            try:
                xCoord = int(words[1])
                yCoord = int(words[2])
                facing = words[3]

                robot.place(xCoord, yCoord, facing)
            except ValueError:
                print("Invalid command parameters")
        else:
            print("Invalid 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] == "QUIT":
        condition = False
    else:
        print("Unknown command...")