@Test public void should_ignore_command_when_given_negative_y_coordinate() { new PlaceCommand(3, -1, Direction.WEST).execute(robot); assertThat(robot.getX(), equalTo(3)); assertThat(robot.getY(), equalTo(3)); assertThat(robot.getFacingDirection(), equalTo(Direction.NORTH)); }
@Test public void should_ignore_command_when_given_y_coordinate_beyond_board_height() { new PlaceCommand(3, 5, Direction.WEST).execute(robot); assertThat(robot.getX(), equalTo(3)); assertThat(robot.getY(), equalTo(3)); assertThat(robot.getFacingDirection(), equalTo(Direction.NORTH)); }
@Test public void test_moving_around_board() throws IOException { when(commander.getNextCommand()) .thenReturn("PLACE 0,0,NORTH") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn("RIGHT") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn("RIGHT") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn("RIGHT") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn(null); robotSimulator.run(); assertThat(robot.getX(), equalTo(0)); assertThat(robot.getY(), equalTo(0)); assertThat(robot.getFacingDirection(), equalTo(Direction.WEST)); }
@Before public void setup() { robot = new Robot(new Board(5, 5)); robot.setX(3); robot.setY(3); robot.setFacingDirection(Direction.NORTH); }
@Test public void test_straight_one_movement() throws IOException { when(commander.getNextCommand()) .thenReturn("PLACE 0,0,NORTH") .thenReturn("MOVE") .thenReturn(null); robotSimulator.run(); assertThat(robot.getX(), equalTo(0)); assertThat(robot.getY(), equalTo(1)); assertThat(robot.getFacingDirection(), equalTo(Direction.NORTH)); }
@Test public void should_be_able_to_handle_empty_initial_lines() throws IOException { when(commander.getNextCommand()) .thenReturn("") .thenReturn(" ") .thenReturn("\t") .thenReturn("PLACE 0,0,NORTH") .thenReturn("MOVE") .thenReturn(null); robotSimulator.run(); assertThat(robot.getX(), equalTo(0)); assertThat(robot.getY(), equalTo(1)); assertThat(robot.getFacingDirection(), equalTo(Direction.NORTH)); }
@Test public void should_ignore_commands_until_first_place_command() throws IOException { when(commander.getNextCommand()) .thenReturn("") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn("LEFT") .thenReturn("MOVE") .thenReturn(null); robotSimulator.run(); assertThat(robot.getX(), equalTo(0)); assertThat(robot.getY(), equalTo(0)); assertThat(robot.getFacingDirection(), nullValue()); assertFalse(robot.isOnBoard()); }
@Test public void robot_should_not_fall_off_the_table() throws IOException { when(commander.getNextCommand()) .thenReturn("PLACE 0,0,NORTH") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn(null); robotSimulator.run(); assertThat(robot.getX(), equalTo(0)); assertThat(robot.getY(), equalTo(4)); assertThat(robot.getFacingDirection(), equalTo(Direction.NORTH)); }
@Test public void test_multiple_place_command() throws IOException { when(commander.getNextCommand()) .thenReturn("PLACE 0,0,NORTH") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn("PLACE 3,3,SOUTH") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn("MOVE") .thenReturn("LEFT") .thenReturn("MOVE") .thenReturn(null); robotSimulator.run(); assertThat(robot.getX(), equalTo(4)); assertThat(robot.getY(), equalTo(0)); assertThat(robot.getFacingDirection(), equalTo(Direction.EAST)); }
@Test public void given_valid_coordinate__THEN__should_set_robot_status_to_be_onBoard() { assertFalse(robot.isOnBoard()); new PlaceCommand(1, 1, Direction.WEST).execute(robot); assertTrue(robot.isOnBoard()); }
@Test public void given_valid_coordinate__THEN__should_set_robot_coordinate_to_the_given_coordinate() { new PlaceCommand(1, 1, Direction.WEST).execute(robot); assertThat(robot.getX(), equalTo(1)); assertThat(robot.getY(), equalTo(1)); }
@Test public void given_valid_coordinate__THEN__should_set_robot_to_the_correct_facing_direction() { new PlaceCommand(1, 1, Direction.WEST).execute(robot); assertThat(robot.getFacingDirection(), equalTo(Direction.WEST)); }