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
|
|
|
|
|
|
|
|
2019-10-19 06:59:56 +09: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()
|
|
|
|
|
2019-10-19 06:59:56 +09:00
|
|
|
if env_id == 'Blackjack-v0':
|
|
|
|
space = spaces.Tuple((
|
|
|
|
spaces.Discrete(32),
|
|
|
|
spaces.Discrete(11),
|
|
|
|
spaces.Discrete(2)))
|
|
|
|
wrapped_space = spaces.Box(-np.inf, np.inf,
|
|
|
|
[32 + 11 + 2], dtype=np.float32)
|
|
|
|
elif env_id == 'KellyCoinflip-v0':
|
|
|
|
space = spaces.Tuple((
|
|
|
|
spaces.Box(0, 250.0, [1], dtype=np.float32),
|
|
|
|
spaces.Discrete(300 + 1)))
|
|
|
|
wrapped_space = spaces.Box(-np.inf, np.inf,
|
|
|
|
[1 + (300 + 1)], dtype=np.float32)
|
|
|
|
|
|
|
|
assert space.contains(obs)
|
|
|
|
assert wrapped_space.contains(wrapped_obs)
|