Ejemplo n.º 1
0
    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)))
Ejemplo n.º 2
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)))
Ejemplo n.º 3
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)))
Ejemplo n.º 4
0
    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)))
Ejemplo n.º 5
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)))
Ejemplo n.º 6
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)))
Ejemplo n.º 7
0
 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)))