예제 #1
0
def test_player_win__board_not_full():
    game = TicTacToeGame()

    with patch("ai_moves.randint") as mock_random:
        game.place(7)
        mock_random.return_value = 1
        game.ai_move()

        game.place(8)
        mock_random.return_value = 2
        game.ai_move()

    with patch("sys.stdout", new=io.StringIO()) as stdout:
        game.place(9)

    assert stdout.getvalue().split("\n")[-2] == "Congratulations! You win!"
예제 #2
0
def test_draw():
    game = TicTacToeGame()

    with patch("ai_moves.randint") as mock_random:
        game.place(5)
        mock_random.return_value = 3
        game.ai_move()

        game.place(7)
        mock_random.return_value = 9
        game.ai_move()

        game.place(6)
        mock_random.return_value = 4
        game.ai_move()

        game.place(2)
        mock_random.return_value = 8
        game.ai_move()

    with patch("sys.stdout", new=io.StringIO()) as stdout:
        game.place(1)

    assert stdout.getvalue().split("\n")[-2] == "Its a TIE!"
예제 #3
0
def test_ai_win__board_not_full():
    game = TicTacToeGame()

    with patch("ai_moves.randint") as mock_random:
        game.place(7)
        mock_random.return_value = 1
        game.ai_move()

        game.place(8)
        mock_random.return_value = 2
        game.ai_move()

        game.place(5)
        mock_random.return_value = 3

        with patch("sys.stdout", new=io.StringIO()) as stdout:
            game.ai_move()

    assert stdout.getvalue().split("\n")[-2] == "Sorry you lost, keep trying!"