def test_get_scaled_reward():
    """
    .
    """
    mission = Mission("test", "faction", 125, "b", 6)
    assert mission.get_scaled_reward(
        0.5) == 62.5, "Expected mission reward returned"
def test_update_mission_list(monkeypatch):
    """
    .
    """
    @utils.counter_wrapper
    def update_missions(yaml):
        """
        .
        """
        assert (yaml == mission_two.yaml() +
                mission_four.yaml()), "YAML for update is correct"

    mission_one = Mission("name", "faction", 1.2, "e", 4)
    mission_two = Mission("name2", "faction", 1.3, "b", 4)
    mission_three = Mission("name", "faction2", 1.4, "e", 4)
    mission_four = Mission("name2", "faction2", 1.5, "l", 4)

    monkeypatch.setattr(utils, "update_mission_file", update_missions)
    optimize_passengers.update_mission_list(
        [
            mission_one,
            mission_two,
            mission_three,
            mission_four,
        ],
        [
            mission_one,
            mission_three,
        ],
    )
    assert update_missions.counter == 1, "Missions would have been updated"
def test_yaml():
    """
    .
    """
    mission = Mission("test", "faction", 125, "b", 6)
    assert mission.yaml() == "\n".join([
        "-",
        "  name: test",
        "  faction: faction",
        "  reward: 125",
        "  min-quality: b",
        "  passengers: 6",
        "\n",
    ]), "YAML for mission correct"
def test_name():
    """
    .
    """
    mission = Mission("test", "faction", 125, "b", 6)
    assert str(
        mission) == "faction - test", "String version of mission is correct"
def test_duplicate_missions(capsys):
    """
    .
    """
    mission_one = Mission("name", "faction", 1.2, "e", 4)
    mission_two = Mission("name2", "faction", 1.3, "b", 4)
    mission_three = Mission("name", "faction2", 1.4, "e", 4)
    mission_four = Mission("name2", "faction2", 1.5, "l", 4)

    assert not optimize_passengers.has_duplicate_missions([
        mission_one,
        mission_two,
        mission_three,
        mission_four,
    ]), "No duplicates"

    printed = capsys.readouterr()
    assert printed.out == "", "Nothing printed"

    assert optimize_passengers.has_duplicate_missions(
        [mission_one, mission_two, mission_three, mission_four,
         mission_two]), "Has single duplicate"

    printed = capsys.readouterr()
    assert printed.out == (
        "At least two missions share a faction and name!\n"
        " - faction - name2\n"), "Single collision printed correctly"

    assert optimize_passengers.has_duplicate_missions([
        mission_one,
        mission_two,
        mission_three,
        mission_four,
        mission_two,
        mission_three,
    ]), "Has multiple duplicate"

    printed = capsys.readouterr()
    assert printed.out == (
        "At least two missions share a faction and name!\n"
        " - faction - name2\n"
        " - faction2 - name\n"), "Multiple collision printed correctly"
def test_assign_missions():
    """
    .
    """
    mission_one = Mission("name1", "faction1", 1.23, "e", 3)
    cabin_one = Cabin(3, "b")

    mission_two = Mission("name2", "faction1", 0.4, "b", 3)
    cabin_two = Cabin(5, "f")

    mission_three = Mission("name1", "faction2", 3, "e", 4)
    cabin_three = Cabin(5, "e")

    results = optimize_passengers.assign_missions_to_cabins(
        [mission_one, mission_two, mission_three],
        [cabin_three, cabin_two, cabin_one])

    assert results == {
        mission_one: cabin_two,
        mission_two: cabin_one,
        mission_three: cabin_three,
    }, "Expected assignment returned"
def test_print_result(capsys):
    """
    .
    """
    mission_one = Mission("name1", "faction1", 1.23, "e", 3)
    cabin_one = Cabin(3, "b")

    mission_two = Mission("name2", "faction1", 0.4, "b", 3)
    cabin_two = Cabin(5, "f")

    mission_three = Mission("name1", "faction2", 3, "e", 4)
    cabin_three = Cabin(5, "e")

    optimize_passengers.print_results({
        mission_one: cabin_one,
        mission_two: cabin_two,
        mission_three: cabin_three,
    })
    printed = capsys.readouterr()
    expected_table_lines = [
        "Faction    Name    Cabin Class   Cabin Quality   Algorithm Score   Reward",
        "=========================================================================",
        "faction1   name1   3             b               0.500             1.230 ",
        "faction1   name2   5             f               0.250             0.400 ",
        "faction2   name1   5             e               0.250             3.000 ",
        "",
    ]
    actual_table_lines = printed.out.split("\n")

    line = 0
    for expected, actual in zip(expected_table_lines, actual_table_lines):
        assert actual == expected, f"Table line {line} correct"
        line += 1

    assert len(expected_table_lines) == len(
        actual_table_lines), "Same number of lines in tables"
Exemple #8
0
def load_missions() -> List[Mission]:
    """
    Load missions from yaml file
    """
    missions = []
    mission_data = utils.get_mission_data()
    for mission in mission_data:
        missions.append(
            Mission(
                mission["name"],
                mission["faction"],
                mission["reward"],
                mission["min-quality"],
                mission["passengers"],
            ))

    return missions
Exemple #9
0
def prompt(faction: str = None) -> str:
    """
    Prompt user for inputs
    """
    name = input("Name: ")
    if not name:
        return None
    if not faction:
        faction = input("Faction: ")

    reward = input("Reward: ")
    cabin = input("Cabin class: ")
    passengers = input("Passenger count: ")

    write_mission_file(Mission(name, faction, reward, cabin, passengers))

    return faction
Exemple #10
0
def write_mission_file(mission: Mission):
    """
    Actually record results in the mission file
    """
    with open("missions.yaml", "a") as mission_file:
        mission_file.write(mission.yaml())