Exemple #1
0
 def test_x_win_vert_middle(self):
     board = [
         'o', 'x', '.',
         'o', 'x', '.',
         '.', 'x', '.',
     ]
     self.assertEqual(ttt.GameStates.x_wins, ttt.game_state(board))
Exemple #2
0
    def test_1(self):

        self.assertEqual(0, 0)  # pass
        self.assertEqual(1, 0)  # fail

        something = board = None
        self.assertEqual(something, ttt.game_state(board))
Exemple #3
0
def test_invalid_wrong_size():
    board = [
        'x',
        '.',
        'o',
    ]
    assert ttt.GameStates.invalid == ttt.game_state(board)
Exemple #4
0
 def test_invalid_two_winners(self):
     board = [
         'o', 'x', '.',
         'o', 'x', '.',
         'o', 'x', '.',
     ]
     self.assertEqual(ttt.GameStates.invalid, ttt.game_state(board))
Exemple #5
0
def _test_x_win_2():
    board = [
        'o', '.', 'o',
        '.', '.', '.',
        'x', 'x', 'x',
    ]
    assert ttt.GameStates.x_wins == ttt.game_state(board)
Exemple #6
0
def test_x_win_diag_1():
    board = [
        'x', '.', 'x',
        'o', 'x', 'o',
        'x', 'o', '.',
    ]
    assert ttt.GameStates.x_wins == ttt.game_state(board)
Exemple #7
0
 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))
Exemple #8
0
 def test_o_win_vert(self):
     board = [
         'x', 'x', 'o',
         '.', '.', 'o',
         'x', '.', 'o',
     ]
     self.assertEqual(ttt.GameStates.o_wins, ttt.game_state(board))
Exemple #9
0
 def test_invalid_illegal_char(self):
     board = [
         'x', '.', 'o',
         'x', '.', 'o',
         'x', '.', 'O',
     ]
     self.assertEqual(ttt.GameStates.invalid, ttt.game_state(board))
Exemple #10
0
 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))
Exemple #11
0
 def test_draw(self):
     board = [
         'x', 'x', 'o',
         'o', 'x', 'x',
         'x', 'o', 'o',
     ]
     self.assertEqual(ttt.GameStates.draw, ttt.game_state(board))
Exemple #12
0
 def test_incomplete_0(self):
     board = [
         'x', 'x', 'o',
         'o', 'x', 'o',
         'x', 'o', '.',
     ]
     self.assertEqual(ttt.GameStates.unfinished, ttt.game_state(board))
Exemple #13
0
def test_x_win_vert_middle():
    board = [
        'o', 'x', '.',
        'o', 'x', '.',
        '.', 'x', '.',
    ]
    assert ttt.GameStates.x_wins == ttt.game_state(board)
Exemple #14
0
def test_o_win_vert():
    board = [
        'x', 'x', 'o',
        '.', '.', 'o',
        'x', '.', 'o',
    ]
    assert ttt.GameStates.o_wins == ttt.game_state(board)
Exemple #15
0
def test_invalid_too_many_o_moves():
    board = [
        'x',
        '.',
        'o',
        'x',
        '.',
        'o',
        'x',
        'o',
        'o',
    ]
    assert ttt.GameStates.invalid == ttt.game_state(board)
Exemple #16
0
def test_invalid_illegal_char():
    board = [
        'x',
        '.',
        'o',
        'x',
        '.',
        'o',
        'x',
        '.',
        'O',
    ]
    assert ttt.GameStates.invalid == ttt.game_state(board)
Exemple #17
0
def test_draw():
    board = [
        'x',
        'x',
        'o',
        'o',
        'x',
        'x',
        'x',
        'o',
        'o',
    ]
    assert ttt.GameStates.draw == ttt.game_state(board)
Exemple #18
0
def test_invalid_two_winners():
    board = [
        'o',
        'x',
        '.',
        'o',
        'x',
        '.',
        'o',
        'x',
        '.',
    ]
    assert ttt.GameStates.invalid == ttt.game_state(board)
Exemple #19
0
def test_incomplete_0():
    board = [
        'x',
        'x',
        'o',
        'o',
        'x',
        'o',
        'x',
        'o',
        '.',
    ]
    assert ttt.GameStates.unfinished == ttt.game_state(board)
Exemple #20
0
    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))
Exemple #21
0
 def test_double_wins(self):
     self.assertEqual(
         GameStates.invalid,
         ttt.game_state([
             'x',
             'x',
             'o',
             'o',
             'x',
             'o',
             'o',
             'x',
             'x',
         ]))
Exemple #22
0
    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])
Exemple #23
0
    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())
Exemple #24
0
 def test_10(self):
     self.assertEqual(GameStates.invalid, ttt.game_state(list("xo.xo.xo.")))
     self.assertEqual(GameStates.draw, ttt.game_state(list("xoxxoxoxo")))
Exemple #25
0
 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.")))
Exemple #26
0
    def test_game_states(self):
        invalid_1 = ['x', 'x', 'x', 'o', 'o', 'o', '.', '.', '.']

        self.assertEqual(ttt.game_state(invalid_1), ttt.GameStates.invalid)
Exemple #27
0
    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)
Exemple #28
0
    def test_game_unfinished(self):
        unfinished_1 = ['x', 'x', '.', 'o', 'o', '.', '.', '.', '.']

        self.assertEqual(ttt.game_state(unfinished_1),
                         ttt.GameStates.unfinished)
Exemple #29
0
 def test_invalid_wrong_size(self):
     board = [
         'x', '.', 'o',
     ]
     self.assertEqual(ttt.GameStates.invalid, ttt.game_state(board))