Files
Gymnasium/tests/experimental/wrappers/test_lambda_action.py

20 lines
760 B
Python
Raw Normal View History

2022-12-10 22:04:14 +00:00
"""Test suite for LambdaActionV0."""
2022-11-20 00:57:10 +01:00
2022-12-10 22:04:14 +00:00
from gymnasium.experimental.wrappers import LambdaActionV0
2022-11-20 00:57:10 +01:00
from gymnasium.spaces import Box
2022-12-10 22:04:14 +00:00
from tests.experimental.wrappers.utils import record_action_step
2022-11-20 00:57:10 +01:00
from tests.testing_env import GenericTestEnv
2022-12-05 19:14:56 +00:00
def test_lambda_action_wrapper():
"""Tests LambdaAction through checking that the action taken is transformed by function."""
2022-12-10 22:04:14 +00:00
env = GenericTestEnv(step_func=record_action_step)
2022-12-05 19:14:56 +00:00
wrapped_env = LambdaActionV0(env, lambda action: action - 2, Box(2, 3))
sampled_action = wrapped_env.action_space.sample()
assert sampled_action not in env.action_space
_, _, _, _, info = wrapped_env.step(sampled_action)
assert info["action"] in env.action_space
assert sampled_action - 2 == info["action"]