def test_generate_reports_and_salary(self, mock_wb_manager): # test generate_report_and_salary method mock_wb_manager.side_effect = MockWorkbookManager conveyor = Conveyor(3, (6, 3, 1), 3, 'test.xlsx', 'Bombs') # bomb is not broken empty_bomb = Bomb(1, 0) percents = [] # 9 bombs with stikers for bomb in generate_minions_stikers(conveyor, empty_bomb): conveyor.bombs = [bomb] conveyor.motivation_report = [] conveyor.generate_reports_and_salary() percents.append(conveyor.percentage_correct) number_is_broken = list(zip(*conveyor.qa_report)[1]).count(1) self.assertEqual(number_is_broken, 6) self.assertEqual(percents.count(100), 3) self.assertListEqual(conveyor.motivation_report, [(1, 6, 2, 1), (2, 6, 0, 3), (3, 3, 1, 5)]) # bomb is broken conveyor = Conveyor(3, (6, 3, 1), 3, 'test.xlsx', 'Bombs') empty_bomb = Bomb(1, 1) percents = [] # 9 bombs with stickers for bomb in generate_minions_stikers(conveyor, empty_bomb): conveyor.bombs = [bomb] conveyor.motivation_report = [] conveyor.generate_reports_and_salary() percents.append(conveyor.percentage_correct) number_is_broken = list(zip(*conveyor.qa_report)[1]).count(1) self.assertEqual(number_is_broken, 6) self.assertEqual(percents.count(100), 6) self.assertListEqual(conveyor.motivation_report, [(1, 6, 2, 1), (2, 6, 0, 3), (3, 3, 1, 5)])
def setup_conveyor_for_test(conveyor_item): test_conveyor = Conveyor(25) for i in range(25): test_conveyor.belt[i] = conveyor_item test_conveyor.top_workers[0].items = set() test_conveyor.bottom_workers[0].items = set() test_conveyor.top_workers[1].items = set() test_conveyor.bottom_workers[1].items = set(['A']) test_conveyor.top_workers[2].items = set() test_conveyor.bottom_workers[2].items = set(['B']) test_conveyor.top_workers[3].items = set() test_conveyor.bottom_workers[3].items = set(['A', 'B']) test_conveyor.top_workers[4].items = set() test_conveyor.bottom_workers[4].items = set(['F']) test_conveyor.top_workers[5].items = set(['A']) test_conveyor.bottom_workers[5].items = set() test_conveyor.top_workers[6].items = set(['A']) test_conveyor.bottom_workers[6].items = set(['A']) test_conveyor.top_workers[7].items = set(['A']) test_conveyor.bottom_workers[7].items = set(['B']) test_conveyor.top_workers[8].items = set(['A']) test_conveyor.bottom_workers[8].items = set(['A', 'B']) test_conveyor.top_workers[9].items = set(['A']) test_conveyor.bottom_workers[9].items = set(['F']) test_conveyor.top_workers[10].items = set(['B']) test_conveyor.bottom_workers[10].items = set() test_conveyor.top_workers[11].items = set(['B']) test_conveyor.bottom_workers[11].items = set(['A']) test_conveyor.top_workers[12].items = set(['B']) test_conveyor.bottom_workers[12].items = set(['B']) test_conveyor.top_workers[13].items = set(['B']) test_conveyor.bottom_workers[13].items = set(['A', 'B']) test_conveyor.top_workers[14].items = set(['B']) test_conveyor.bottom_workers[14].items = set(['F']) test_conveyor.top_workers[15].items = set(['A', 'B']) test_conveyor.bottom_workers[15].items = set() test_conveyor.top_workers[16].items = set(['A', 'B']) test_conveyor.bottom_workers[16].items = set(['A']) test_conveyor.top_workers[17].items = set(['A', 'B']) test_conveyor.bottom_workers[17].items = set(['B']) test_conveyor.top_workers[18].items = set(['A', 'B']) test_conveyor.bottom_workers[18].items = set(['A', 'B']) test_conveyor.top_workers[19].items = set(['A', 'B']) test_conveyor.bottom_workers[19].items = set(['F']) test_conveyor.top_workers[20].items = set(['F']) test_conveyor.bottom_workers[20].items = set() test_conveyor.top_workers[21].items = set(['F']) test_conveyor.bottom_workers[21].items = set(['A']) test_conveyor.top_workers[22].items = set(['F']) test_conveyor.bottom_workers[22].items = set(['B']) test_conveyor.top_workers[23].items = set(['F']) test_conveyor.bottom_workers[23].items = set(['A', 'B']) test_conveyor.top_workers[24].items = set(['F']) test_conveyor.bottom_workers[24].items = set(['F']) return test_conveyor
def test_run_conveyor(self, mock_wb_manager): # test run_conveyor method mock_wb_manager.side_effect = MockWorkbookManager conveyor = Conveyor(7, (6, 3, 1), 3, 'test.xlsx', 'Bombs') conveyor.run_conveyor() is_broken_cnt = 0 for bomb in conveyor.bombs: is_broken_cnt += 1 if bomb.is_broken else 0 # each bomb should be checked by different minions 3 times self.assertEqual(len(set(bomb.minions_stickers.keys())), 3) self.assertEqual(is_broken_cnt, 5)
def __init__(self, audiofiles_dir): self.siren = Siren(audiofiles_dir) self.conveyor = Conveyor() self.destroy_conveyor = DestroyCoveyor() # temp self.remove_stopper = RemoveStopper() # temp sorted_items, self.wating_times = fire_and_conveyor_time() print(sorted_items) func_dict = {'describe_fire_truck_start': self.siren.on, 'describe_fire_truck_end': self.siren.off, 'move_conveyor_start': self.conveyor.on, 'move_conveyor_end': self.conveyor.off, 'destroy_coveyor_start': self.destroy_conveyor.on, 'destroy_coveyor_end': self.destroy_conveyor.off, 'remove_stopper_start': self.remove_stopper.on, 'remove_stopper_end': self.remove_stopper.off} sortfunc = SortFunctions(sorted_items, func_dict) self.func = sortfunc.func
def rand_init(details_min, details_max, time_min, time_max): """Генерує випадковий конвеєр по параметрам з аргументів details_min - мінімум деталей details_max - максимум деталей time_min - мінамальний час обробки деталі та перенаголодження верстату time_max - максимальний час обратки деталі та переналогдження верстау """ number_of_details = random.randint(details_min, details_max) spent_time = [ random.randint(time_min, time_max) for i in range(number_of_details) ] reload_time = [[ random.randint(time_min, time_max) for i in range(number_of_details) ] for i in range(number_of_details)] for i in range(number_of_details): # заповнюємо головну діагональ нулями reload_time[i][i] = 0 Job = Conveyor(number_of_details, spent_time, reload_time) return Job
def excel_file(input_file): """""" book = xlrd.open_workbook(input_file) sheet = book.sheet_by_index(0) if sheet.nrows != sheet.ncols + 2: return "SizeError" else: try: number_of_details = sheet.ncols spent_time = [ int(sheet.cell(0, i).value) for i in range(number_of_details) ] reload_time = [[ int(sheet.cell(i + 2, j).value) for j in range(number_of_details) ] for i in range(number_of_details)] except ValueError: return "ValueError" Job = Conveyor(number_of_details, spent_time, reload_time) return Job
def keyboard(): """Шаблон для ручного вводу""" Job = Conveyor(3, [1, 1, 1], [[0, 1, 1], [1, 0, 1], [1, 1, 0]]) return Job
def test_end_of_belt(): test_conveyor_A = Conveyor(1) test_conveyor_A.belt[1] = 'A' test_conveyor_A.check_end_of_belt() test_conveyor_B = Conveyor(1) test_conveyor_B.belt[1] = 'B' test_conveyor_B.check_end_of_belt() test_conveyor_F = Conveyor(1) test_conveyor_F.belt[1] = 'F' test_conveyor_F.check_end_of_belt() test_conveyor_space = Conveyor(1) test_conveyor_space.belt[1] = ' ' test_conveyor_space.check_end_of_belt() assert test_conveyor_A.finished_items == 0 assert test_conveyor_A.untouched_A_components == 1 assert test_conveyor_A.untouched_B_components == 0 assert test_conveyor_B.finished_items == 0 assert test_conveyor_B.untouched_A_components == 0 assert test_conveyor_B.untouched_B_components == 1 assert test_conveyor_F.finished_items == 1 assert test_conveyor_F.untouched_A_components == 0 assert test_conveyor_F.untouched_B_components == 0 assert test_conveyor_space.finished_items == 0 assert test_conveyor_space.untouched_A_components == 0 assert test_conveyor_space.untouched_B_components == 0