def test_perform(): auto = Task("a", auto_task=True, state=BaseTaskState.WORKING) auto.perform(0, seed=1234) assert auto.remaining_work_amount == auto.default_work_amount - 1 task = Task("task") task.state = BaseTaskState.READY w1 = Worker("w1") w2 = Worker("w2") w1.workamount_skill_mean_map = {"task": 1.0} task.allocated_worker_list = [w1, w2] w1.assigned_task_list = [task] w2.assigned_task_list = [task] c = Component("a") c.append_targeted_task(task) task.perform(10) assert task.remaining_work_amount == task.default_work_amount assert task.target_component == c assert c.error == 0.0 task.state = BaseTaskState.WORKING task.perform(10) assert task.remaining_work_amount == task.default_work_amount - 1.0 assert task.target_component == c assert c.error == 0.0 # Next test case w1.workamount_skill_sd_map = {"task": 0.2} w1.quality_skill_mean_map = {"task": 0.9} w1.quality_skill_sd_map = {"task": 0.02} task.perform(11, seed=1234, increase_component_error=2.0) assert task.remaining_work_amount == 7.905712967253502 assert c.error == 2.0
def test_has_workamount_skill(): w = Worker("w1", "----") # w.set_workamount_skill_mean_map( # {"task1": 1.0, "task2": 0.0}, update_other_skill_info=True # ) w.workamount_skill_mean_map = {"task1": 1.0, "task2": 0.0} assert w.has_workamount_skill("task1") assert not w.has_workamount_skill("task2") assert not w.has_workamount_skill("task3")
def test_perform(): task = Task("task") task.state = BaseTaskState.WORKING w1 = Worker("w1") w2 = Worker("w2") w1.workamount_skill_mean_map = {"task": 1.0} task.allocated_worker_list = [w1, w2] w1.assigned_task_list = [task] w2.assigned_task_list = [task] c = Component("a") c.append_targeted_task(task) w = Workflow([task]) w.perform(10) assert task.remaining_work_amount == task.default_work_amount - 1.0 assert task.target_component == c assert c.error == 0.0
def test_get_work_amount_skill_progress(): """test_get_work_amount_skill_progress.""" w = Worker("w1", "----") # w.set_workamount_skill_mean_map( # {"task1": 1.0, "task2": 0.0}, update_other_skill_info=True # ) w.workamount_skill_mean_map = {"task1": 1.0, "task2": 0.0} assert w.get_work_amount_skill_progress("task3") == 0.0 assert w.get_work_amount_skill_progress("task2") == 0.0 with pytest.raises(ZeroDivisionError): assert w.get_work_amount_skill_progress("task1") == 1.0 task1 = Task("task1") task1.state = BaseTaskState.NONE w.assigned_task_list = [task1] with pytest.raises(ZeroDivisionError): assert w.get_work_amount_skill_progress("task1") == 1.0 task1.state = BaseTaskState.READY with pytest.raises(ZeroDivisionError): assert w.get_work_amount_skill_progress("task1") == 1.0 task1.state = BaseTaskState.WORKING_ADDITIONALLY assert w.get_work_amount_skill_progress("task1") == 1.0 task1.state = BaseTaskState.FINISHED with pytest.raises(ZeroDivisionError): assert w.get_work_amount_skill_progress("task1") == 1.0 task1.state = BaseTaskState.WORKING assert w.get_work_amount_skill_progress("task1") == 1.0 w.workamount_skill_sd_map["task1"] = 0.1 w.get_work_amount_skill_progress("task1", seed=1234) # seed test task2 = Task("task2") task2.state = BaseTaskState.NONE w.assigned_task_list.append(task2) w.workamount_skill_sd_map["task1"] = 0.0 assert w.get_work_amount_skill_progress("task1") == 1.0 task2.state = BaseTaskState.WORKING assert w.get_work_amount_skill_progress("task1") == 0.5
def dummy_project(scope="function"): """dummy_project.""" # Components in Product c3 = Component("c3") c1 = Component("c1") c2 = Component("c2") c3.extend_child_component_list([c1, c2]) # Tasks in Workflow task1_1 = Task("task1_1", need_facility=True) task1_2 = Task("task1_2") task2_1 = Task("task2_1") task3 = Task("task3") task3.extend_input_task_list([task1_2, task2_1]) task1_2.append_input_task(task1_1) c1.extend_targeted_task_list([task1_1, task1_2]) c2.append_targeted_task(task2_1) c3.append_targeted_task(task3) # Facilities in workplace f1 = BaseFacility("f1") f1.workamount_skill_mean_map = { task1_1.name: 1.0, } # workplace.facility_list.append(f1) # Workplace in BaseOrganization workplace = BaseWorkplace("workplace", facility_list=[f1]) workplace.extend_targeted_task_list([task1_1, task1_2, task2_1, task3]) # Teams in Organization team = Team("team") team.extend_targeted_task_list([task1_1, task1_2, task2_1, task3]) # Workers in each Team w1 = Worker("w1", team_id=team.ID, cost_per_time=10.0) w1.workamount_skill_mean_map = { task1_1.name: 1.0, task1_2.name: 1.0, task2_1.name: 0.0, task3.name: 1.0, } w1.facility_skill_map = {f1.name: 1.0} team.worker_list.append(w1) w2 = Worker("w2", team_id=team.ID, cost_per_time=6.0) w2.workamount_skill_mean_map = { task1_1.name: 1.0, task1_2.name: 0.0, task2_1.name: 1.0, task3.name: 1.0, } w2.facility_skill_map = {f1.name: 1.0} team.worker_list.append(w2) # Project including Product, Workflow and Organization project = Project( init_datetime=datetime.datetime(2020, 4, 1, 8, 0, 0), unit_timedelta=datetime.timedelta(days=1), ) project.product = Product([c3, c1, c2]) project.workflow = Workflow([task1_1, task1_2, task2_1, task3]) project.organization = Organization(team_list=[team], workplace_list=[workplace]) return project