Example #1
0
def test_base_envs():
    """Test parts of base_envs not covered elsewhere."""

    class NewEnv(base_envs.TabularModelMDP):
        def __init__(self):
            nS = 3
            nA = 2
            transition_matrix = np.random.rand(nS, nA, nS)
            transition_matrix /= transition_matrix.sum(axis=2)[:, :, None]
            reward_matrix = np.random.rand(nS)
            super().__init__(
                transition_matrix=transition_matrix,
                reward_matrix=reward_matrix,
            )

    env = NewEnv()

    assert np.all(np.eye(3) == env.feature_matrix)

    envs.test_premature_step(env, skip_fn=pytest.skip, raises_fn=pytest.raises)

    env.reset()
    assert env.n_actions_taken == 0
    env.step(env.action_space.sample())
    assert env.n_actions_taken == 1
    env.step(env.action_space.sample())
    assert env.n_actions_taken == 2
Example #2
0
 def test_premature_step(self, env):
     """Test that you must call reset() before calling step()."""
     bench_test.test_premature_step(
         env,
         skip_fn=pytest.skip,
         raises_fn=pytest.raises,
     )
Example #3
0
 def test_premature_step(self, env: gym.Env):
     """Tests if step() before reset() raises error."""
     envs.test_premature_step(env,
                              skip_fn=pytest.skip,
                              raises_fn=pytest.raises)