diff --git a/simulation-system/libs/csle-common/tests/test_simulation_config_dao.py b/simulation-system/libs/csle-common/tests/test_simulation_config_dao.py index 41329936b..57f9f8319 100644 --- a/simulation-system/libs/csle-common/tests/test_simulation_config_dao.py +++ b/simulation-system/libs/csle-common/tests/test_simulation_config_dao.py @@ -1,4 +1,10 @@ from csle_common.dao.simulation_config.action import Action +from csle_common.dao.simulation_config.action_space_config import ActionSpaceConfig +from csle_common.dao.simulation_config.value_type import ValueType +from csle_common.dao.simulation_config.agent_log import AgentLog +from csle_common.dao.simulation_config.env_parameter import EnvParameter +from csle_common.dao.simulation_config.env_parameters_config import EnvParametersConfig +from csle_common.dao.simulation_config.initial_state_distribution_config import InitialStateDistributionConfig class TestSimulationConfigDaoSuite: @@ -22,3 +28,89 @@ def test_action(self) -> None: action.to_dict()) assert (Action.from_dict(action.to_dict()) == action) + + def test_action_space_config(self) -> None: + """ + Tests creation and dict conversion of the ActionSpaceConfig DAO + + :return: None + """ + + action_space_config = ActionSpaceConfig(actions=[Action(id=1, descr="test")], + player_id=1, action_type=ValueType.INTEGER) + + assert isinstance(action_space_config.to_dict(), dict) + assert isinstance(ActionSpaceConfig.from_dict(action_space_config.to_dict()), + ActionSpaceConfig) + assert (ActionSpaceConfig.from_dict(action_space_config.to_dict()).to_dict() == + action_space_config.to_dict()) + assert (ActionSpaceConfig.from_dict(action_space_config.to_dict()) == + action_space_config) + + def test_agent_log(self) -> None: + """ + Tests creation and dict conversion of the AgentLog DAO + + :return: None + """ + + agent_log = AgentLog() + + assert isinstance(agent_log.to_dict(), dict) + assert isinstance(AgentLog.from_dict(agent_log.to_dict()), + AgentLog) + assert (AgentLog.from_dict(agent_log.to_dict()).to_dict() == + agent_log.to_dict()) + assert (AgentLog.from_dict(agent_log.to_dict()) == + agent_log) + + def test_env_parameter(self) -> None: + """ + Tests creation and dict conversion of the EnvParameter DAO + + :return: None + """ + + env_parameter = EnvParameter(id=1, name="test", descr="test1") + + assert isinstance(env_parameter.to_dict(), dict) + assert isinstance(EnvParameter.from_dict(env_parameter.to_dict()), + EnvParameter) + assert (EnvParameter.from_dict(env_parameter.to_dict()).to_dict() == + env_parameter.to_dict()) + assert (EnvParameter.from_dict(env_parameter.to_dict()) == + env_parameter) + + def test_env_parameters_config(self) -> None: + """ + Tests creation and dict conversion of the EnvParametersConfig DAO + + :return: None + """ + + env_parameters_config = EnvParametersConfig(parameters=[EnvParameter(id=1, name="test", descr="test1")]) + + assert isinstance(env_parameters_config.to_dict(), dict) + assert isinstance(EnvParametersConfig.from_dict(env_parameters_config.to_dict()), + EnvParametersConfig) + assert (EnvParametersConfig.from_dict(env_parameters_config.to_dict()).to_dict() == + env_parameters_config.to_dict()) + assert (EnvParametersConfig.from_dict(env_parameters_config.to_dict()) == + env_parameters_config) + + def test_initial_state_distribution_config(self) -> None: + """ + Tests creation and dict conversion of the InitialStateDistributionConfig DAO + + :return: None + """ + + initial_state_distribution_config = InitialStateDistributionConfig(initial_state_distribution=[0.1, 0.9]) + + assert isinstance(initial_state_distribution_config.to_dict(), dict) + assert isinstance(InitialStateDistributionConfig.from_dict(initial_state_distribution_config.to_dict()), + InitialStateDistributionConfig) + assert (InitialStateDistributionConfig.from_dict(initial_state_distribution_config.to_dict()).to_dict() == + initial_state_distribution_config.to_dict()) + assert (InitialStateDistributionConfig.from_dict(initial_state_distribution_config.to_dict()) == + initial_state_distribution_config)