Exemple #1
0
    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)))
Exemple #2
0
    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)))
Exemple #3
0
 def test_move_stops_on_obstacle(self):
     mars = Rover(self.landscape, (1, 3), Direction.N)
     self.assertFalse(mars.move_forward())
     self.assertTrue(mars.is_position((1, 3)))
     self.assertFalse(mars.move_backwards())
     self.assertTrue(mars.is_position((1, 3)))
Exemple #4
0
 def test_move_backwards_changes_position(self):
     mars = Rover(self.landscape, (0, 2), Direction.E)
     self.assertTrue(mars.move_backwards())
     self.assertTrue(mars.is_position((0, 1)))
     self.assertTrue(mars.move_backwards())
     self.assertTrue(mars.is_position((0, 0)))