Game { public int move(char player) { for (int i = 0; i < 9; i++) { if (board.charAt(i) == '-') { Game game = play(i, player); if (game.winner() == player) return i; } } for (int i = 0; i < 9; i++) { if (board.charAt(i) == '-') return i; } return -1; } Game(String s);  Game(StringBuffer s, int position, char player); int move(char player); Game play(int i, char player); char winner(); public StringBuffer board; }
@Test public void testFindWinningMove() { Game game = new Game("XO-XX-OOX"); assertEquals(5, game.move('X')); }
@Test public void testDefaultMove() { Game game = new Game("XOXOX-OXO"); assertEquals(5, game.move('X')); game = new Game("XOXOXOOX-"); assertEquals(8, game.move('O')); game = new Game("---------"); assertEquals(0, game.move('X')); game = new Game("XXXXXXXXX"); assertEquals(-1, game.move('X')); }