Пример #1
0
    def test_invalid_height(self):
        with self.assertRaises(ValueError) as e:
            width, height = 10, -1
            plateau = Plateau(width, height)

        self.assertEqual(type(e.exception), ValueError)
        self.assertEqual(str(e.exception), "Invalid height: {}".format(height))
Пример #2
0
    def test_invalid_width(self):
        with self.assertRaises(ValueError) as e:
            width, height = -1, 10
            plateau = Plateau(width, height)

        self.assertEqual(type(e.exception), ValueError)
        self.assertEqual(str(e.exception), "Invalid width: {}".format(width))
Пример #3
0
 def test_spin_right(self):
     plateau = Plateau(5, 5)
     position = Position(1, 2)
     initial_heading = 'N'
     rover = Rover(plateau, position, initial_heading)
     self.assertEqual(rover.heading, initial_heading)
     rover.spin_right()
     self.assertEqual(rover.heading, rover.DIRECTIONS[initial_heading]['R'])
Пример #4
0
    def test___str__(self):
        plateau = Plateau(5, 5)
        position = Position(1, 2)

        rover = Rover(plateau, position, 'N')
        self.assertEqual(
            str(rover), '{} {} {}'.format(rover.position.x, rover.position.y,
                                          rover.heading))
Пример #5
0
 def test_move_east(self):
     plateau = Plateau(5, 5)
     position = Position(1, 2)
     heading = 'E'
     rover = Rover(plateau, position, heading)
     self.assertEqual(rover.position, position)
     res = rover.move()
     self.assertEqual(res, True)
     self.assertEqual(rover.position, Position(2, 2))
Пример #6
0
    def test_process(self):
        plateau = Plateau(5, 5)
        position = Position(1, 2)

        rover = Rover(plateau, position, 'N')
        rover.process('LMLMLMLMM')

        self.assertEqual(rover.position, Position(1, 3))
        self.assertEqual(rover.heading, 'N')
Пример #7
0
    def test_current_position(self):
        plateau = Plateau(5, 5)
        position = Position(1, 2)

        rover = Rover(plateau, position, 'N')
        self.assertEqual(
            rover.current_position,
            '{} {} {}'.format(rover.position.x, rover.position.y,
                              rover.heading))
Пример #8
0
    def test_run_command_success(self):
        plateau = Plateau(5, 5)
        position = Position(1, 2)

        rover = Rover(plateau, position, 'N')
        rover.run_command('L')

        self.assertEqual(rover.position, Position(1, 2))
        self.assertEqual(rover.heading, 'W')
Пример #9
0
    def move_not_available(self):
        plateau = Plateau(5, 5)
        position = Position(1, 8)
        initial_heading = 'N'
        rover = Rover(plateau, position, initial_heading)
        with self.assertRaises(Exception) as e:
            res = rover.move()

        self.assertEqual(type(e.exception), Exception)
        self.assertEqual(str(e.exception), "Move not available")
Пример #10
0
    def test_run_command_unrecognized_command(self):
        plateau = Plateau(5, 5)
        position = Position(1, 2)

        rover = Rover(plateau, position, 'N')
        command = 'A'
        with self.assertRaises(Exception) as e:
            rover.run_command(command)

        self.assertEqual(type(e.exception), Exception)
        self.assertEqual(str(e.exception),
                         "Unrecognized command: {0}".format(command))
Пример #11
0
    def test___str__(self):
        plateau = Plateau(5, 5)
        position = Position(1, 2)

        rover = Rover(plateau, position, 'N')
        self.assertEqual(
            str(rover.plateau), '0 0 0 0 0 0\n'
            '0 0 0 0 0 0\n'
            '0 0 0 0 0 0\n'
            '0 1 0 0 0 0\n'
            '0 0 0 0 0 0\n'
            '0 0 0 0 0 0\n')
Пример #12
0
def main():
    plateau = Plateau(5, 5)
    position = Position(1, 2)
    # Create rover instance
    rovers = Rovers(plateau, position, Rovers.directions.get('N'))
    instructions = input('Enter Instructions:')

    rovers.validate_instruction(instructions)
    print(rovers)
    rovers.set_position(3, 3, Rovers.directions.get('E'))
    instructions_new = input('Enter New Instructions:')
    rovers.validate_instruction(instructions_new)
    print(rovers)
Пример #13
0
def main():
    input_plateau = input().split()
    plateau_x, plateau_y = int(input_plateau[0]), int(input_plateau[1])
    plateau = Plateau(plateau_x, plateau_y)
    rovers = []
    while True:
        input_rover = input().split()
        if not input_rover:
            break
        rover_x, rover_y, heading = int(input_rover[0]), int(
            input_rover[1]), input_rover[2]
        position = Position(rover_x, rover_y)
        rover = Rover(plateau, position, heading)
        commands = input()
        rover.process(commands)
        rovers.append(rover)

    for rover in rovers:
        print(rover)
Пример #14
0
 def test_move_available_east_inside(self):
     width, height = 10, 10
     plateau = Plateau(width, height)
     position, heading = Position(5, 5), 'E'
     self.assertEqual(plateau.move_available(position, heading), True)
Пример #15
0
    def test_valid(self):
        plateau = Plateau(7, 10)

        self.assertEqual(plateau.width - 1, 7)
        self.assertEqual(plateau.height - 1, 10)
Пример #16
0
 def test_move_not_available_east_boundary(self):
     width, height = 10, 10
     plateau = Plateau(width, height)
     position, heading = Position(10, 5), 'E'
     self.assertEqual(plateau.move_available(position, heading), False)