コード例 #1
0
ファイル: test.py プロジェクト: niroo96/Toy-Robot-Simulator
    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)")
コード例 #2
0
ファイル: test.py プロジェクト: niroo96/Toy-Robot-Simulator
    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)")
コード例 #3
0
ファイル: test.py プロジェクト: niroo96/Toy-Robot-Simulator
    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
コード例 #4
0
        # COMMAND + 3 Parameters [PLACE {X} {Y} {Direction}]
        if len(words) == 4:
            try:
                xCoordinate = int(words[1])
                yCoordinate = int(words[2])
                direction = words[3]

                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"