def test_remove_insert_absence_time_list(): """test_remove_insert_absence_time_list.""" f1 = BaseFacility("w1", "----") f1.cost_list = [1.0, 0.0, 1.0, 0.0, 0.0, 1.0] f1.assigned_task_id_record = ["aa", "bb", "cc", "dd", "ee", "ff"] f1.state_record_list = [2, 1, 2, 1, 1, 2] f2 = BaseFacility("w1", "----") f2.cost_list = [1.0, 0.0, 1.0, 0.0, 0.0, 1.0] f2.assigned_task_id_record = ["aa", "bb", "cc", "dd", "ee", "ff"] f2.state_record_list = [2, 1, 2, 1, 1, 2] workplace = BaseWorkplace("aa", facility_list=[f1, f2]) workplace.cost_list = [2.0, 0.0, 2.0, 0.0, 0.0, 2.0] absence_time_list = [1, 3, 4] workplace.remove_absence_time_list(absence_time_list) assert workplace.cost_list == [2.0, 2.0, 2.0] assert f1.cost_list == [1.0, 1.0, 1.0] assert f1.assigned_task_id_record == ["aa", "cc", "ff"] assert f1.state_record_list == [2, 2, 2] assert f2.cost_list == [1.0, 1.0, 1.0] assert f2.assigned_task_id_record == ["aa", "cc", "ff"] assert f2.state_record_list == [2, 2, 2] workplace.insert_absence_time_list(absence_time_list) assert workplace.cost_list == [2.0, 0.0, 2.0, 0.0, 0.0, 2.0] assert f1.cost_list == [1.0, 0.0, 1.0, 0.0, 0.0, 1.0] assert f1.assigned_task_id_record == ["aa", "aa", "cc", "cc", "cc", "ff"] assert f1.state_record_list == [2, 0, 2, 0, 0, 2] assert f2.cost_list == [1.0, 0.0, 1.0, 0.0, 0.0, 1.0] assert f2.assigned_task_id_record == ["aa", "aa", "cc", "cc", "cc", "ff"] assert f2.state_record_list == [2, 0, 2, 0, 0, 2]
def test_create_data_for_gantt_plotly(): """test_create_data_for_gantt_plotly.""" workplace = BaseWorkplace("workplace") w1 = BaseFacility("w1", cost_per_time=10.0) w1.state_record_list = [ BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.FREE, ] w2 = BaseFacility("w2", cost_per_time=5.0) w2.state_record_list = [ BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.FREE, ] workplace.facility_list = [w1, w2] init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0) timedelta = datetime.timedelta(days=1) workplace.create_data_for_gantt_plotly(init_datetime, timedelta)
def test_get_facility_list(): """test_get_facility_list.""" # TODO if we have enough time for setting test case... workplace = BaseWorkplace("workplace") w1 = BaseFacility("w1", cost_per_time=10.0) w2 = BaseFacility("w2", cost_per_time=5.0) workplace.facility_list = [w2, w1] assert ( len( workplace.get_facility_list( name="test", ID="test", workplace_id="test", cost_per_time=99876, solo_working=True, workamount_skill_mean_map={}, workamount_skill_sd_map=[], state=BaseFacilityState.WORKING, cost_list=[], assigned_task_list=[], assigned_task_id_record=[], ) ) == 0 )
def test_create_data_for_cost_history_plotly(): factory = BaseFactory("factory") w1 = BaseFacility("w1", cost_per_time=10.0) w1.cost_list = [0, 0, 10, 10, 0, 10] w2 = BaseFacility("w2", cost_per_time=5.0) w2.cost_list = [5, 5, 0, 0, 5, 5] factory.facility_list = [w1, w2] factory.cost_list = list(map(sum, zip(w1.cost_list, w2.cost_list))) init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0) timedelta = datetime.timedelta(days=1) data = factory.create_data_for_cost_history_plotly(init_datetime, timedelta) x = [(init_datetime + time * timedelta).strftime("%Y-%m-%d %H:%M:%S") for time in range(len(factory.cost_list))] # w1 assert data[0].name == w1.name assert data[0].x == tuple(x) assert data[0].y == tuple(w1.cost_list) # w2 assert data[1].name == w2.name assert data[1].x == tuple(x) assert data[1].y == tuple(w2.cost_list)
def test_create_gantt_plotly(tmpdir): """test_create_gantt_plotly.""" workplace = BaseWorkplace("workplace") w1 = BaseFacility("w1", cost_per_time=10.0) w1.state_record_list = [ BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.FREE, ] w2 = BaseFacility("w2", cost_per_time=5.0) w2.state_record_list = [ BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.FREE, ] workplace.facility_list = [w1, w2] init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0) timedelta = datetime.timedelta(days=1) workplace.create_gantt_plotly( init_datetime, timedelta, save_fig_path=os.path.join(str(tmpdir), "test.png") ) for ext in ["png", "html", "json"]: save_fig_path = os.path.join(str(tmpdir), "test." + ext) workplace.create_gantt_plotly( init_datetime, timedelta, save_fig_path=save_fig_path )
def test_add_labor_cost(): factory = BaseFactory("factory") w1 = BaseFacility("w1", cost_per_time=10.0) w2 = BaseFacility("w2", cost_per_time=5.0) factory.facility_list = [w2, w1] w1.state = BaseFacilityState.WORKING w2.state = BaseFacilityState.FREE factory.add_labor_cost() assert w1.cost_list == [10.0] assert w2.cost_list == [0.0] assert factory.cost_list == [10.0] factory.add_labor_cost(only_working=False) assert factory.cost_list == [10.0, 15.0] assert w1.cost_list == [10.0, 10.0] assert w2.cost_list == [0.0, 5.0]
def test_add_labor_cost(): """test_add_labor_cost.""" workplace = BaseWorkplace("workplace") w1 = BaseFacility("w1", cost_per_time=10.0) w2 = BaseFacility("w2", cost_per_time=5.0) workplace.facility_list = [w2, w1] w1.state = BaseFacilityState.WORKING w2.state = BaseFacilityState.FREE workplace.add_labor_cost() assert w1.cost_list == [10.0] assert w2.cost_list == [0.0] assert workplace.cost_list == [10.0] workplace.add_labor_cost(only_working=False) assert workplace.cost_list == [10.0, 15.0] assert w1.cost_list == [10.0, 10.0] assert w2.cost_list == [0.0, 5.0]
def test_add_facility(): """test_add_facility.""" workplace = BaseWorkplace("workplace") facility = BaseFacility("facility") workplace.add_facility(facility) assert len(workplace.facility_list) == 1 assert facility.workplace_id == workplace.ID
def test_init(): """test_init.""" workplace = BaseWorkplace("workplace") assert workplace.name == "workplace" assert len(workplace.ID) > 0 assert workplace.facility_list == [] assert workplace.targeted_task_list == [] assert workplace.parent_workplace is None assert workplace.max_space_size == 1.0 assert workplace.input_workplace_list == [] assert workplace.output_workplace_list == [] assert workplace.cost_list == [] workplace.cost_list.append(1) assert workplace.cost_list == [1.0] w1 = BaseFacility("w1") t1 = BaseTask("task1") workplace1 = BaseWorkplace( "workplace1", parent_workplace=workplace, targeted_task_list=[t1], facility_list=[w1], max_space_size=2.0, cost_list=[10], placed_component_list=[BaseComponent("c")], placed_component_id_record=["xxxx"], ) assert workplace1.facility_list == [w1] assert workplace1.targeted_task_list == [t1] assert workplace1.parent_workplace == workplace assert workplace1.max_space_size == 2.0 assert workplace1.cost_list == [10] assert workplace1.placed_component_list[0].name == "c" assert workplace1.placed_component_id_record == ["xxxx"]
def test_has_workamount_skill(): """test_has_workamount_skill.""" w = BaseFacility("w1", "----") 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_get_work_amount_skill_progress(): """test_get_work_amount_skill_progress.""" w = BaseFacility("w1", "----") 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 = BaseTask("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 = BaseTask("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 test_init(dummy_facility): """test_init.""" # team = Team("team") assert dummy_facility.name == "wsss" assert dummy_facility.workplace_id == "---" assert dummy_facility.cost_per_time == 0.0 assert not dummy_facility.solo_working assert dummy_facility.workamount_skill_mean_map == {} assert dummy_facility.workamount_skill_sd_map == {} # assert dummy_facility.quality_skill_mean_map == {} assert dummy_facility.state == BaseFacilityState.FREE assert dummy_facility.cost_list == [] assert dummy_facility.assigned_task_list == [] w = BaseFacility( "w1", solo_working=True, state=BaseFacilityState.WORKING, cost_list=[10, 10], state_record_list=["a"], assigned_task_list=[BaseTask("task")], assigned_task_id_record=[[], ["ss"]], ) assert w.name == "w1" assert w.workplace_id is None assert w.cost_per_time == 0.0 assert w.solo_working assert w.workamount_skill_mean_map == {} assert w.workamount_skill_sd_map == {} # assert w.quality_skill_mean_map == {} assert w.state == BaseFacilityState.WORKING assert w.cost_list == [10, 10] assert w.assigned_task_list[0].name == "task" assert w.assigned_task_id_record == [[], ["ss"]]
def test_init(): factory = BaseFactory("factory") assert factory.name == "factory" assert len(factory.ID) > 0 assert factory.facility_list == [] assert factory.targeted_task_list == [] assert factory.parent_factory is None assert factory.max_space_size == 1.0 assert factory.cost_list == [] factory.cost_list.append(1) assert factory.cost_list == [1.0] w1 = BaseFacility("w1") t1 = BaseTask("task1") factory1 = BaseFactory( "factory1", parent_factory=factory, targeted_task_list=[t1], facility_list=[w1], max_space_size=2.0, cost_list=[10], placed_component_list=[BaseComponent("c")], placed_component_id_record=["xxxx"], ) assert factory1.facility_list == [w1] assert factory1.targeted_task_list == [t1] assert factory1.parent_factory == factory assert factory1.max_space_size == 2.0 assert factory1.cost_list == [10] assert factory1.placed_component_list[0].name == "c" assert factory1.placed_component_id_record == ["xxxx"]
def dummy_organization(scope="function"): c1 = BaseTeam("c1") w11 = BaseWorker("w11", cost_per_time=10.0) w12 = BaseWorker("w12", cost_per_time=5.0) w11.start_time_list = [0, 5] w11.finish_time_list = [2, 8] w12.start_time_list = [9] w12.finish_time_list = [11] c1.worker_list = [w11, w12] c2 = BaseTeam("c2") w2 = BaseWorker("w2", cost_per_time=5.0) w2.start_time_list = [9] w2.finish_time_list = [11] c2.worker_list = [w2] c2.parent_team = c1 f = BaseFacility("f", cost_per_time=20.0) f.start_time_list = [9] f.finish_time_list = [11] factory = BaseFactory("factory", facility_list=[f]) dummy_factory = BaseFactory("dummy") factory.parent_factory = dummy_factory organization = BaseOrganization(team_list=[c1, c2], factory_list=[factory, dummy_factory]) return organization
def test_can_add_resources(): task = BaseTask("task") w1 = BaseWorker("w1", solo_working=True) w2 = BaseWorker("w2") w1.workamount_skill_mean_map = {"task": 1.0} w2.workamount_skill_mean_map = {"task": 1.0} f1 = BaseFacility("f1") f2 = BaseFacility("f2", solo_working=True) f1.workamount_skill_mean_map = {"task": 1.0} f2.workamount_skill_mean_map = {"task": 1.0} w1.facility_skill_map = {f1.name: 1.0} assert task.can_add_resources(worker=w1) is False task.state = BaseTaskState.FINISHED assert task.can_add_resources(worker=w1) is False task.state = BaseTaskState.READY assert task.can_add_resources(worker=w1) is True assert task.can_add_resources(worker=w2, facility=f2) is False assert task.can_add_resources(worker=w1, facility=f1) is True w1.solo_working = False task.allocated_worker_list = [w1] task.allocated_facility_list = [f1] assert task.can_add_resources(worker=w2, facility=f2) is False w1.solo_working = True assert task.can_add_resources(worker=w2, facility=f2) is False w1.solo_working = False f1.solo_working = True assert task.can_add_resources(worker=w2, facility=f2) is False w1.solo_working = False f1.solo_working = False w2.solo_working = False f2.solo_working = False assert task.can_add_resources(worker=w1, facility=f1) is True assert task.can_add_resources(worker=w2, facility=f2) is False f1.workamount_skill_mean_map = {} assert task.can_add_resources(worker=w1, facility=f1) is False w1.workamount_skill_mean_map = {} assert task.can_add_resources(worker=w1) is False assert task.can_add_resources() is False
def test_create_gantt_plotly(): factory = BaseFactory("factory") w1 = BaseFacility("w1", cost_per_time=10.0) w1.start_time_list = [0, 5] w1.finish_time_list = [2, 8] w2 = BaseFacility("w2", cost_per_time=5.0) w2.start_time_list = [9] w2.finish_time_list = [11] factory.facility_list = [w1, w2] init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0) timedelta = datetime.timedelta(days=1) factory.create_gantt_plotly(init_datetime, timedelta, save_fig_path="test.png") if os.path.exists("test.png"): os.remove("test.png")
def dummy_team_for_extracting(scope="function"): """dummy_team_for_extracting.""" facility1 = BaseFacility("facility1") facility1.state_record_list = [ BaseFacilityState.FREE, BaseFacilityState.FREE, BaseFacilityState.FREE, BaseFacilityState.FREE, BaseFacilityState.FREE, ] facility2 = BaseFacility("facility2") facility2.state_record_list = [ BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.WORKING, ] facility3 = BaseFacility("facility3") facility3.state_record_list = [ BaseFacilityState.FREE, BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.FREE, ] facility4 = BaseFacility("facility4") facility4.state_record_list = [ BaseFacilityState.FREE, BaseFacilityState.FREE, BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.FREE, ] facility5 = BaseFacility("facility5") facility5.state_record_list = [ BaseFacilityState.FREE, BaseFacilityState.FREE, BaseFacilityState.FREE, BaseFacilityState.FREE, BaseFacilityState.WORKING, ] return BaseWorkplace( "test", facility_list=[facility1, facility2, facility3, facility4, facility5] )
def test_has_workamount_skill(): w = BaseFacility("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_create_cost_history_plotly(): factory = BaseFactory("factory") w1 = BaseFacility("w1", cost_per_time=10.0) w1.cost_list = [0, 0, 10, 10, 0, 10] w2 = BaseFacility("w2", cost_per_time=5.0) w2.cost_list = [5, 5, 0, 0, 5, 5] factory.facility_list = [w1, w2] factory.cost_list = list(map(sum, zip(w1.cost_list, w2.cost_list))) init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0) timedelta = datetime.timedelta(days=1) factory.create_cost_history_plotly(init_datetime, timedelta) factory.create_cost_history_plotly(init_datetime, timedelta, title="bbbbbbb", save_fig_path="test.png") if os.path.exists("test.png"): os.remove("test.png")
def test_initialize(): """test_initialize.""" team = BaseWorkplace("team") w = BaseFacility("w1", workplace_id=team.ID) w.state = BaseFacilityState.WORKING w.cost_list = [9.0, 7.2] w.assigned_task_list = [BaseTask("task")] w.initialize() assert w.state == BaseFacilityState.FREE assert w.cost_list == [] assert w.assigned_task_list == []
def dummy_organization(scope="function"): """dummy_organization.""" c1 = BaseTeam("c1") w11 = BaseWorker("w11", cost_per_time=10.0) w12 = BaseWorker("w12", cost_per_time=5.0) w11.state_record_list = [ BaseWorkerState.WORKING, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.FREE, ] w12.state_record_list = [ BaseWorkerState.WORKING, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.FREE, ] c1.worker_list = [w11, w12] c2 = BaseTeam("c2") w2 = BaseWorker("w2", cost_per_time=5.0) w2.state_record_list = [ BaseWorkerState.WORKING, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.WORKING, BaseWorkerState.FREE, BaseWorkerState.FREE, ] c2.worker_list = [w2] c2.parent_team = c1 f = BaseFacility("f", cost_per_time=20.0) f.state_record_list = [ BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.FREE, ] workplace = BaseWorkplace("workplace", facility_list=[f]) dummy_workplace = BaseWorkplace("dummy") workplace.parent_workplace = dummy_workplace organization = BaseOrganization( team_list=[c1, c2], workplace_list=[workplace, dummy_workplace]) return organization
def test_create_cost_history_plotly(tmpdir): """test_create_cost_history_plotly.""" workplace = BaseWorkplace("workplace") w1 = BaseFacility("w1", cost_per_time=10.0) w1.cost_list = [0, 0, 10, 10, 0, 10] w2 = BaseFacility("w2", cost_per_time=5.0) w2.cost_list = [5, 5, 0, 0, 5, 5] workplace.facility_list = [w1, w2] workplace.cost_list = list(map(sum, zip(w1.cost_list, w2.cost_list))) init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0) timedelta = datetime.timedelta(days=1) workplace.create_cost_history_plotly(init_datetime, timedelta) for ext in ["png", "html", "json"]: save_fig_path = os.path.join(str(tmpdir), "test." + ext) workplace.create_cost_history_plotly( init_datetime, timedelta, title="bbbbbbb", save_fig_path=save_fig_path ) if os.path.exists(save_fig_path): os.remove(save_fig_path)
def test_create_data_for_gantt_plotly(): factory = BaseFactory("factory") w1 = BaseFacility("w1", cost_per_time=10.0) w1.start_time_list = [0, 5] w1.finish_time_list = [2, 8] w2 = BaseFacility("w2", cost_per_time=5.0) w2.start_time_list = [9] w2.finish_time_list = [11] factory.facility_list = [w1, w2] init_datetime = datetime.datetime(2020, 4, 1, 8, 0, 0) timedelta = datetime.timedelta(days=1) df = factory.create_data_for_gantt_plotly(init_datetime, timedelta) # w1 part1 assert df[0]["Task"] == factory.name + ": " + w1.name assert df[0]["Start"] == ( init_datetime + w1.start_time_list[0] * timedelta).strftime("%Y-%m-%d %H:%M:%S") assert df[0]["Finish"] == (init_datetime + (w1.finish_time_list[0] + 1.0) * timedelta).strftime("%Y-%m-%d %H:%M:%S") assert df[0]["Type"] == "Facility" # w1 part2 assert df[1]["Task"] == factory.name + ": " + w1.name assert df[1]["Start"] == ( init_datetime + w1.start_time_list[1] * timedelta).strftime("%Y-%m-%d %H:%M:%S") assert df[1]["Finish"] == (init_datetime + (w1.finish_time_list[1] + 1.0) * timedelta).strftime("%Y-%m-%d %H:%M:%S") assert df[1]["Type"] == "Facility" # w2 assert df[2]["Start"] == ( init_datetime + w2.start_time_list[0] * timedelta).strftime("%Y-%m-%d %H:%M:%S") assert df[2]["Finish"] == (init_datetime + (w2.finish_time_list[0] + 1.0) * timedelta).strftime("%Y-%m-%d %H:%M:%S") assert df[2]["Type"] == "Facility"
def test_initialize(): """test_initialize.""" workplace = BaseWorkplace("workplace") workplace.cost_list = [9.0, 7.2] w = BaseFacility("w1") workplace.facility_list = [w] w.state = BaseFacilityState.WORKING w.cost_list = [9.0, 7.2] w.assigned_task_list = [BaseTask("task")] workplace.initialize() assert workplace.cost_list == [] assert w.state == BaseFacilityState.FREE assert w.cost_list == [] assert w.assigned_task_list == []
def test_initialize(): team = BaseFactory("team") w = BaseFacility("w1", factory_id=team.ID) w.state = BaseFacilityState.WORKING w.cost_list = [9.0, 7.2] w.start_time_list = [0] w.finish_time_list = [1] w.assigned_task_list = [BaseTask("task")] w.initialize() assert w.state == BaseFacilityState.FREE assert w.cost_list == [] assert w.start_time_list == [] assert w.finish_time_list == [] assert w.assigned_task_list == []
def test_plot_simple_gantt(): """test_plot_simple_gantt.""" workplace = BaseWorkplace("workplace") w1 = BaseFacility("w1", cost_per_time=10.0) w1.state_record_list = [ BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.FREE, ] w2 = BaseFacility("w2", cost_per_time=5.0) w2.state_record_list = [ BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.FREE, ] workplace.facility_list = [w1, w2] workplace.plot_simple_gantt()
def test_init(): task = BaseTask("task") assert task.name == "task" assert len(task.ID) > 0 assert task.default_work_amount == 10.0 assert task.input_task_list == [] assert task.output_task_list == [] assert task.due_time == -1 assert task.allocated_team_list == [] assert task.target_component is None assert task.default_progress == 0.0 # assert task.additional_work_amount == 0.0 assert task.est == 0.0 assert task.eft == 0.0 assert task.lst == -1.0 assert task.lft == -1.0 assert task.remaining_work_amount == task.default_work_amount * ( 1.0 - task.default_progress) # assert task.actual_work_amount == task.default_work_amount * ( # 1.0 - task.default_progress # ) assert task.state == BaseTaskState.NONE assert task.ready_time_list == [] assert task.start_time_list == [] assert task.finish_time_list == [] # assert task.additional_task_flag is False assert task.allocated_worker_list == [] tb = BaseTask( "task_b1", remaining_work_amount=0.0, state=BaseTaskState.FINISHED, ready_time_list=[1], start_time_list=[2], finish_time_list=[5], allocated_worker_list=[BaseWorker("a")], allocated_worker_id_record=[["idid"]], allocated_facility_list=[BaseFacility("b")], allocated_facility_id_record=[["ibib"]], ) assert tb.remaining_work_amount == 0.0 assert tb.state == BaseTaskState.FINISHED assert tb.ready_time_list == [1] assert tb.start_time_list == [2] assert tb.finish_time_list == [5] assert tb.allocated_worker_list[0].name == "a" assert tb.allocated_worker_id_record == [["idid"]] assert tb.allocated_facility_list[0].name == "b" assert tb.allocated_facility_id_record == [["ibib"]]
def test_initialize(): factory = BaseFactory("factory") factory.cost_list = [9.0, 7.2] w = BaseFacility("w1") factory.facility_list = [w] w.state = BaseFacilityState.WORKING w.cost_list = [9.0, 7.2] w.start_time_list = [0] w.finish_time_list = [1] w.assigned_task_list = [BaseTask("task")] factory.initialize() assert factory.cost_list == [] assert w.state == BaseFacilityState.FREE assert w.cost_list == [] assert w.start_time_list == [] assert w.finish_time_list == [] assert w.assigned_task_list == []
def test_get_time_list_for_gannt_chart(): w = BaseFacility("w1", "----") w.state_record_list = [ BaseFacilityState.FREE, BaseFacilityState.FREE, BaseFacilityState.WORKING, ] ready_time_list, working_time_list = w.get_time_list_for_gannt_chart() assert ready_time_list == [(0, 2)] assert working_time_list == [(2, 1)] w.state_record_list = [ BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.FREE, ] ready_time_list, working_time_list = w.get_time_list_for_gannt_chart() assert ready_time_list == [(2, 1)] assert working_time_list == [(0, 2)] w.state_record_list = [ BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.WORKING, ] ready_time_list, working_time_list = w.get_time_list_for_gannt_chart() assert ready_time_list == [] assert working_time_list == [(0, 3)] # for backward w.state_record_list = [ BaseFacilityState.FREE, BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.WORKING, BaseFacilityState.FREE, BaseFacilityState.FREE, BaseFacilityState.FREE, BaseFacilityState.WORKING, ] ready_time_list, working_time_list = w.get_time_list_for_gannt_chart() assert ready_time_list == [(0, 1), (4, 3)] assert working_time_list == [(1, 3), (7, 1)]
def test_remove_insert_absence_time_list(): """test_remove_insert_absence_time_list.""" w = BaseFacility("w1", "----") w.cost_list = [1.0, 0.0, 1.0, 0.0, 0.0, 1.0] w.assigned_task_id_record = ["aa", "bb", "cc", "dd", "ee", "ff"] w.state_record_list = [2, 1, 2, 1, 1, 2] absence_time_list = [0, 1, 4] w.remove_absence_time_list(absence_time_list) assert w.cost_list == [1.0, 0.0, 1.0] assert w.assigned_task_id_record == ["cc", "dd", "ff"] assert w.state_record_list == [2, 1, 2] w.insert_absence_time_list(absence_time_list) assert w.cost_list == [0.0, 0.0, 1.0, 0.0, 0.0, 1.0] assert w.assigned_task_id_record == [None, None, "cc", "dd", "dd", "ff"] assert w.state_record_list == [ BaseFacilityState.FREE, BaseFacilityState.FREE, 2, 1, BaseFacilityState.FREE, 2, ]