def test_check_stability(): """ Test that StableMarriage can recognise whether a matching is stable. """ from matching import Player suitors = [Player("A"), Player("B")] reviewers = [Player("X"), Player("Y")] (a, b), (x, y) = suitors, reviewers a.set_prefs(reviewers) b.set_prefs(reviewers[::-1]) x.set_prefs(suitors) y.set_prefs(suitors[::-1]) game = StableMarriage(suitors, reviewers) matching = game.solve() assert game.check_stability() (a, b), (x, y) = game.suitors, game.reviewers matching[a] = y matching[b] = x assert not game.check_stability()
def test_check_stability(): """ Test that StableMarriage can recognise whether a matching is stable. """ from matching import Player suitors = [Player("A"), Player("B")] reviewers = [Player(1), Player(2)] suitors[0].set_prefs(reviewers) suitors[1].set_prefs(reviewers[::-1]) reviewers[0].set_prefs(suitors) reviewers[1].set_prefs(suitors[::-1]) game = StableMarriage(suitors, reviewers) matching = game.solve() assert game.check_stability() (s_a, s_b), (r_1, r_2) = game.suitors, game.reviewers matching[s_a] = r_2 matching[s_b] = r_1 assert not game.check_stability()