Exemple #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)))
Exemple #2
0
 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))
Exemple #3
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 #4
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 #5
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)))
Exemple #6
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)))