def test_first_input(self): coordinate = Coordinate(1, 2) plateau = Plateau(5, 5) rover = Rover(coordinate, North()) RoverManager(plateau, rover).perform("LMLMLMLMM") self.assertEqual(rover.coordinate, Coordinate(1, 3)) self.assertEqual(rover.direction, North())
def test_second_input(self): coordinate = Coordinate(3, 3) plateau = Plateau(5, 5) rover = Rover(coordinate, East()) RoverManager(plateau, rover).perform("MMRMMRMRRM") self.assertEqual(rover.coordinate, Coordinate(5, 1)) self.assertEqual(rover.direction, East())
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')
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')
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)
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')
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)
def setUp(self): self.coordinate = Coordinate(1, 2) self.plateau = Plateau(5, 5)
def test_basic_methods(): pl = Plateau() pl.is_in_range(0, 0) pl.is_position_available()
def test_overwrite_plateau(self): plateau = Plateau(5, 5) ctrl = Controller(plateau) self.assertRaises(PlateauException, ctrl.set_plateau, x=5, y=5)
def setUp(self): self.plateau = Plateau() self.plateau.position_x = 5 self.plateau.position_y = 5
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')
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')
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')