Пример #1
0
def test_check_removing_placed_workplace():
    """test_check_removing_placed_workplace."""
    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 = BaseWorkplace("f1")
    f2 = BaseWorkplace("f2")
    c1.placed_workplace = f1
    c2.placed_workplace = f2
    f1.set_placed_component(c1)
    f2.set_placed_component(c2)

    # case1
    task1.state = BaseTaskState.WORKING
    task2.state = BaseTaskState.FINISHED
    product.check_removing_placed_workplace()
    assert c1.placed_workplace.name == "f1"
    assert c2.placed_workplace is None

    # case2
    task1.state = BaseTaskState.FINISHED
    task2.state = BaseTaskState.FINISHED
    c1.append_child_component(c2)
    c1.placed_workplace = f1
    c2.placed_workplace = f1
    f1.placed_component_list = [c1, c2]
    product.check_removing_placed_workplace()
    assert c1.placed_workplace is None
    assert c2.placed_workplace is None
Пример #2
0
def test_get_available_space_size():
    """test_get_available_space_size."""
    max_space_size = 5.0
    workplace = BaseWorkplace("f", max_space_size=max_space_size)
    assert workplace.get_available_space_size() == max_space_size
    c1_space_size = 3.0
    workplace.set_placed_component(BaseComponent("c1", space_size=c1_space_size))
    assert workplace.get_available_space_size() == max_space_size - c1_space_size
Пример #3
0
def test_remove_placed_component():
    """test_remove_placed_component."""
    c = BaseComponent("c")
    c1 = BaseComponent("c1")
    c2 = BaseComponent("c2")
    c.append_child_component(c1)
    c1.append_child_component(c2)
    workplace = BaseWorkplace("workplace")
    workplace.set_placed_component(c)
    assert workplace.placed_component_list == [c, c1, c2]
    workplace.remove_placed_component(c)
    assert workplace.placed_component_list == []
Пример #4
0
def test_can_put():
    """test_can_put."""
    c1 = BaseComponent("c1", space_size=2.0)
    c2 = BaseComponent("c2", space_size=2.0)
    workplace = BaseWorkplace("f", max_space_size=1.0)
    assert workplace.can_put(c1) is False
    assert workplace.can_put(c2) is False
    workplace.max_space_size = 3.0
    assert workplace.can_put(c1) is True
    assert workplace.can_put(c2) is True
    workplace.set_placed_component(c1)
    assert workplace.can_put(c2) is False
    workplace.max_space_size = 4.0
    assert workplace.can_put(c2) is True