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'))
def testRoverAsExample2(self): rover1 = Rover('E', 3, 3) self.assertEqual((5, 1), rover1.move('MMRMMRMRRM')) self.assertEqual((6, 1), rover1.move('M'))
def testRoverAsExample1(self): rover1 = Rover('N', 1, 2) self.assertEqual((1, 3), rover1.move('LMLMLMLMM')) self.assertEqual((1, 4), rover1.move('M'))
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)