def test_observation_action_space(self):
        """Tests the observation and action spaces upon initialization."""
        env = WaveAttenuationEnv(sim_params=self.sim_params,
                                 scenario=self.scenario,
                                 env_params=self.env_params)

        # check the observation space
        self.assertTrue(
            test_space(env.observation_space,
                       expected_size=2 * env.scenario.vehicles.num_vehicles,
                       expected_min=0,
                       expected_max=1))

        # check the action space
        self.assertTrue(
            test_space(
                env.action_space,
                expected_size=env.scenario.vehicles.num_rl_vehicles,
                expected_min=-abs(
                    env.env_params.additional_params["max_decel"]),
                expected_max=env.env_params.additional_params["max_accel"]))

        env.terminate()
    def test_reset_no_same_length(self):
        """
        Tests that the reset method uses the original ring length when the
        range is set to None.
        """
        # setup env_params with not range
        env_params = deepcopy(self.env_params)
        env_params.additional_params["ring_length"] = None

        # create the environment
        env = WaveAttenuationEnv(sim_params=self.sim_params,
                                 scenario=self.scenario,
                                 env_params=env_params)

        # reset the network several times and check its length
        self.assertEqual(env.k.scenario.length(), LOOP_PARAMS["length"])
        env.reset()
        self.assertEqual(env.k.scenario.length(), LOOP_PARAMS["length"])
        env.reset()
        self.assertEqual(env.k.scenario.length(), LOOP_PARAMS["length"])
    def test_reset(self):
        """
        Tests that the reset method creating new ring lengths within the
        requested range.
        """
        # set a random seed to ensure the network lengths are always the same
        # during testing
        random.seed(9001)

        # create the environment
        env = WaveAttenuationEnv(sim_params=self.sim_params,
                                 scenario=self.scenario,
                                 env_params=self.env_params)

        # reset the network several times and check its length
        self.assertEqual(env.k.scenario.length(), 230)
        env.reset()
        self.assertEqual(env.k.scenario.length(), 239)
        env.reset()
        self.assertEqual(env.k.scenario.length(), 224)