def test_step_return_values_win():
    under_test = ConnectFourGame()

    under_test.board = np.array(
        [
            [0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0],
            [2, 2, 2, 0, 0, 0, 0],
            [1, 1, 1, 0, 0, 0, 0],
        ]
    )

    expected_observation = np.array(
        [
            [0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0],
            [2, 2, 2, 0, 0, 0, 0],
            [1, 1, 1, 1, 0, 0, 0],
        ]
    )

    expected_reward = 100.0
    expected_done = True
    expected_info = {}

    observation, reward, done, info = under_test.step(3)

    assert np.array_equal(observation, expected_observation)
    assert expected_reward == reward
    assert expected_done == done
    assert expected_info == info
def test_not_is_draw_with_full_board_and_winner():
    under_test = ConnectFourGame()
    under_test.board = np.array(
        [
            [2, 1, 2, 2, 1, 2, 1],
            [2, 1, 2, 2, 1, 2, 1],
            [2, 1, 2, 2, 1, 2, 1],
            [1, 2, 1, 2, 2, 1, 2],
            [1, 2, 1, 1, 2, 1, 1],
            [1, 2, 1, 1, 2, 1, 2],
        ]
    )

    assert not under_test.is_draw()
def test_not_is_draw():
    under_test = ConnectFourGame()
    under_test.board = np.array(
        [
            [1, 0, 2, 0, 2, 0, 0],
            [1, 0, 2, 0, 1, 0, 0],
            [2, 0, 1, 0, 2, 0, 0],
            [1, 0, 2, 0, 1, 0, 0],
            [1, 0, 2, 0, 2, 0, 1],
            [1, 0, 2, 0, 1, 1, 2],
        ]
    )

    assert not under_test.is_draw()
def test_error_if_col_full():
    under_test = ConnectFourGame()

    under_test.board = np.array(
        [
            [2, 0, 0, 0, 0, 0, 0],
            [1, 0, 0, 0, 0, 0, 0],
            [2, 0, 0, 0, 0, 0, 0],
            [1, 0, 0, 0, 0, 0, 0],
            [2, 0, 0, 0, 0, 0, 0],
            [1, 0, 0, 0, 0, 0, 0],
        ]
    )

    with pytest.raises(ValueError):
        under_test.step(0)
def test_get_valid_moves_with_some_columns_full():
    under_test = ConnectFourGame()
    under_test.board = np.array(
        [
            [1, 0, 2, 0, 2, 0, 0],
            [1, 0, 2, 0, 1, 0, 0],
            [2, 0, 1, 0, 2, 0, 0],
            [1, 0, 2, 0, 1, 0, 0],
            [1, 0, 2, 0, 2, 0, 1],
            [1, 0, 2, 0, 1, 1, 2],
        ]
    )

    expected = [1, 3, 5, 6]

    actual = under_test.get_valid_moves()

    assert actual == expected
def test_step_return_values_draw():
    under_test = ConnectFourGame()

    under_test.board = np.array(
        [
            [0, 1, 2, 2, 1, 2, 1],
            [2, 1, 2, 2, 1, 2, 1],
            [2, 1, 2, 2, 1, 2, 1],
            [1, 2, 1, 1, 2, 1, 2],
            [1, 2, 1, 1, 2, 1, 1],
            [1, 2, 1, 1, 2, 1, 2],
        ]
    )
    under_test.turn = "O"

    expected_observation = np.array(
        [
            [2, 1, 2, 2, 1, 2, 1],
            [2, 1, 2, 2, 1, 2, 1],
            [2, 1, 2, 2, 1, 2, 1],
            [1, 2, 1, 1, 2, 1, 2],
            [1, 2, 1, 1, 2, 1, 1],
            [1, 2, 1, 1, 2, 1, 2],
        ]
    )

    expected_reward = -50.0
    expected_done = True
    expected_info = {}

    observation, reward, done, info = under_test.step(0)

    assert np.array_equal(observation, expected_observation)
    assert expected_reward == reward
    assert expected_done == done
    assert expected_info == info