Beispiel #1
0
def test_get_worst_match(name, capacity, pref_names):
    """ Check that a hospital can return its worst match. """

    hospital = Hospital(name, capacity)
    others = [Resident(other) for other in pref_names]

    hospital.matching = [others[0]]
    assert hospital.get_worst_match() == others[0]

    hospital.matching = others
    assert hospital.get_worst_match() == others[-1]
Beispiel #2
0
def test_get_successors(name, capacity, pref_names):
    """Check that a hospital can get the successors to its worst current match."""

    hospital = Hospital(name, capacity)
    others = [Resident(other) for other in pref_names]

    hospital.set_prefs(others)
    hospital.matching = [others[0]]
    assert hospital.get_successors() == others[1:]

    hospital.matching = others
    assert hospital.get_successors() == []
Beispiel #3
0
def test_get_favourite(name, capacity, pref_names):
    """ Check the correct player is returned as the hospital's favourite. """

    hospital = Hospital(name, capacity)
    others = [Resident(other) for other in pref_names]

    hospital.set_prefs(others)
    assert hospital.get_favourite() == others[0]

    hospital.matching = others
    assert hospital.get_favourite() is None
Beispiel #4
0
def test_check_if_oversubscribed(name, capacity, pref_names):
    """ Check that a hospital can verify whether it is oversubscribed. """

    hospital = Hospital(name, capacity)
    others = [Resident(other) for other in pref_names]

    assert hospital.check_if_oversubscribed() is False

    hospital.matching = others
    hospital.capacity = 0
    message = hospital.oversubscribed_message()
    assert hospital.check_if_oversubscribed() == message
Beispiel #5
0
def test_check_if_match_is_unacceptable(name, capacity, pref_names):
    """ Check that a hospital can verify the acceptability of its matches. """

    hospital = Hospital(name, capacity)
    others = [Resident(other) for other in pref_names]

    assert hospital.check_if_match_is_unacceptable() == []

    hospital.set_prefs(others[:-1])
    hospital.matching = [others[-1]]
    message = hospital.not_in_preferences_message(others[-1])
    assert hospital.check_if_match_is_unacceptable() == [message]
Beispiel #6
0
def test_unmatch(name, capacity, pref_names):
    """ Check that a hospital can unmatch from a player correctly. """

    hospital = Hospital(name, capacity)
    others = [Resident(other) for other in pref_names]

    hospital.matching = others
    for i, other in enumerate(others[:-1]):
        hospital.unmatch(other)
        assert hospital.matching == others[i + 1:]

    hospital.unmatch(others[-1])
    assert hospital.matching == []