def test_updateState_Not_First_Shift(self): param = Parameters() param.num_processors = 2 self.coreObj = Core(param) for mock_processor in self.coreObj.processors: mock_processor.isIdle = MagicMock(return_value=False) mock_event = Event() mock_event.executeEvent = MagicMock() mock_event.eventTime = Constants.SIMULATION_INITIAL_TIME + 1 * 3600 + 1 self.coreObj.updateState(mock_event) mock_event = Event() mock_event.executeEvent = MagicMock() mock_event.eventTime = Constants.SIMULATION_INITIAL_TIME + 5 * 3600 + 1 self.coreObj.updateState(mock_event) self.assertEqual( self.coreObj.currentTime, Constants.SIMULATION_INITIAL_TIME + 5 * 3600 + 1, "The current time should be updated to SIMULATION_INITIAL_TIME + 5*3600 + 1" ) self.assertEqual( self.coreObj.serviceProcessors, (5 * 3600 + 1) * 2, "The service processors time should be (5*3600 + 1) * 2 (2 service processors)" ) self.assertEqual(self.coreObj.idleProcessors, 0, "The idle time should be 0")
def setUpClass(cls): cls.setWithShifts(True) param = Parameters() param.num_processors = Constants.DEFAULT_PROCESSORS shift_duration = [5, 5, 2, 2] shift_type = [ Constants.ENTREGA, Constants.ENTREGA, Constants.RECOGIDA, Constants.DUAL ] shift_factor = 3600 # hours param.setParameters(shift_duration, shift_type, shift_factor) cls.coreObj = Core(param) cls.coreObj.output_file = open('./TEST_System.txt', "w+") cls.coreObj.parameters.output_file = Constants.OUTPUT_PATH + "TEST_System" cls.coreObj.run() cls.coreObj.output_file.close() with open(Constants.OUTPUT_PATH + 'TEST_System.csv', "r") as read: header = read.readline().split(',') header = [tmp.split('\n')[0] for tmp in header] for i in range(len(header)): cls.cols[header[i]] = i line = read.readline() # [current_time, event_name, event_scheduled, event_time, idle_proc, service_proc, num_idle_proc, buff_len, queue_len, entities_system, shift] # Current_Time,Event_Name,Event_Scheduled,Event-Time,Idle_Processors,Service_Processors,Number_Idle_Processors,Buffer_Length,Queue_Length,Entities_System,Shift while line: row = TestSystemWithShifts.process_line(line) cls.static_big_matrix.append(row) line = read.readline()
def test_run(self): param = Parameters() param.num_processors = 2 self.coreObj = Core(param) self.coreObj.output_file = open('./TEST.txt', "w+") self.coreObj.parameters.output_file = "TEST" self.coreObj.run() self.coreObj.output_file.close() self.assertEquals( self.coreObj.eventsList.qsize(), 0, "The length should be 0 because the simulation ended") obj = self.coreObj.eventsList self.assertIsNotNone("The object is not none", obj) with open('./TEST.stats.csv', "r") as read: self.assertNotEquals(len(read.read()), 0, "The file should not be empty")
def test_updateState_With_2Idle_Processors(self): param = Parameters() param.num_processors = 2 self.coreObj = Core(param) for mock_processor in self.coreObj.processors: mock_processor.isIdle = MagicMock(return_value=True) mock_event = Event() mock_event.executeEvent = MagicMock() mock_event.eventTime = Constants.SIMULATION_INITIAL_TIME + 123 self.coreObj.updateState(mock_event) self.assertEqual( self.coreObj.currentTime, Constants.SIMULATION_INITIAL_TIME + 123, "The current time should be updated to SIMULATION_INITIAL_TIME + 123" ) self.assertEqual( self.coreObj.idleProcessors, 123 * 2, "The idle time should be 123 * 2 (2 idle processors)") self.assertEqual(self.coreObj.serviceProcessors, 0, "The service processors time should be 0")