mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-20 22:12:03 +00:00
* Move tests to root with automatic PyCharm import refactoring. This will likely fail some tests * Changed entry point for a registration test env. * Move a stray lunar_lander test to tests/envs/... * black * Change the version from which importlib_metadata is replaced with importlib.metadata. Also requiring installing importlib_metadata for python 3.8 now. ??????????? * Undo last commit
30 lines
836 B
Python
30 lines
836 B
Python
import pytest
|
|
|
|
import numpy as np
|
|
|
|
import gym
|
|
from gym.wrappers import TransformObservation
|
|
|
|
|
|
@pytest.mark.parametrize("env_id", ["CartPole-v1", "Pendulum-v1"])
|
|
def test_transform_observation(env_id):
|
|
affine_transform = lambda x: 3 * x + 2
|
|
env = gym.make(env_id)
|
|
wrapped_env = TransformObservation(
|
|
gym.make(env_id), lambda obs: affine_transform(obs)
|
|
)
|
|
|
|
env.seed(0)
|
|
wrapped_env.seed(0)
|
|
|
|
obs = env.reset()
|
|
wrapped_obs = wrapped_env.reset()
|
|
assert np.allclose(wrapped_obs, affine_transform(obs))
|
|
|
|
action = env.action_space.sample()
|
|
obs, reward, done, _ = env.step(action)
|
|
wrapped_obs, wrapped_reward, wrapped_done, _ = wrapped_env.step(action)
|
|
assert np.allclose(wrapped_obs, affine_transform(obs))
|
|
assert np.allclose(wrapped_reward, reward)
|
|
assert wrapped_done == done
|