def test_command_little_journey(self): landscape = ((0, 0, 0, 1, 0, 0), (0, 1, 0, 0, 0, 0), (0, 0, 0, 1, 0, 0), (0, 0, 0, 0, 0, 1), (0, 0, 1, 1, 1, 0), (0, 0, 0, 0, 0, 0)) mars = Rover(landscape, (0, 0), Direction.E) # We move two to the right, but the next one finds an obstacle mars.command("F-F-F") self.assertTrue(mars.is_direction(Direction.E)) self.assertTrue(mars.is_position((0,2))) # We turn to the South and move three spaces, the next is an obstacle mars.command("R-F-F-F-F") self.assertTrue(mars.is_direction(Direction.S)) self.assertTrue(mars.is_position((3,2))) # We turn to the West and move backwards two spaces, the next is an obstacle mars.command("R-B-B-B") self.assertTrue(mars.is_direction(Direction.W)) self.assertTrue(mars.is_position((3,4)))
def test_turn_right(self): mars = Rover(self.landscape, (0, 0), Direction.N) mars.turn_right() self.assertTrue(mars.is_direction(Direction.E)) mars.turn_right() self.assertTrue(mars.is_direction(Direction.S)) mars.turn_right() self.assertTrue(mars.is_direction(Direction.W)) mars.turn_right() self.assertTrue(mars.is_direction(Direction.N))
def test_move_stops_on_edge_overflow(self): mars = Rover(self.landscape, (5, 5), Direction.E) self.assertFalse(mars.move_forward()) self.assertTrue(mars.is_position((5, 5))) mars.turn_left() self.assertTrue(mars.is_direction(Direction.N)) self.assertFalse(mars.move_backwards()) self.assertTrue(mars.is_position((5, 5)))
def test_little_journey(self): landscape = ((0, 0, 0, 1, 0, 0), (0, 1, 0, 0, 0, 0), (0, 0, 0, 1, 0, 0), (0, 0, 0, 0, 0, 1), (0, 0, 1, 1, 1, 0), (0, 0, 0, 0, 0, 0)) mars = Rover(landscape, (0, 0), Direction.E) # We move two to the right, but the next one finds an obstacle self.assertTrue(mars.move_forward()) self.assertTrue(mars.move_forward()) self.assertFalse(mars.move_forward()) self.assertTrue(mars.is_direction(Direction.E)) self.assertTrue(mars.is_position((0,2))) # We turn to the South and move three spaces, the next is an obstacle mars.turn_right() self.assertTrue(mars.move_forward()) self.assertTrue(mars.move_forward()) self.assertTrue(mars.move_forward()) self.assertFalse(mars.move_forward()) self.assertTrue(mars.is_direction(Direction.S)) self.assertTrue(mars.is_position((3,2))) # We turn to the West and move backwards two spaces, the next is an obstacle mars.turn_right() self.assertTrue(mars.move_backwards()) self.assertTrue(mars.move_backwards()) self.assertFalse(mars.move_backwards()) self.assertTrue(mars.is_direction(Direction.W)) self.assertTrue(mars.is_position((3,4)))
def test_command_only_moves_till_it_stops(self): landscape = ((0, 0, 0, 1, 0, 0), (0, 1, 0, 0, 0, 0), (0, 0, 0, 1, 0, 0), (0, 0, 0, 0, 0, 1), (0, 0, 1, 1, 1, 0), (0, 0, 0, 0, 0, 0)) mars = Rover(landscape, (0, 0), Direction.E) # We move two to the right, but the next one finds an obstacle mars.command("F-F-F") self.assertTrue(mars.is_direction(Direction.E)) self.assertTrue(mars.is_position((0,2)))
def test_can_init_with_given_values(self): mars = Rover(self.landscape, (0, 0), Direction.N) self.assertTrue(mars.is_direction(Direction.N)) self.assertTrue(mars.is_position((0, 0)))