Пример #1
0
    def test_RunDeviceSuccess(self):
        communication_network = CommunicationNetwork([['A', 'B']])

        com_sys_A = CommunicationSystem()
        com_sys_A.set_agent_id('A')
        com_sys_A.set_outgoing_data('Hello, I am Alice!')
        communication_network = com_sys_A.write_to_environment(
            Logger(False), communication_network)

        com_sys_B = CommunicationSystem()
        com_sys_B.set_agent_id('B')
        com_sys_B.set_outgoing_data('Hello, I am Bob!')
        communication_network = com_sys_B.write_to_environment(
            Logger(False), communication_network)

        com_sys_A.read_from_environment(Logger(False), communication_network)
        com_sys_B.read_from_environment(Logger(False), communication_network)

        self.assertEqual(com_sys_A.get_ingoing_data(),
                         [['B', 'Hello, I am Bob!']])
        self.assertEqual(com_sys_B.get_ingoing_data(),
                         [['A', 'Hello, I am Alice!']])
Пример #2
0
    def test_RunTaskSuccess(self):
        communication_network = CommunicationNetwork([['A', 'B']])

        com_device_A = CommunicationSystem()
        com_device_A.set_agent_id('A')
        device_collection_A = list()
        device_collection_A.append(com_device_A)
        task_A = AverageConsensus([10.0, 0.5])
        task_A.set_agent_id('A')

        com_device_B = CommunicationSystem()
        com_device_B.set_agent_id('B')
        device_collection_B = list()
        device_collection_B.append(com_device_B)
        task_B = AverageConsensus([20.0, 0.5])
        task_B.set_agent_id('B')

        for i in range(0, 2):
            device_collection_A[0].read_from_environment(
                Logger(False), communication_network)
            device_collection_B[0].read_from_environment(
                Logger(False), communication_network)

            device_collection_A = task_A.run_iteration(Logger(False),
                                                       device_collection_A)
            device_collection_B = task_B.run_iteration(Logger(False),
                                                       device_collection_B)

            communication_network = device_collection_A[
                0].write_to_environment(Logger(False), communication_network)
            communication_network = device_collection_B[
                0].write_to_environment(Logger(False), communication_network)

        mean_value = 15.0
        epsilon = 0.05
        task_A_value = task_A.get_variable()
        task_B_value = task_B.get_variable()
        self.assertTrue(abs(task_A_value - mean_value) < epsilon)
        self.assertTrue(abs(task_B_value - mean_value) < epsilon)
Пример #3
0
    def test_DeviceFactoryCreateSuccess(self):
        device_factory = DeviceFactory(Logger(False))
        device = device_factory.create('DummyDevice', [])

        self.assertEqual(device.get_name(), 'DummyDevice')
Пример #4
0
    def test_TaskFactoryInvalidNameReturnFalse(self):
        device_factory = DeviceFactory(Logger(False))

        self.assertFalse(device_factory.create('InvalidNamedDevice', []))
Пример #5
0
    def test_DeviceFactoryCreateWithParametersSuccess(self):
        device_factory = DeviceFactory(Logger(False))
        device = device_factory.create('CommunicationSystem', ['node_id_01'])

        self.assertEqual(device.get_name(), 'CommunicationSystem')
Пример #6
0
    def test_EnvironmentFactoryCreateSuccess(self):
        env_factory = EnvironmentFactory(Logger(False))
        env_object = env_factory.create('DummyEnvironmentObject', [])

        self.assertEqual(env_object.get_name(), 'DummyEnvironmentObject')
Пример #7
0
    def test_EnvironmentFactoryInvalidNameReturnFalse(self):
        env_factory = EnvironmentFactory(Logger(False))

        self.assertFalse(env_factory.create('InvalidNameEnvironmentObject',
                                            []))
Пример #8
0
    def test_EnvironmentFactoryCreateWithParametersSuccess(self):
        env_factory = EnvironmentFactory(Logger(False))
        env_object = env_factory.create('CommunicationNetwork', [])

        self.assertEqual(env_object.get_name(), 'CommunicationNetwork')
Пример #9
0
    def test_RunTaskSuccess(self):
        communication_network = CommunicationNetwork([['A', 'B']])

        com_device_A = CommunicationSystem()
        com_device_A.set_agent_id('A')
        device_collection_A = list()
        device_collection_A.append(com_device_A)
        task_A = Ping('ping')

        com_device_B = CommunicationSystem()
        com_device_B.set_agent_id('B')
        device_collection_B = list()
        device_collection_B.append(com_device_B)
        task_B = Ping('pong')

        device_collection_A[0].read_from_environment(Logger(False),
                                                     communication_network)
        device_collection_B[0].read_from_environment(Logger(False),
                                                     communication_network)

        device_collection_A = task_A.run_iteration(Logger(False),
                                                   device_collection_A)
        device_collection_B = task_B.run_iteration(Logger(False),
                                                   device_collection_B)

        communication_network = device_collection_A[0].write_to_environment(
            Logger(False), communication_network)
        communication_network = device_collection_B[0].write_to_environment(
            Logger(False), communication_network)

        self.assertEqual(task_A.get_variable(), 'ping')
        self.assertEqual(task_B.get_variable(), 'pong')

        device_collection_A[0].read_from_environment(Logger(False),
                                                     communication_network)
        device_collection_B[0].read_from_environment(Logger(False),
                                                     communication_network)

        device_collection_A = task_A.run_iteration(Logger(False),
                                                   device_collection_A)
        device_collection_B = task_B.run_iteration(Logger(False),
                                                   device_collection_B)

        communication_network = device_collection_A[0].write_to_environment(
            Logger(False), communication_network)
        communication_network = device_collection_B[0].write_to_environment(
            Logger(False), communication_network)

        self.assertEqual(task_A.get_variable(), 'ping')
        self.assertEqual(task_B.get_variable(), 'pong')

        device_collection_A[0].read_from_environment(Logger(False),
                                                     communication_network)
        device_collection_B[0].read_from_environment(Logger(False),
                                                     communication_network)

        device_collection_A = task_A.run_iteration(Logger(False),
                                                   device_collection_A)
        device_collection_B = task_B.run_iteration(Logger(False),
                                                   device_collection_B)

        communication_network = device_collection_A[0].write_to_environment(
            Logger(False), communication_network)
        communication_network = device_collection_B[0].write_to_environment(
            Logger(False), communication_network)

        self.assertEqual(task_A.get_variable(), 'ping')
        self.assertEqual(task_B.get_variable(), 'pong')

        device_collection_A[0].read_from_environment(Logger(False),
                                                     communication_network)
        device_collection_B[0].read_from_environment(Logger(False),
                                                     communication_network)

        device_collection_A = task_A.run_iteration(Logger(False),
                                                   device_collection_A)
        device_collection_B = task_B.run_iteration(Logger(False),
                                                   device_collection_B)

        communication_network = device_collection_A[0].write_to_environment(
            Logger(False), communication_network)
        device_collection_B[0].write_to_environment(Logger(False),
                                                    communication_network)

        self.assertEqual(task_A.get_variable(), 'ping')
        self.assertEqual(task_B.get_variable(), 'pong')
Пример #10
0
    def test_CompletedTaskSuccess(self):
        task = Counter([0, 10])
        while task.get_state() != Task.State.COMPLETED_OK:
            task.run_iteration(Logger(False))

        self.assertEqual(task.get_state(), Task.State.COMPLETED_OK)
Пример #11
0
    def test_RunTaskSuccess(self):
        task = Counter([0, 10])
        task.run_iteration(Logger(False))

        self.assertEqual(task.get_state(), Task.State.RUNNING)
Пример #12
0
    def test_RunTaskSuccess(self):
        task = DummyTask()
        task.run_iteration(Logger(False))

        self.assertEqual(task.get_state(), Task.State.COMPLETED_OK)
Пример #13
0
    def test_TaskFactoryInvalidNameReturnFalse(self):
        task_factory = TaskFactory(Logger(False))

        self.assertFalse(task_factory.create('InvalidNamedTask', []))
Пример #14
0
    def test_TaskFactoryCreateWithParametersSuccess(self):
        task_factory = TaskFactory(Logger(False))
        task = task_factory.create('Counter', [0, 1])

        self.assertEqual(task.get_name(), 'Counter')
Пример #15
0
    def test_TaskFactoryCreateSuccess(self):
        task_factory = TaskFactory(Logger(False))
        task = task_factory.create('DummyTask', [])

        self.assertEqual(task.get_name(), 'DummyTask')