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_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_step(): under_test = ConnectFourGame() expected = 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], [0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0], ] ) under_test.step(0) assert np.array_equal(under_test.board, expected) assert under_test.turn == "O"
def test_reset(): under_test = ConnectFourGame() expected = 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], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], ] ) # Do some stuff under_test.step(1) under_test.step(2) under_test.step(1) under_test.step(4) under_test.reset() assert np.array_equal(under_test.board, 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
def test_step_return_values(): under_test = ConnectFourGame() 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], [0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0], ] ) expected_reward = 0.0 expected_done = False 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