def testName01(self):
        """ Testing ToyRobotInterpreter place() handler """
        toy = ToyRobot()
        toy.place = Mock()
        tri = ToyRobotInterpreter(toy)

        tri.cmd_PLACE_handler('1,2,NORTH')
        toy.place.assert_called_once_with(1, 2, 'NORTH')
    def testName02(self):
        """ Testing multiple ToyRobotInterpreter place() calls """
        toy = ToyRobot()
        toy.place = Mock()
        tri = ToyRobotInterpreter(toy)
        tri.cmd_PLACE_handler('1,2,NORTH')
        tri.cmd_PLACE_handler('3,4,EAST')

        expected = [call(1, 2, 'NORTH'), call(3, 4, 'EAST')]
        self.assertEqual(toy.place.call_args_list, expected,
                         "method_calls not initialised correctly")
예제 #3
0
    def testName02(self):
        """ Testing place between bounds """
        toy_robot = ToyRobot()
        toy_robot.place(1, 2, 'NORTH')
        self.assertEqual(coord(toy_robot), (1, 2, 'NORTH'))

        toy_robot.place(6, 7, 'NORTH')
        self.assertEqual(coord(toy_robot), (5, 5, 'NORTH'))

        toy_robot.place(-6, -7, 'NORTH')
        self.assertEqual(coord(toy_robot), (0, 0, 'NORTH'))
예제 #4
0
 def testName03(self):
     """ Testing rotate """
     toy_robot = ToyRobot()
     toy_robot.place(1, 1, 'NORTH')
     self.assertEqual(toy_robot.curr_facing, 'NORTH')
 
     for f in ('WEST', 'SOUTH', 'EAST', 'NORTH'):
         toy_robot.rotate_left()
         self.assertEqual(toy_robot.curr_facing, f)
 
     for f in ('EAST', 'SOUTH', 'WEST', 'NORTH'):
         toy_robot.rotate_right()
         self.assertEqual(toy_robot.curr_facing, f)
예제 #5
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)")
예제 #6
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)")
예제 #7
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)")
예제 #8
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)")
예제 #9
0
파일: start.py 프로젝트: tmatkovic/ToyRobot
from toyrobot import ToyRobot

robot = ToyRobot()

condition = True

while condition:
    text_entered = input("Enter new command (QUIT for end): ")

    # convert user input to uppercase, so command comparison is case insensitive
    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":
예제 #10
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'))
예제 #11
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'))
예제 #12
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')
예제 #13
0
#!/usr/bin/env python3

from sys import stdin

from toyrobot import ToyRobot
from toyrobotinterpreter import ToyRobotInterpreter
from inputparser import InputParser

if __name__ == '__main__':
    toy_robot = ToyRobot()
    inputparser = InputParser(ToyRobotInterpreter(toy_robot))

    for line in stdin:
        line = line.rstrip()
        if line == ':q':
            print('exiting..')
            break
        inputparser.process_line(line)