Пример #1
0
    def test_it_stops_before_reaching_distant_obstacle(self):
        marsrover = MarsRover(rocks=[(0, 2)])
        try:
            marsrover.execute('f')
            marsrover.execute('f')
        except ReachedObstacleError:
            pass

        self.assertEqual(marsrover.position, (0, 1))
Пример #2
0
    def test_it_starts_at_0_0(self):
        marsrover = MarsRover()

        self.assertEquals(marsrover.position, (0, 0))
Пример #3
0
    def test_it_rotate_to_west_when_order_is_l_and_orientation_is_n(self):
        marsrover = MarsRover(orientation='N')

        marsrover.execute('l')

        self.assertEqual(marsrover.orientation, 'W')
Пример #4
0
def test_rover_can_move_around_obstacle():
    grid = Grid(10, 10, Position(0, 4))
    curiosity = MarsRover(grid)
    curiosity.execute("MMMMMMRMLMMLMRM")
    assert curiosity.get_location() == "0:6:N"
Пример #5
0
    def test_it_returns_to_100_when_x_limit_is_crossed(self):
        marsrover = MarsRover(x=0, orientation='E', orders=['b'])

        self.assertEqual(marsrover.position, (100, 0))
Пример #6
0
    def test_it_works_when_lot_of_orders_given(self):
        marsrover = MarsRover(orders=[
            'f', 'f', 'r', 'f', 'f', 'l', 'b', 'b'
        ])

        self.assertEqual(marsrover.position, (2, 0))
Пример #7
0
    def test_it_calls_check_order_parameter(self):
        patched_check = self.patch('check_order_parameter')

        MarsRover()

        self.assertTrue(patched_check.called)
Пример #8
0
    def test_it_takes_starting_orientation(self):
        marsrover = MarsRover(orientation='S')

        self.assertEquals(marsrover.orientation, 'S')
Пример #9
0
    def test_it_moves_back_when_order_is_b(self):
        marsrover = MarsRover(y=1)

        marsrover.execute('b')

        self.assertEquals(marsrover.position, (0, 0))
Пример #10
0
    def test_it_moves_front_when_order_is_f(self):
        marsrover = MarsRover()

        marsrover.execute('f')

        self.assertEquals(marsrover.position, (0, 1))
Пример #11
0
 def test_raises_exception_when_reaching_obstacle_and_limit_west(self):
     with self.assertRaises(ReachedObstacleError):
         MarsRover(orientation='W', orders=['f'], rocks=[(100, 0)])
Пример #12
0
 def test_it_raises_exception_when_reaching_obstacle_and_limit_north(self):
     with self.assertRaises(ReachedObstacleError):
         MarsRover(y=100, orders=['f'], rocks=[(0, 0)])
Пример #13
0
def curiosity():
    return MarsRover(Grid(10, 10))
Пример #14
0
def test_rover_can_wrap_around_different_sized_grids():
    grid = Grid(5, 8)
    curiosity = MarsRover(grid)
    curiosity.execute("LMLM")
    assert curiosity.get_location() == "4:7:S"
Пример #15
0
    def test_it_takes_starting_position(self):
        marsrover = MarsRover(3, 2)

        self.assertEquals(marsrover.position, (3, 2))
Пример #16
0
    def test_it_turns_right_when_order_is_r(self):
        marsrover = MarsRover()

        marsrover.execute('r')

        self.assertEquals(marsrover.orientation, 'E')
Пример #17
0
    def test_it_starts_facing_north(self):
        marsrover = MarsRover()

        self.assertEquals(marsrover.orientation, 'N')
Пример #18
0
    def test_it_turns_left_when_order_is_l(self):
        marsrover = MarsRover()

        marsrover.execute('l')

        self.assertEquals(marsrover.orientation, 'W')
Пример #19
0
    def test_it_calls_check_position_parameters(self):
        patched_check = self.patch('check_position_parameters')

        MarsRover()

        self.assertTrue(patched_check.called)
Пример #20
0
    def test_it_moves_front_when_order_is_f_and_orientation_is_w(self):
        marsrover = MarsRover(orientation='W', x=1)

        marsrover.execute('f')

        self.assertEquals(marsrover.position, (0, 0))
Пример #21
0
    def test_it_calls_execute_with_orders(self):
        execute = self.patch('MarsRover.execute')

        MarsRover(orders=['f'])

        execute.assert_called_with('f')
Пример #22
0
    def test_it_moves_back_when_order_is_b_and_orientation_is_e(self):
        marsrover = MarsRover(orientation='E', x=1)

        marsrover.execute('b')

        self.assertEquals(marsrover.position, (0, 0))
Пример #23
0
    def test_it_returns_to_100_when_y_limit_is_crossed(self):
        marsrover = MarsRover(y=0, orders=['b'])

        self.assertEqual(marsrover.position, (0, 100))
Пример #24
0
    def test_it_rotate_to_north_when_order_is_r_and_orientation_is_w(self):
        marsrover = MarsRover(orientation='W')

        marsrover.execute('r')

        self.assertEqual(marsrover.orientation, 'N')
Пример #25
0
 def test_it_raises_exception_when_reaching_obstacle(self):
     with self.assertRaises(ReachedObstacleError):
         MarsRover(orders=['f'], rocks=[(0, 1)])
Пример #26
0
def test_rover_cannot_move_through_obstacle():
    grid = Grid(10, 10, Position(0, 4))
    curiosity = MarsRover(grid)
    curiosity.execute("MMMMMM")
    assert curiosity.get_location() == "O:0:3:N"