def game(): board = request.args.get('board') if not board: abort(400) try: State(board) except StateInvalid: abort(400) return tic_tac_toe(board)
def test_is_valid(self): assert State('ooxxoxoxx').is_valid() assert State(' o ').is_valid() with self.assertRaises(StateInvalid): State('oooxoxxxx').is_valid()
def test_is_terminal(self): assert State('xxx o oo').is_terminal() assert State(' o xox o ').is_terminal()
def test_has_won(self): assert State('xo oxo ox').has_won('x') assert State(' ooxoxxox').has_won('o')
def test_diags(self): assert State('xo oxo ox').get_diag_1() == 'xxx' assert State('o xoxoxo ').get_diag_2() == 'xxx'
def test_get_cols(self): st = State('x oxo x o') assert st.get_col(0) == 'xxx' assert st.get_col(1) == ' o ' assert st.get_col(2) == 'o o'
def test_get_rows(self): st = State('xxxo o o ') assert st.get_row(0) == 'xxx' assert st.get_row(1) == 'o o' assert st.get_row(2) == ' o '