def test_check_removing_placed_factory(): c1 = BaseComponent("c1") task1 = BaseTask("task1") c1.append_targeted_task(task1) c2 = BaseComponent("c2") task2 = BaseTask("task2") c2.append_targeted_task(task2) product = BaseProduct([c1, c2]) f1 = BaseFactory("f1") f2 = BaseFactory("f2") c1.placed_factory = f1 c2.placed_factory = f2 f1.set_placed_component(c1) f2.set_placed_component(c2) # case1 task1.state = BaseTaskState.WORKING task2.state = BaseTaskState.FINISHED product.check_removing_placed_factory() assert c1.placed_factory.name == "f1" assert c2.placed_factory is None # case2 task1.state = BaseTaskState.FINISHED task2.state = BaseTaskState.FINISHED c1.append_child_component(c2) c2.placed_factory = BaseFactory("f2") product.check_removing_placed_factory() assert c1.placed_factory is None assert c2.placed_factory is None
def test_remove_placed_component(): c = BaseComponent("c") factory = BaseFactory("factory") factory.set_placed_component(c) assert factory.placed_component_list == [c] factory.remove_placed_component(c) assert factory.placed_component_list == []
def test_can_put(): c1 = BaseComponent("c1", space_size=2.0) c2 = BaseComponent("c2", space_size=2.0) factory = BaseFactory("f", max_space_size=1.0) assert factory.can_put(c1) is False assert factory.can_put(c2) is False factory.max_space_size = 3.0 assert factory.can_put(c1) is True assert factory.can_put(c2) is True factory.set_placed_component(c1) assert factory.can_put(c2) is False factory.max_space_size = 4.0 assert factory.can_put(c2) is True