Код: Выделить всё
@Test
void testRowX() {
// given
String sizeOfBoardString = "3\n2";
ByteArrayInputStream inputStream = new ByteArrayInputStream(sizeOfBoardString.getBytes());
System.setIn(new ByteArrayInputStream(sizeOfBoardString.getBytes()));
// when
OutputComputer outputComputer = new OutputComputer();
outputComputer.gameStart();
outputComputer.gameType();
InputSelector inputSelector = new InputSelector();
int boardSize = inputSelector.boardType();
StartGame startGame = new StartGame();
startGame.runGame(boardSize, boardSize);
String whoWin = "Won X";
// then
assertEquals("Wona X", whoWin);
}
Подводя итог, я пытаюсь протестировать программу «тик-такто». Я спрашиваю размер доски, и она принимает значение. Но когда я спрашиваю, компьютер это или человек, мне отвечают, что это не имеет значения. Но, по моему мнению, из-за этого значения должно быть 2: String sizeOfBoardString = "3\n2";
Если я запускаю программу вручную, она работает нормально
Код: Выделить всё
public class StartGame {
public void runGame(int boardSize, int boardSize2) {
RealUser realUser = new RealUser();
Computer computer = new Computer();
OutputComputer outputComputer = new OutputComputer();
Board board = new Board(boardSize, boardSize);
outputComputer.computerOrHuman();
int compOrHum = board.computerOrHuman();
board.showFilledBoard();
}
Код: Выделить всё
public class Board {
private char[][] values;
private int rows;
private int columns;
List winnersX = new ArrayList();
List winnersO = new ArrayList();
public Board(int rows, int columns) {
this.rows = rows;
this.columns = columns;
this.values = new char[rows][columns];
}
public int computerOrHuman() {
InputSelector inputSelector = new InputSelector();
int ifHuman = inputSelector.computerOrHuman();
return ifHuman;
}
}
Код: Выделить всё
public class InputSelector {
Scanner scanner = new Scanner(System.in);
public int computerOrHuman() {
int computerOrHuman = Integer.parseInt(scanner.nextLine());
return computerOrHuman;
}
}
Вот результат кода:
Добро пожаловать в TicTacToe!
Выберите тип игры. Введите 3 или 10.
Вы хотите играть с компьютером(1) или человеком(2)?
Строка не найдена
Подробнее здесь: https://stackoverflow.com/questions/792 ... d-i-change
Мобильная версия