import unittest

import pymasep as pm
from test.unit.mocks.game_mock import GameMock
from test.unit.mocks.controller_mock import ControllerMock


class TestController(unittest.TestCase):

    def test_init(self):
        """
        :test : pm.common.Controller()
        :condition : -
        :main_result : Controller is initialized
        """
        env = pm.common.Environment()
        ctrl = pm.common.Controller(environment=env)
        self.assertIsInstance(ctrl, pm.common.Controller)
        self.assertEqual(env, ctrl.environment)

    def test_action_choice(self):
        """
        :test : pm.common.Controller.action_choice()
        :condition: -
        :main_return : an action is returned
        """
        env = pm.common.Environment()
        game = GameMock()
        observation = pm.common.State(environment=env, name='state',
                                      template=game.templates['DefaultStateTemplate'])
        agent = pm.common.Agent(environment=env, name='agent',
                                template=game.templates['DefaultAgentTemplate'])
        controller = ControllerMock(env)
        action = controller.action_choice(observation, agent)
        self.assertIsInstance(action, pm.common.Action)
