def test_moves_backward(
     self,
     direction: Direction,
     initial: Coordinates,
     final: Coordinates,
 ) -> None:
     rover = Rover(initial, direction)
     rover.move_backward()
     assert rover.position() == final
class testRover(unittest.TestCase):
    def setUp(self):
        self.rover = Rover(1, 2, 'N')

    def test_rotate(self):
        inst1 = 'L'
        self.rover.rotate(inst1)
        self.assertEqual(self.rover.dir, 'W')

        inst2 = 'R'
        self.rover.rotate(inst2)
        self.assertEqual(self.rover.dir, 'N')
예제 #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)))
예제 #4
0
class TestRover(unittest.TestCase):
    def setUp(self):
        self.rover = Rover(x=1, y=1, dir='N')
        
    def testRoverLandingAtZero(self):
        rover = Rover('N')
        self.assertEqual((0, 0), rover.getLocation())
        
    def testRoverLandingOnPlanet(self):
        self.assertEqual((1, 1), self.rover.getLocation())
        
    def testRoverMoveForwardNorth(self):
        self.assertEqual((1, 2), self.rover.move('M'))
          
    def testRoverTurnRightMoveForwardEast(self):
        self.assertEqual((2, 1), self.rover.move('RM'))

    def testRoverTrunRightRightMoveForwardSouth(self):
        self.assertEqual((1, 0), self.rover.move('RRM'))
        
    def testRoverTrunRight3timesMoveForwardWest(self):
        self.assertEqual((0, 1), self.rover.move('RRRM'))

    def testRoverTrunRight4timesMoveForwardNorth(self):
        self.assertEqual((1, 2), self.rover.move('RRRRM'))

    def testRoverTurnLeftMoveForwardWest(self):
        self.assertEqual((0, 1), self.rover.move('LM'))

    def testRoverTurnLeftTwiceMoveForwardSouth(self):
        self.assertEqual((1, 0), self.rover.move('LLM'))

    def testRoverTurnLeft3TimesMoveForwardSouth(self):
        self.assertEqual((2, 1), self.rover.move('LLLM'))

    def testRoverTurnLeft4TimesMoveForwardNouth(self):
        self.assertEqual((1, 2), self.rover.move('LLLLM'))

    def testRoverAsExample1(self):
        rover1 = Rover('N', 1, 2)
        self.assertEqual((1, 3), rover1.move('LMLMLMLMM'))
        self.assertEqual((1, 4), rover1.move('M'))

    def testRoverAsExample2(self):
        rover1 = Rover('E', 3, 3)
        self.assertEqual((5, 1), rover1.move('MMRMMRMRRM'))
        self.assertEqual((6, 1), rover1.move('M'))
예제 #5
0
class TestRover(unittest.TestCase):
    def setUp(self):
        self.rover = Rover(x=1, y=1, dir='N')

    def testRoverLandingAtZero(self):
        rover = Rover('N')
        self.assertEqual((0, 0), rover.getLocation())

    def testRoverLandingOnPlanet(self):
        self.assertEqual((1, 1), self.rover.getLocation())

    def testRoverMoveForwardNorth(self):
        self.assertEqual((1, 2), self.rover.move('M'))

    def testRoverTurnRightMoveForwardEast(self):
        self.assertEqual((2, 1), self.rover.move('RM'))

    def testRoverTrunRightRightMoveForwardSouth(self):
        self.assertEqual((1, 0), self.rover.move('RRM'))

    def testRoverTrunRight3timesMoveForwardWest(self):
        self.assertEqual((0, 1), self.rover.move('RRRM'))

    def testRoverTrunRight4timesMoveForwardNorth(self):
        self.assertEqual((1, 2), self.rover.move('RRRRM'))

    def testRoverTurnLeftMoveForwardWest(self):
        self.assertEqual((0, 1), self.rover.move('LM'))

    def testRoverTurnLeftTwiceMoveForwardSouth(self):
        self.assertEqual((1, 0), self.rover.move('LLM'))

    def testRoverTurnLeft3TimesMoveForwardSouth(self):
        self.assertEqual((2, 1), self.rover.move('LLLM'))

    def testRoverTurnLeft4TimesMoveForwardNouth(self):
        self.assertEqual((1, 2), self.rover.move('LLLLM'))

    def testRoverAsExample1(self):
        rover1 = Rover('N', 1, 2)
        self.assertEqual((1, 3), rover1.move('LMLMLMLMM'))
        self.assertEqual((1, 4), rover1.move('M'))

    def testRoverAsExample2(self):
        rover1 = Rover('E', 3, 3)
        self.assertEqual((5, 1), rover1.move('MMRMMRMRRM'))
        self.assertEqual((6, 1), rover1.move('M'))
예제 #6
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)))
예제 #7
0
 def testRoverLandingAtZero(self):
     rover = Rover('N')
     self.assertEqual((0, 0), rover.getLocation())
예제 #8
0
 def setUp(self):
     self.rover = Rover(x=1, y=1, dir='N')
예제 #9
0
 def testRoverAsExample2(self):
     rover1 = Rover('E', 3, 3)
     self.assertEqual((5, 1), rover1.move('MMRMMRMRRM'))
     self.assertEqual((6, 1), rover1.move('M'))
예제 #10
0
 def testRoverAsExample1(self):
     rover1 = Rover('N', 1, 2)
     self.assertEqual((1, 3), rover1.move('LMLMLMLMM'))
     self.assertEqual((1, 4), rover1.move('M'))
예제 #11
0
 def testRoverAsExample2(self):
     rover1 = Rover('E', 3, 3)
     self.assertEqual((5, 1), rover1.move('MMRMMRMRRM'))
     self.assertEqual((6, 1), rover1.move('M'))
예제 #12
0
 def testRoverLandingAtZero(self):
     rover = Rover('N')
     self.assertEqual((0, 0), rover.getLocation())
예제 #13
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)))
예제 #14
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))
예제 #15
0
 def test_cant_move_outside_boundaries(self):
     mars = Rover(self.landscape, (0, 0), Direction.N)
     self.assertFalse(mars.can_move((-4, 0)))
     self.assertFalse(mars.can_move((0, 12)))
     self.assertFalse(mars.can_move((11, 3)))
     self.assertFalse(mars.can_move((4, -2)))
예제 #16
0
 def test_position_has_obstacles(self):
     mars = Rover(self.landscape, (0, 0), Direction.N)
     self.assertTrue(mars.can_move((4, 0)))
     self.assertFalse(mars.can_move((0, 3)))
예제 #17
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)))
예제 #18
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)))
class MarsRoverTests(unittest.TestCase):
    def setUp(self):
        self.rover = Rover()

    def test_mars_rover_starts_at_0_0(self):
        self.assertEqual((0,0), self.rover.position)

    def test_mars_rover_starts_facing_north(self):
        self.assertEqual('N', self.rover.direction)

    def test_mars_rover_accepts_f_command(self):
        self.rover.move('f')
        self.assertEqual((0, 1), self.rover.position)

    def test_mars_rover_accepts_r_command(self):
        self.rover.move('r')
        self.assertEqual('E', self.rover.direction)

    def test_mars_rover_rejects_other_commands(self):
        with self.assertRaises(TypeError):
            self.rover.move('z')

    def test_mars_rover_accepts_rf_command(self):
        self.rover.move('rf')

    def test_mars_rover_moves_to_1_1_on_frf(self):
        self.rover.move('frf')
        self.assertEqual((1,1), self.rover.position)

    def test_mars_rover_rolls(self):
        self.rover.move(4*'r')
        self.assertEqual('N', self.rover.direction)
        self.assertEqual((0,0), self.rover.position)
예제 #20
0
 def testRoverAsExample1(self):
     rover1 = Rover('N', 1, 2)
     self.assertEqual((1, 3), rover1.move('LMLMLMLMM'))
     self.assertEqual((1, 4), rover1.move('M'))
 def setUp(self):
     self.rover = Rover(1, 2, 'N')
예제 #22
0
 def setUp(self):
     self.rover = Rover(x=1, y=1, dir='N')
 def setUp(self):
     self.rover = Rover()
 def test_starts_at_the_given_position_and_facing_direction(self) -> None:
     rover = Rover(Coordinates(1, 3), Direction.north())
     assert rover.position() == Coordinates(1, 3)
     assert rover.direction() == Direction.north()
예제 #25
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)))
 def test_turns_left(self, initial: Direction, final: Direction) -> None:
     rover = Rover(Coordinates(3, 3), initial)
     rover.turn_left()
     assert rover.direction() == final
예제 #27
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)))