def test_x_win_vert_middle(self): board = [ 'o', 'x', '.', 'o', 'x', '.', '.', 'x', '.', ] self.assertEqual(ttt.GameStates.x_wins, ttt.game_state(board))
def test_1(self): self.assertEqual(0, 0) # pass self.assertEqual(1, 0) # fail something = board = None self.assertEqual(something, ttt.game_state(board))
def test_invalid_wrong_size(): board = [ 'x', '.', 'o', ] assert ttt.GameStates.invalid == ttt.game_state(board)
def test_invalid_two_winners(self): board = [ 'o', 'x', '.', 'o', 'x', '.', 'o', 'x', '.', ] self.assertEqual(ttt.GameStates.invalid, ttt.game_state(board))
def _test_x_win_2(): board = [ 'o', '.', 'o', '.', '.', '.', 'x', 'x', 'x', ] assert ttt.GameStates.x_wins == ttt.game_state(board)
def test_x_win_diag_1(): board = [ 'x', '.', 'x', 'o', 'x', 'o', 'x', 'o', '.', ] assert ttt.GameStates.x_wins == ttt.game_state(board)
def test_x_win_diag_1(self): board = [ 'x', '.', 'x', 'o', 'x', 'o', 'x', 'o', '.', ] self.assertEqual(ttt.GameStates.x_wins, ttt.game_state(board))
def test_o_win_vert(self): board = [ 'x', 'x', 'o', '.', '.', 'o', 'x', '.', 'o', ] self.assertEqual(ttt.GameStates.o_wins, ttt.game_state(board))
def test_invalid_illegal_char(self): board = [ 'x', '.', 'o', 'x', '.', 'o', 'x', '.', 'O', ] self.assertEqual(ttt.GameStates.invalid, ttt.game_state(board))
def test_invalid_too_many_o_moves(self): board = [ 'x', '.', 'o', 'x', '.', 'o', 'x', 'o', 'o', ] self.assertEqual(ttt.GameStates.invalid, ttt.game_state(board))
def test_draw(self): board = [ 'x', 'x', 'o', 'o', 'x', 'x', 'x', 'o', 'o', ] self.assertEqual(ttt.GameStates.draw, ttt.game_state(board))
def test_incomplete_0(self): board = [ 'x', 'x', 'o', 'o', 'x', 'o', 'x', 'o', '.', ] self.assertEqual(ttt.GameStates.unfinished, ttt.game_state(board))
def test_x_win_vert_middle(): board = [ 'o', 'x', '.', 'o', 'x', '.', '.', 'x', '.', ] assert ttt.GameStates.x_wins == ttt.game_state(board)
def test_o_win_vert(): board = [ 'x', 'x', 'o', '.', '.', 'o', 'x', '.', 'o', ] assert ttt.GameStates.o_wins == ttt.game_state(board)
def test_invalid_too_many_o_moves(): board = [ 'x', '.', 'o', 'x', '.', 'o', 'x', 'o', 'o', ] assert ttt.GameStates.invalid == ttt.game_state(board)
def test_invalid_illegal_char(): board = [ 'x', '.', 'o', 'x', '.', 'o', 'x', '.', 'O', ] assert ttt.GameStates.invalid == ttt.game_state(board)
def test_draw(): board = [ 'x', 'x', 'o', 'o', 'x', 'x', 'x', 'o', 'o', ] assert ttt.GameStates.draw == ttt.game_state(board)
def test_invalid_two_winners(): board = [ 'o', 'x', '.', 'o', 'x', '.', 'o', 'x', '.', ] assert ttt.GameStates.invalid == ttt.game_state(board)
def test_incomplete_0(): board = [ 'x', 'x', 'o', 'o', 'x', 'o', 'x', 'o', '.', ] assert ttt.GameStates.unfinished == ttt.game_state(board)
def test_bad_boards(self): # or something self.assertEqual(GameStates.invalid, ttt.game_state(None)) self.assertEqual(GameStates.invalid, ttt.game_state("xo.ox.ox.")) self.assertEqual(GameStates.invalid, ttt.game_state([])) self.assertEqual(GameStates.invalid, ttt.game_state(['.'] * 8)) self.assertEqual(GameStates.invalid, ttt.game_state(['.'] * 10)) self.assertEqual(GameStates.invalid, ttt.game_state(['x'] * 2 + ['.'] * 7)) self.assertEqual(GameStates.invalid, ttt.game_state(['o'] * 2 + ['.'] * 7)) # x goes first self.assertEqual(GameStates.invalid, ttt.game_state(['o'] * 1 + ['.'] * 8))
def test_double_wins(self): self.assertEqual( GameStates.invalid, ttt.game_state([ 'x', 'x', 'o', 'o', 'x', 'o', 'o', 'x', 'x', ]))
def _test_all_perms(self): results = {} for board in all_boards(): # if board == list("xoxxoxoxo"): # print board e = ttt.game_state(list(board)) results[e] = results.get(e, 0) + 1 # {0: 13815, 2: 920, 1: 4520, 3: 412, 4: 16} print results self.assertEqual(3**9, sum(results.values())) self.assertEqual(13815, results[GameStates.invalid]) self.assertEqual(4520, results[GameStates.unfinished]) self.assertEqual(920, results[GameStates.x_wins]) self.assertEqual(412, results[GameStates.o_wins]) self.assertEqual(16, results[GameStates.draw])
def test_1(self): tic = ttt.TTT() assert len(tic.board) == 9 assert all([s == '.' for s in tic.board]) assert tic.state is ttt.game_state(tic) assert tic.display( ) == '. | . | .\n---------\n. | . | .\n---------\n. | . | .' assert tic._nelem('.') == 9 assert tic._nelem('x') == 0 assert tic._nelem('o') == 0 self.assertRaises(AssertionError, lambda: tic._nelem('p')) assert tic.state is ttt.GameStates.unfinished tic.board = ['x', 'x', 'x', 'x', 'x'] assert tic.state is ttt.GameStates.invalid tic.board = ['x'] * 9 assert tic.state is ttt.GameStates.invalid tic.board = ['o'] * 9 assert tic.state is ttt.GameStates.invalid tic.board = ['x', 'x', '.', '.', '.', '.', '.', '.', '.'] assert tic.state is ttt.GameStates.invalid tic.board = ['x', 'o', 'o', '.', '.', '.', '.', '.', '.'] assert tic.state is ttt.GameStates.invalid tic.board = ['x', 'x', 'x', 'o', 'o', '.', '.', '.', '.'] assert tic.state is ttt.GameStates.x_wins tic.board = ['o', 'x', 'x', 'o', 'o', '.', 'x', 'x', 'o'] assert tic.state is ttt.GameStates.o_wins tic.board = ['x', 'o', 'x', 'x', 'o', 'o', 'o', 'x', '.'] assert tic.state is ttt.GameStates.draw # tic.board = ['o', 'x', 'o', 'x', 'o', '.', 'x', 'x', '.'] # assert tic.state is ttt.GameStates.o_wins tac = ttt.TTT() tac.play('NE') assert tac.state is ttt.GameStates.unfinished print(tac.display())
def test_10(self): self.assertEqual(GameStates.invalid, ttt.game_state(list("xo.xo.xo."))) self.assertEqual(GameStates.draw, ttt.game_state(list("xoxxoxoxo")))
def test_good_boards(self): self.assertEqual(GameStates.unfinished, ttt.game_state(['.'] * 9)) self.assertEqual(GameStates.x_wins, ttt.game_state(list("xxx.oo..."))) self.assertEqual(GameStates.x_wins, ttt.game_state(list("xo.xo.x.."))) self.assertEqual(GameStates.o_wins, ttt.game_state(list("ooo.xx.x.")))
def test_game_states(self): invalid_1 = ['x', 'x', 'x', 'o', 'o', 'o', '.', '.', '.'] self.assertEqual(ttt.game_state(invalid_1), ttt.GameStates.invalid)
def test_game_draw(self): draw_1 = ['x', 'x', 'o', 'o', 'o', 'x', 'x', 'o', 'x'] self.assertEqual(ttt.game_state(draw_1), ttt.GameStates.draw)
def test_game_unfinished(self): unfinished_1 = ['x', 'x', '.', 'o', 'o', '.', '.', '.', '.'] self.assertEqual(ttt.game_state(unfinished_1), ttt.GameStates.unfinished)
def test_invalid_wrong_size(self): board = [ 'x', '.', 'o', ] self.assertEqual(ttt.GameStates.invalid, ttt.game_state(board))