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!']])
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)
def test_DeviceFactoryCreateSuccess(self): device_factory = DeviceFactory(Logger(False)) device = device_factory.create('DummyDevice', []) self.assertEqual(device.get_name(), 'DummyDevice')
def test_TaskFactoryInvalidNameReturnFalse(self): device_factory = DeviceFactory(Logger(False)) self.assertFalse(device_factory.create('InvalidNamedDevice', []))
def test_DeviceFactoryCreateWithParametersSuccess(self): device_factory = DeviceFactory(Logger(False)) device = device_factory.create('CommunicationSystem', ['node_id_01']) self.assertEqual(device.get_name(), 'CommunicationSystem')
def test_EnvironmentFactoryCreateSuccess(self): env_factory = EnvironmentFactory(Logger(False)) env_object = env_factory.create('DummyEnvironmentObject', []) self.assertEqual(env_object.get_name(), 'DummyEnvironmentObject')
def test_EnvironmentFactoryInvalidNameReturnFalse(self): env_factory = EnvironmentFactory(Logger(False)) self.assertFalse(env_factory.create('InvalidNameEnvironmentObject', []))
def test_EnvironmentFactoryCreateWithParametersSuccess(self): env_factory = EnvironmentFactory(Logger(False)) env_object = env_factory.create('CommunicationNetwork', []) self.assertEqual(env_object.get_name(), 'CommunicationNetwork')
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')
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)
def test_RunTaskSuccess(self): task = Counter([0, 10]) task.run_iteration(Logger(False)) self.assertEqual(task.get_state(), Task.State.RUNNING)
def test_RunTaskSuccess(self): task = DummyTask() task.run_iteration(Logger(False)) self.assertEqual(task.get_state(), Task.State.COMPLETED_OK)
def test_TaskFactoryInvalidNameReturnFalse(self): task_factory = TaskFactory(Logger(False)) self.assertFalse(task_factory.create('InvalidNamedTask', []))
def test_TaskFactoryCreateWithParametersSuccess(self): task_factory = TaskFactory(Logger(False)) task = task_factory.create('Counter', [0, 1]) self.assertEqual(task.get_name(), 'Counter')
def test_TaskFactoryCreateSuccess(self): task_factory = TaskFactory(Logger(False)) task = task_factory.create('DummyTask', []) self.assertEqual(task.get_name(), 'DummyTask')