Skip to content

Commit

Permalink
test random number generator consistent on reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Bam4d committed Feb 14, 2022
1 parent aea0a49 commit 53557bc
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions python/tests/random_seed_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,50 @@ def test_random_seed_consistency():
env1.reset()
env2.reset()

def test_random_seed_consistency_after_reset():
env1 = create_env()
env2 = create_env()
env1.seed(10)
env2.seed(10)

for i in range(10):
action1 = env1.action_space.sample()
action2 = env2.action_space.sample()

assert action1 == action2

obs1, reward1, done1, info1 = env1.step(action1)
obs2, reward2, done2, info2 = env2.step(action2)

global_obs1 = env1.render(observer='global', mode='rgb_array')
global_obs2 = env2.render(observer='global', mode='rgb_array')

assert np.all(global_obs1 == global_obs2), f'global obs differ at test 1 step {i}'

assert np.all(obs1 == obs2)
assert reward1 == reward2
assert done1 == done2
assert info1 == info2

env1.reset()
env2.reset()

for i in range(10):
action1 = env1.action_space.sample()
action2 = env2.action_space.sample()

assert action1 == action2

obs1, reward1, done1, info1 = env1.step(action1)
obs2, reward2, done2, info2 = env2.step(action2)

global_obs1 = env1.render(observer='global', mode='rgb_array')
global_obs2 = env2.render(observer='global', mode='rgb_array')

assert np.all(global_obs1 == global_obs2), f' global obs differ at test 2 step {i}'

assert np.all(obs1 == obs2)
assert reward1 == reward2
assert done1 == done2
assert info1 == info2

0 comments on commit 53557bc

Please sign in to comment.