Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1import pytest 

2 

3from rover.rover import Rover 

4 

5 

6def test_rover_initialisation(): 

7 assert Rover(0, 0, "EAST") 

8 

9 

10def test_rover_can_move(rover): 

11 command = "F" 

12 assert rover.move(command) is not None 

13 

14 

15@pytest.mark.parametrize( 

16 ("init", "command", "expected"), 

17 [ 

18 ((0, 0, "EAST"), "F", (1, 0, "EAST")), 

19 ((0, 0, "EAST"), "B", (-1, 0, "EAST")), 

20 ((0, 0, "EAST"), "R", (0, 0, "SOUTH")), 

21 ((0, 0, "EAST"), "L", (0, 0, "NORTH")), 

22 # change starting point 

23 ((0, 0, "WEST"), "F", (-1, 0, "WEST")), 

24 ((0, 0, "SOUTH"), "R", (0, 0, "WEST")), 

25 ((0, 0, "SOUTH"), "F", (0, -1, "SOUTH")), 

26 ], 

27) 

28def test_rover_receive_commands(init, command, expected): 

29 rover = Rover(*init) 

30 assert rover.move(command) == expected 

31 

32 

33def test_rover_rejects_invalid_commands(rover): 

34 command = " W " 

35 with pytest.raises(ValueError): 

36 rover.move(command) 

37 

38 

39@pytest.mark.parametrize( 

40 ("init", "command", "expected"), 

41 [ 

42 ((0, 0, "NORTH"), "FB", (0, 0, "NORTH")), 

43 ((0, 0, "NORTH"), "FF", (0, 2, "NORTH")), 

44 ((4, 2, "EAST"), "FLFFFRFLB", (6, 4, "NORTH")), 

45 ], 

46) 

47def test_rover_can_receive_multiple_commands(init, command, expected): 

48 rover = Rover(*init) 

49 assert rover.move(command) == expected