Exemple #1
0
def test_set_prefs(name, pref_names):
    """ Verify a Player can set its preferences correctly. """

    player = Player(name)
    others = [Player(other) for other in pref_names]

    player.set_prefs(others)
    assert player.prefs == others
    assert player._original_prefs == others
Exemple #2
0
def test_get_favourite(name, pref_names):
    """ Check the correct player is returned as the favourite of a player. """

    player = Player(name)
    others = [Player(other) for other in pref_names]

    player.set_prefs(others)
    favourite = others[0]
    assert player.get_favourite() == favourite
Exemple #3
0
def test_prefers(name, pref_names):
    """Test that a comparison of preference between two other players can be
    found for a player."""

    player = Player(name)
    others = [Player(other) for other in pref_names]

    player.set_prefs(others)
    for i, other in enumerate(others[:-1]):
        assert player.prefers(other, others[i + 1])
Exemple #4
0
def test_match_pair(name, pref_names):
    """ Verify that two players can be matched to one another. """

    others = [Player(other) for other in pref_names]

    for other in others:
        player = Player(name)
        other.set_prefs([player])
        player.set_prefs(others)

        _match_pair(player, other)
        assert player.matching == other
        assert other.matching == player
Exemple #5
0
def test_delete_pair(name, pref_names):
    """ Verify that two players can forget each other. """

    others = [Player(other) for other in pref_names]

    for other in others:
        player = Player(name)
        other.set_prefs([player])
        player.set_prefs(others)

        _delete_pair(player, other)
        assert player.prefs == [o for o in others if o != other]
        assert other.prefs == []
Exemple #6
0
def test_get_successors(name, pref_names):
    """Test that the correct successors to another player in a player's
    preference list are found."""

    player = Player(name)
    others = [Player(other) for other in pref_names]

    player.set_prefs(others)
    player.matching = others[0]
    if len(player._original_prefs) > 1:
        successors = others[1:]
        assert player.get_successors() == successors
    else:
        assert player.get_successors() == []
Exemple #7
0
def test_forget(name, pref_names):
    """ Test that a player can forget somebody. """

    player = Player(name)
    others = [Player(other) for other in pref_names]

    player.set_prefs(others)
    for i, other in enumerate(others[:-1]):
        player.forget(other)
        assert player.prefs == others[i + 1:]

    player.forget(others[-1])
    assert player.prefs == []
    assert player._original_prefs == others
Exemple #8
0
def _make_players(player_prefs):
    """Make a set of ``Player`` instances from the dictionary given. Add their
    preferences."""

    player_dict = {}
    for player_name in player_prefs:
        player = Player(name=player_name)
        player_dict[player_name] = player

    for player_name, player in player_dict.items():
        prefs = [player_dict[name] for name in player_prefs[player_name]]
        player.set_prefs(prefs)

    players = list(player_dict.values())

    return players
Exemple #9
0
def test_check_if_match_unacceptable(name, pref_names):
    """ Test that the acceptability of a match is caught correctly. """

    player = Player(name)
    others = [Player(other) for other in pref_names]

    message = player.unmatched_message()
    assert player.check_if_match_is_unacceptable() == message

    player.set_prefs(others[:-1])
    player.match(others[-1])
    message = player.not_in_preferences_message(others[-1])
    assert player.check_if_match_is_unacceptable() == message

    player.set_prefs(others)
    assert player.check_if_match_is_unacceptable() is None
Exemple #10
0
def test_check_inputs_player_prefs_unique(name, other_names, clean):
    """ Test that a game can verify its players have unique preferences. """

    player = Player(name)
    others = [Player(other) for other in other_names]
    player.set_prefs(others + others[:1])

    game = DummyGame(clean)
    game.players = [player]

    with warnings.catch_warnings(record=True) as w:
        game._check_inputs_player_prefs_unique("players")

        message = w[-1].message
        assert isinstance(message, PreferencesChangedWarning)
        assert str(message).startswith(name)
        assert others[0].name in str(message)
        if clean:
            assert player.pref_names == other_names
def test_set_prefs(name, capacity, pref_names):
    """Test that a Supervisor can set its preferences correctly, and the
    preferences of its project(s)."""

    supervisor = Supervisor(name, capacity)
    projects = [Project(i, capacity) for i in range(3)]
    students = []
    for sname in pref_names:
        student = Student(sname)
        student.set_prefs(projects)
        students.append(student)

    supervisor.projects = projects
    supervisor.set_prefs(students)
    assert supervisor.prefs == students
    assert supervisor._pref_names == pref_names
    assert supervisor._original_prefs == students

    for project in supervisor.projects:
        assert project.prefs == students
        assert project._pref_names == pref_names
        assert project._original_prefs == students