2019-08-23 23:49:12 +02:00
|
|
|
import pytest
|
|
|
|
|
2019-10-19 06:59:56 +09:00
|
|
|
import numpy as np
|
|
|
|
|
2019-08-23 23:49:12 +02:00
|
|
|
import gym
|
|
|
|
from gym.wrappers import FlattenObservation
|
2019-10-19 06:59:56 +09:00
|
|
|
from gym import spaces
|
2019-08-23 23:49:12 +02:00
|
|
|
|
|
|
|
|
2021-07-29 02:26:34 +02:00
|
|
|
@pytest.mark.parametrize("env_id", ["Blackjack-v0", "KellyCoinflip-v0"])
|
2019-08-23 23:49:12 +02:00
|
|
|
def test_flatten_observation(env_id):
|
|
|
|
env = gym.make(env_id)
|
|
|
|
wrapped_env = FlattenObservation(env)
|
|
|
|
|
|
|
|
obs = env.reset()
|
|
|
|
wrapped_obs = wrapped_env.reset()
|
|
|
|
|
2021-07-29 02:26:34 +02:00
|
|
|
if env_id == "Blackjack-v0":
|
2021-07-29 12:42:48 -04:00
|
|
|
space = spaces.Tuple((spaces.Discrete(32), spaces.Discrete(11), spaces.Discrete(2)))
|
2021-07-29 02:26:34 +02:00
|
|
|
wrapped_space = spaces.Box(-np.inf, np.inf, [32 + 11 + 2], dtype=np.float32)
|
|
|
|
elif env_id == "KellyCoinflip-v0":
|
2021-07-29 12:42:48 -04:00
|
|
|
space = spaces.Tuple((spaces.Box(0, 250.0, [1], dtype=np.float32), spaces.Discrete(300 + 1)))
|
2021-07-29 02:26:34 +02:00
|
|
|
wrapped_space = spaces.Box(-np.inf, np.inf, [1 + (300 + 1)], dtype=np.float32)
|
2019-10-19 06:59:56 +09:00
|
|
|
|
|
|
|
assert space.contains(obs)
|
|
|
|
assert wrapped_space.contains(wrapped_obs)
|