2016-04-27 08:00:58 -07:00
|
|
|
import json # note: ujson fails this test due to float equality
|
|
|
|
import numpy as np
|
2017-02-11 22:17:02 -08:00
|
|
|
import pytest
|
2017-11-05 21:16:46 +03:00
|
|
|
from gym.spaces import Tuple, Box, Discrete, MultiDiscrete, MultiBinary, Dict
|
2016-04-27 08:00:58 -07:00
|
|
|
|
2017-02-11 22:17:02 -08:00
|
|
|
|
|
|
|
@pytest.mark.parametrize("space", [
|
Cleanup, removal of unmaintained code (#836)
* add dtype to Box
* remove board_game, debugging, safety, parameter_tuning environments
* massive set of breaking changes
- remove python logging module
- _step, _reset, _seed, _close => non underscored method
- remove benchmark and scoring folder
* Improve render("human"), now resizable, closable window.
* get rid of default step and reset in wrappers, so it doesn’t silently fail for people with underscore methods
* CubeCrash unit test environment
* followup fixes
* MemorizeDigits unit test envrionment
* refactored spaces a bit
fixed indentation
disabled test_env_semantics
* fix unit tests
* fixes
* CubeCrash, MemorizeDigits tested
* gym backwards compatibility patch
* gym backwards compatibility, followup fixes
* changelist, add spaces to main namespaces
* undo_logger_setup for backwards compat
* remove configuration.py
2018-01-25 18:20:14 -08:00
|
|
|
Discrete(3),
|
|
|
|
Tuple([Discrete(5), Discrete(10)]),
|
|
|
|
Tuple([Discrete(5), Box(low=np.array([0,0]),high=np.array([1,5]))]),
|
|
|
|
Tuple((Discrete(5), Discrete(2), Discrete(2))),
|
|
|
|
MultiDiscrete([ 2, 2, 100]),
|
|
|
|
Dict({"position": Discrete(5), "velocity": Box(low=np.array([0,0]),high=np.array([1,5]))}),
|
2017-02-11 22:17:02 -08:00
|
|
|
])
|
2016-04-27 08:00:58 -07:00
|
|
|
def test_roundtripping(space):
|
|
|
|
sample_1 = space.sample()
|
|
|
|
sample_2 = space.sample()
|
|
|
|
assert space.contains(sample_1)
|
|
|
|
assert space.contains(sample_2)
|
|
|
|
json_rep = space.to_jsonable([sample_1, sample_2])
|
|
|
|
|
|
|
|
json_roundtripped = json.loads(json.dumps(json_rep))
|
|
|
|
|
|
|
|
samples_after_roundtrip = space.from_jsonable(json_roundtripped)
|
|
|
|
sample_1_prime, sample_2_prime = samples_after_roundtrip
|
|
|
|
|
|
|
|
s1 = space.to_jsonable([sample_1])
|
|
|
|
s1p = space.to_jsonable([sample_1_prime])
|
|
|
|
s2 = space.to_jsonable([sample_2])
|
|
|
|
s2p = space.to_jsonable([sample_2_prime])
|
|
|
|
assert s1 == s1p, "Expected {} to equal {}".format(s1, s1p)
|
|
|
|
assert s2 == s2p, "Expected {} to equal {}".format(s2, s2p)
|