mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-07 00:11:46 +00:00
Co-authored-by: Kallinteris Andreas <30759571+Kallinteris-Andreas@users.noreply.github.com> Co-authored-by: Jet <38184875+jjshoots@users.noreply.github.com> Co-authored-by: Omar Younis <42100908+younik@users.noreply.github.com>
26 lines
867 B
Python
26 lines
867 B
Python
"""Test suite for ClipAction wrapper."""
|
|
|
|
import numpy as np
|
|
|
|
from gymnasium.spaces import Box
|
|
from gymnasium.wrappers import ClipAction
|
|
from tests.testing_env import GenericTestEnv
|
|
from tests.wrappers.utils import record_action_step
|
|
|
|
|
|
def test_clip_action_wrapper():
|
|
"""Test that the action is correctly clipped to the base environment action space."""
|
|
env = GenericTestEnv(
|
|
action_space=Box(np.array([0, 0, 3]), np.array([1, 2, 4])),
|
|
step_func=record_action_step,
|
|
)
|
|
wrapped_env = ClipAction(env)
|
|
|
|
sampled_action = np.array([-1, 5, 3.5], dtype=np.float32)
|
|
assert sampled_action not in env.action_space
|
|
assert sampled_action in wrapped_env.action_space
|
|
|
|
_, _, _, _, info = wrapped_env.step(sampled_action)
|
|
assert np.all(info["action"] in env.action_space)
|
|
assert np.all(info["action"] == np.array([0, 2, 3.5]))
|