From 53557bc9fd4df55cc9935bd7372b1af62342f8c6 Mon Sep 17 00:00:00 2001 From: Bam4d Date: Mon, 14 Feb 2022 09:18:15 +0000 Subject: [PATCH] test random number generator consistent on reset --- python/tests/random_seed_test.py | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/python/tests/random_seed_test.py b/python/tests/random_seed_test.py index b50f8e8ac..411a9b4fe 100644 --- a/python/tests/random_seed_test.py +++ b/python/tests/random_seed_test.py @@ -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 +