Example #1
0
def test_requirement_as_set_3():
    req = RequirementOr([
        Requirement.impossible(),
        _req("A"),
    ])
    assert req.as_set(None) == RequirementSet([
        RequirementList([_req("A")]),
    ])
Example #2
0
def test_requirement_as_set_1():
    req = RequirementAnd([
        _req("A"),
        RequirementOr([_req("B"), _req("C")]),
        RequirementOr([_req("D"), _req("E")]),
    ])
    assert req.as_set(None) == RequirementSet([
        RequirementList([_req("A"), _req("B"), _req("D")]),
        RequirementList([_req("A"), _req("B"), _req("E")]),
        RequirementList([_req("A"), _req("C"), _req("D")]),
        RequirementList([_req("A"), _req("C"), _req("E")]),
    ])
Example #3
0
def test_requirement_or_str():
    req = RequirementOr([
        _req("C"),
        _req("A"),
        _req("B"),
    ])
    assert str(req) == "(A ≥ 1 or B ≥ 1 or C ≥ 1)"
Example #4
0
def test_simplify_requirement_set_static():
    res_a, id_req_a = make_req_a()
    res_b, id_req_b = make_req_b()

    the_set = RequirementOr([
        RequirementAnd([id_req_a]),
        RequirementAnd([id_req_b]),
    ])

    simple_1 = the_set.patch_requirements({res_a: 0, res_b: 0}, 1)
    simple_2 = the_set.patch_requirements({res_a: 0, res_b: 1}, 1)
    simple_3 = the_set.patch_requirements({res_a: 1, res_b: 1}, 1)

    assert simple_1.as_set.alternatives == frozenset()
    assert simple_2.as_set.alternatives == frozenset([RequirementList([])])
    assert simple_3.as_set.alternatives == frozenset([RequirementList([])])
Example #5
0
def test_requirement_as_set_4():
    req = RequirementOr([
        Requirement.impossible(),
        _req("A"),
        Requirement.trivial(),
    ])
    assert req.as_set == RequirementSet([
        RequirementList([]),
    ])
Example #6
0
def test_requirement_template_nested(database):
    # Setup
    use_a = RequirementTemplate(database, "Use A")
    use_b = RequirementTemplate(database, "Use B")

    database.requirement_template["Use A"] = _req("A")
    database.requirement_template["Use B"] = RequirementOr([use_a, _req("B")])

    # Run
    as_set = use_b.as_set

    # Assert
    assert as_set == RequirementSet([
        RequirementList([_req("A")]),
        RequirementList([_req("B")]),
    ])
Example #7
0
def test_build_no_changes(skip_qtbot, echoes_resource_database):
    # Setup
    def mk_req(name: str):
        return ResourceRequirement.with_data(echoes_resource_database,
                                             ResourceType.ITEM, name, 1, False)

    requirement = RequirementOr([
        RequirementAnd([
            mk_req("Dark"),
            mk_req("Light"),
        ]),
        mk_req("Power"),
    ])

    # Run
    editor = connections_editor.ConnectionsEditor(None,
                                                  echoes_resource_database,
                                                  requirement)
    skip_qtbot.addWidget(editor)
    result = editor.final_requirement

    # Assert
    assert result == requirement
Example #8
0
def test_build_no_changes(skip_qtbot, echoes_resource_database):
    # Setup
    def mk_req(index: int):
        return ResourceRequirement.with_data(echoes_resource_database,
                                             ResourceType.ITEM, index, 1,
                                             False)

    requirement = RequirementOr([
        RequirementAnd([
            mk_req(1),
            mk_req(2),
        ]),
        mk_req(0),
    ])

    # Run
    editor = connections_editor.ConnectionsEditor(None,
                                                  echoes_resource_database,
                                                  requirement)
    skip_qtbot.addWidget(editor)
    result = editor.final_requirement

    # Assert
    assert result == requirement
Example #9
0
def read_requirement_or(data: Dict,
                        resource_database: ResourceDatabase) -> RequirementOr:
    return RequirementOr(
        [read_requirement(item, resource_database) for item in data["data"]])
Example #10
0

def test_trivial_requirement_damage():
    assert Requirement.trivial().damage({}, None) == 0


def test_trivial_requirement_str():
    assert str(Requirement.trivial()) == "Trivial"


@pytest.mark.parametrize(
    ["original", "expected"],
    [(
        RequirementOr([
            RequirementAnd([
                _req("A"),
            ]),
        ]),
        _req("A"),
    ), (
        RequirementAnd([
            RequirementOr([
                _req("A"),
            ]),
        ]),
        _req("A"),
    ),
     (
         RequirementAnd([
             RequirementOr([_req("B"), Requirement.trivial()]),
             RequirementAnd([