Exemplo n.º 1
0
    def test_invalid_instructions(self):
        plateau = Plateau(5, 5)
        ctrl = Controller(plateau)
        ctrl.land_rover(x=2, y=2, heading=c.WEST, name='rover1')

        self.assertRaises(ValueError,
                          ctrl.instructions,
                          rover_name='rover1',
                          instructions_str='XYRMMRMRRM')
Exemplo n.º 2
0
    def test_when_rover_lands_with_valid_params(self):
        plateau = Plateau(5, 5)
        ctrl = Controller(plateau)
        ctrl.land_rover(x=2, y=2, heading=c.WEST, name='rover1')

        rover = ctrl.dict_rover['rover1']

        self.assertEqual(rover.x_pos, 2)
        self.assertEqual(rover.y_pos, 2)
        self.assertEqual(rover.heading, c.WEST)
Exemplo n.º 3
0
    def test_instruction_without_rover_landed(self):
        plateau = Plateau(5, 5)
        ctrl = Controller(plateau)

        self.assertRaises(InvalidRover,
                          ctrl.instructions,
                          rover_name='rover1',
                          instructions_str='MMRMMRMRRM')
Exemplo n.º 4
0
    def test_valid_instruction(self):
        plateau = Plateau(5, 5)
        ctrl = Controller(plateau)

        ctrl.land_rover(x=3, y=3, heading=c.EAST, name='rover1')
        ctrl.instructions('rover1', 'MMRMMRMRRM')
        rover1 = ctrl.dict_rover['rover1']

        ctrl.land_rover(x=1, y=2, heading=c.NORTH, name='rover2')
        ctrl.instructions('rover2', 'LMLMLMLMM')
        rover2 = ctrl.dict_rover['rover2']

        self.assertEquals(rover1.x_pos, 5)
        self.assertEquals(rover1.y_pos, 1)
        self.assertEquals(rover1.heading, c.EAST)

        self.assertEquals(rover2.x_pos, 1)
        self.assertEquals(rover2.y_pos, 3)
        self.assertEquals(rover2.heading, c.NORTH)
Exemplo n.º 5
0
    def test_instruction_causing_collision(self):
        plateau = Plateau(5, 5)
        ctrl = Controller(plateau)
        ctrl.land_rover(x=2, y=2, heading=c.WEST, name='rover1')

        ctrl.land_rover(x=3, y=2, heading=c.WEST, name='rover2')

        self.assertRaises(CollisionException,
                          ctrl.instructions,
                          rover_name='rover2',
                          instructions_str='M')
Exemplo n.º 6
0
def main():
    command = ''
    quit = 'quit'
    report = ''

    ctrl = Controller(plateau=None)

    init_msg()

    try:
        while command.strip() != quit:
            command = raw_input()

            # Remove whitespaces, put command to lower case and
            # break it into prefix (ex: plateau, landing, instruction)
            # and suffix ( params ex: '1 2 N', 'LMLMLMLMM')
            command_parts = command.strip().lower().split(':')

            if len(command_parts) == 2:
                # Plateau dimensions setting
                # ex: 'plateau: 5 5'
                if command_parts[0].endswith(c.PLATEAU):
                    plateau_input_handle(command_parts, ctrl)

                elif command_parts[0].endswith(c.LANDIND):
                    landing_input_handle(command_parts, ctrl)

                elif command_parts[0].endswith(c.INSTRUCTIONS):
                    instruction_input_handle(command_parts, ctrl)

            elif command == report:
                resume_rovers(ctrl.dict_rover)

            elif command.strip() != quit:
                print "'{}' is not a valid command. " \
                      "Please check the syntax.".format(command)
        resume_rovers(ctrl.dict_rover)
        print "bye :)"
    except EOFError:
        pass
Exemplo n.º 7
0
    def test_overwrite_plateau(self):
        plateau = Plateau(5, 5)
        ctrl = Controller(plateau)

        self.assertRaises(PlateauException, ctrl.set_plateau, x=5, y=5)
Exemplo n.º 8
0
    def test_creating_valid_plateau(self):
        ctrl = Controller(None)
        ctrl.set_plateau(5, 5)

        self.assertEquals(ctrl.plateau.x_max, 5)
        self.assertEquals(ctrl.plateau.y_max, 5)
Exemplo n.º 9
0
 def test_instruction_without_plateau(self):
     ctrl = Controller(None)
     self.assertRaises(InvalidRover,
                       ctrl.instructions,
                       rover_name='rover1',
                       instructions_str='MMRMMRMRRM')
Exemplo n.º 10
0
    def test_landing_without_plateau(self):
        ctrl = Controller(None)

        self.assertRaises(ValueError, ctrl.land_rover, x=1, y=2,
                          heading=c.NORTH, name='rover1')
Exemplo n.º 11
0
 def test_landing_collision_position(self):
     plateau = Plateau(5, 5)
     ctrl = Controller(plateau)
     ctrl.land_rover(x=2, y=2, heading=c.WEST, name='rover1')
     self.assertRaises(CollisionException, ctrl.land_rover, x=2, y=2,
                       heading=c.WEST, name='rover2')
Exemplo n.º 12
0
 def test_when_rover_lands_with_not_valid_heading(self):
     plateau = Plateau(5, 5)
     ctrl = Controller(plateau)
     self.assertRaises(ValueError, ctrl.land_rover, x=2, y=2,
                       heading='X', name='rover1')
Exemplo n.º 13
0
 def test_landing_outside_y_plateau_dimension(self):
     plateau = Plateau(5, 5)
     ctrl = Controller(plateau)
     self.assertRaises(InvalidPlateauBounds, ctrl.land_rover, x=2, y=10,
                       heading=c.NORTH, name='rover1')