Пример #1
0
 def test_tic_tac_toe_check_doesnt_accept_non_string_boards(self, board):
     with pytest.raises(
             TypeError,
             message=
             "Method is supposed to raise TypeError on lists not containing all strings"
     ):
         tic_tac_toe_check(board)
Пример #2
0
 def test_horizontal_row_two_winner(self):
     """ Asserts that the winning character is returned if a winner in the second row is found """
     try:
         impl.tic_tac_toe_check(["o", "o", "", "x", "x", "x", "", "", "o"])
         assert True
     except:
         assert False
Пример #3
0
 def test_tic_tac_toe_check_not_empty_string(self):
     tmp1 = list(FULL_BOARD_CONFIG)
     tmp1[0] = ' '
     with self.assertRaises(
             ValueError,
             message="does not flag invalid empty position string"):
         impl.tic_tac_toe_check(tmp1)
Пример #4
0
def test_tic_tac_toe_check_multiple_winning_patterns():
    tmp1 = list(FULL_BOARD_CONFIG)
    tmp1[8] = 'x'
    tmp1[0] = 'o'
    with pytest.raises(ValueError,
                       message="does not flag multiple winning patterns"):
        impl.tic_tac_toe_check(tmp1)
Пример #5
0
 def test_tic_tac_toe_check_only_accepts_lists_with_lowercase_x_or_o_or_empty(
         self):
     with pytest.raises(
             ValueError,
             message="Method is supposed to raise ValueError on lists not"
             " containing all 'x's, 'o's, and/or ''."):
         tic_tac_toe_check(["x", "o", "o", "x", "o", "x", "1", "z", "y"])
Пример #6
0
 def test_bottom_left_to_top_right_diagonal_winner(self):
     """ Asserts that the winning character is returned if a winner in the bottom to top diagonal """
     try:
         impl.tic_tac_toe_check(["o", "o", "x", "o", "x", "", "x", "", ""])
         assert True
     except:
         assert False
Пример #7
0
 def test_passes_if_board_is_legal(self):
     """ Asserts that no error is raised if the given board is a legal board """
     try:
         impl.tic_tac_toe_check(["", "", "", "", "", "", "", "", ""])
         assert True
     except:
         assert False
Пример #8
0
 def test_tic_tac_toe_check_raises_value_error_on_multiple_winning_patterns(
         self, board):
     with pytest.raises(
             ValueError,
             message=
             "Method is supposed to raise ValueError on multiple winners."):
         tic_tac_toe_check(board)
Пример #9
0
 def test_vertical_column_three_winner(self):
     """ Asserts that the winning character is returned if a winner in the third vertical column is found """
     try:
         impl.tic_tac_toe_check(["o", "", "x", "o", "", "x", "", "o", "x"])
         assert True
     except:
         assert False
Пример #10
0
 def test_tic_tac_toe_check_only_accepts_correct_board_size_lists(
         self, board):
     with pytest.raises(
             ValueError,
             message=
             "Method is supposed to raise ValueError on incorrectly sized lists."
     ):
         tic_tac_toe_check(board)
Пример #11
0
 def test_raises_if_board_contains_more_than_one_winner(self):
     """ Asserts that ValueError is raised if the board contains more than one winner """
     try:
         impl.tic_tac_toe_check(["x", "x", "x", "o", "o", "o", "", "", ""])
         assert False
     except ValueError:
         assert True
     except:
         assert False
Пример #12
0
 def test_raises_if_board_is_not_length_nine(self):
     """ Asserts that ValueError is raised if the board is not exactly nine strings """
     try:
         impl.tic_tac_toe_check([""])
         assert False
     except ValueError:
         assert True
     except:
         assert False
Пример #13
0
 def test_raises_if_board_contains_invalid_characters(self):
     """ Asserts that ValueError is raised if the board contains invalid characters """
     try:
         impl.tic_tac_toe_check(["", "", "", "", "", "", "", "", "z"])
         assert False
     except ValueError:
         assert True
     except:
         assert False
Пример #14
0
 def test_raises_if_board_is_none(self):
     """ Asserts that TypeError is raised if the given board is None """
     try:
         impl.tic_tac_toe_check(None)
         assert False
     except TypeError:
         assert True
     except:
         assert False
Пример #15
0
 def test_raises_if_board_is_non_list(self):
     """ Asserts that TypeError is raised if the given board is not a list """
     try:
         impl.tic_tac_toe_check("board")
         assert False
     except TypeError:
         assert True
     except:
         assert False
Пример #16
0
def test_tic_tac_toe_check_invalid_symbol_type1():
    with pytest.raises(TypeError, message="does not flag invalid arg type"):
        impl.tic_tac_toe_check([1] * 9)
    with pytest.raises(TypeError, message="does not flag invalid arg type"):
        impl.tic_tac_toe_check([None] * 9)
    tmp1 = list(FULL_BOARD_CONFIG)
    tmp1[0] = 1
    with pytest.raises(TypeError, message="does not flag invalid arg type"):
        impl.tic_tac_toe_check(tmp1)
Пример #17
0
def test_tic_tac_toe_check_invalid_symbol_type1():
    with pytest.raises(TypeError):
        impl.tic_tac_toe_check([1] * 9)
    with pytest.raises(TypeError):
        impl.tic_tac_toe_check([None] * 9)
    tmp1 = list(FULL_BOARD_CONFIG)
    tmp1[0] = 1
    with pytest.raises(TypeError):
        impl.tic_tac_toe_check(tmp1)
Пример #18
0
 def test_tic_tac_toe_check_returns_o_as_winner(self, board):
     winner = tic_tac_toe_check(board)
     assert winner == 'o'
Пример #19
0
def test_tic_tac_toe_check_incorrect_board_type1():
    with pytest.raises(TypeError, message="does not flag invalid arg type"):
        impl.tic_tac_toe_check(None)
    with pytest.raises(TypeError):
        impl.tic_tac_toe_check(3)
Пример #20
0
 def test_tic_tac_toe_check_accepts_all_winning_pattern_types(self, board):
     winner = tic_tac_toe_check(board)
     assert winner == 'x'
Пример #21
0
def test_tic_tac_toe_check_multiple_symbols():
    tmp1 = list(FULL_BOARD_CONFIG)
    tmp1[0] = 'y'
    with pytest.raises(ValueError, message="does not flag invalid symbols"):
        impl.tic_tac_toe_check(tmp1)
Пример #22
0
 def test_tic_tac_toe_check_doesnt_return_empty_string_as_winner(self):
     winner = tic_tac_toe_check(["x", "o", "x", "", "", "", "x", "o", "x"])
     assert winner != ""
Пример #23
0
 def test_tic_tac_toe_check_only_accepts_lists(self, board):
     with pytest.raises(
             TypeError,
             message=
             "Method is supposed to raise TypeError on non-list inputs"):
         tic_tac_toe_check(board)
Пример #24
0
def test_tic_tac_toe_check_partial_board():
    tmp1 = list(FULL_BOARD_CONFIG)
    tmp1[0] = ''
    assert impl.tic_tac_toe_check(
        tmp1) == None, "fails to return None when there is no winner"
Пример #25
0
def test_tic_tac_toe_check_no_winning_pattern():
    tmp1 = list(FULL_BOARD_CONFIG)
    assert impl.tic_tac_toe_check(
        tmp1) == None, "fails to return None when there is no winner"
Пример #26
0
 def test_tic_tac_toe_check_returns_none_on_list_of_empties(self):
     value = tic_tac_toe_check(["", "", "", "", "", "", "", "", ""])
     assert value is None
Пример #27
0
def test_tic_tac_toe_check_incorrect_board_size():
    with pytest.raises(ValueError, message="does not flag invalid board size"):
        impl.tic_tac_toe_check(['x'] * 3)
Пример #28
0
 def test_tic_tac_toe_check_returns_none_on_no_winners(self):
     winner = tic_tac_toe_check(
         ["x", "o", "x", "x", "x", "o", "o", "x", "o"])
     assert winner is None
Пример #29
0
def test_tic_tac_toe_check_not_o():
    tmp1 = list(FULL_BOARD_CONFIG.replace('o', 'd'))
    with pytest.raises(ValueError, message="does not flag invalid symbols"):
        impl.tic_tac_toe_check(tmp1)
Пример #30
0
def test_tic_tac_toe_check_x_based_winning_pattern():
    tmp1 = list(FULL_BOARD_CONFIG)
    tmp1[6] = 'x'
    assert impl.tic_tac_toe_check(
        tmp1) == 'x', "fails to recognize x based winning pattern"