예제 #1
0
    def test_placetest(self):
        robot = ToyRobot()

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

        # more than board bounds
        robot.place(1, 6, "SOUTH")
        self.assertNotEqual(robot.report(), "(1, 6, SOUTH)")

        robot.place(0, 0, "SOUTH")
        self.assertEqual(robot.report(), "(0, 0, SOUTH)")
예제 #2
0
    def test_righttest(self):
        robot = ToyRobot()

        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)")
예제 #3
0
    def test_lefttest(self):
        robot = ToyRobot()

        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)")
예제 #4
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)")
예제 #5
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...")
예제 #6
0
 def testName01(self, mock_stdout):
     """ Testing report formatting """
     toy_robot = ToyRobot()
     toy_robot.place(1, 2, 'NORTH')
     toy_robot.report()
     self.assertEqual(mock_stdout.getvalue().rstrip('\r\n'), '1, 2, NORTH')