@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)); }
@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 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_coordinate_to_the_given_coordinate() { new PlaceCommand(1, 1, Direction.WEST).execute(robot); assertThat(robot.getX(), equalTo(1)); assertThat(robot.getY(), equalTo(1)); }