File size: 1,647 Bytes
079c32c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import pytest
import numpy as np
from easydict import EasyDict
from zoo.box2d.lunarlander.envs import LunarLanderEnv


@pytest.mark.envtest
@pytest.mark.parametrize(
    'cfg', [
        EasyDict({
            'env_name': 'LunarLander-v2',
            'act_scale': False,
            'replay_path': None,
            'replay_path_gif': None,
            'save_replay_gif': False,
        }),
        EasyDict({
            'env_name': 'LunarLanderContinuous-v2',
            'act_scale': True,
            'replay_path': None,
            'replay_path_gif': None,
            'save_replay_gif': False,
        })
    ]
)
class TestLunarLanderEnvEnv:
    """
        Overview:
            The env created for testing the LunarLander environment.
            It is used to check information such as observation space, action space and reward space.
    """

    def test_naive(self, cfg):
        env = LunarLanderEnv(cfg)
        env.seed(314)
        assert env._seed == 314
        obs = env.reset()
        assert obs['observation'].shape == (8, )
        for i in range(10):
            random_action = env.random_action()
            timestep = env.step(random_action)
            print(timestep)
            assert isinstance(timestep.obs['observation'], np.ndarray)
            assert isinstance(timestep.done, bool)
            assert timestep.obs['observation'].shape == (8, )
            assert timestep.reward.shape == (1, )
            assert timestep.reward >= env.reward_space.low
            assert timestep.reward <= env.reward_space.high
        print(env.observation_space, env.action_space, env.reward_space)
        env.close()