Esempio n. 1
0
    def test_stability_random(self) -> None:
        num_trial = 100
        max_pair = 50
        for _ in range(0, num_trial):
            a_list = []
            b_list = []
            count = random.randrange(10, max_pair)
            # create candidates in two lists
            for i in range(count):
                a_list.append(Person("a_" + str(i)))
                b_list.append(Person("b_" + str(i)))
            # randomly set prefernces for each candidate
            for a in a_list:
                pref = b_list[:]
                random.shuffle(pref)
                a.set_preferences(pref)
            for b in b_list:
                pref = a_list[:]
                random.shuffle(pref)
                b.set_preferences(pref)

            pairs = generate_stable_pairs(a_list, b_list)
            assert len(pairs) == count
            assert len(set([a for a, b in pairs])) == count
            assert len(set([b for a, b in pairs])) == count
            if not check_stability(pairs):
                dump_dict = {}
                for a in a_list:
                    dump_dict[str(a)] = a.get_preferences()
                for b in b_list:
                    dump_dict[str(b)] = b.get_preferences()
                dump_dict['pairs'] = pairs
                print(dump_dict)
            assert check_stability(pairs)
Esempio n. 2
0
    def test_stable_result_for_two(self) -> None:
        left = [self.nIsTwo['Simon'], self.nIsTwo['Peter']]
        right = [self.nIsTwo['Jane'], self.nIsTwo['Mary']]
        pairs: Sequence[Pair] = generate_stable_pairs(left, right)

        assert len(pairs) == 2
        assert (self.nIsTwo['Simon'], self.nIsTwo['Jane']) in pairs
        assert (self.nIsTwo['Peter'], self.nIsTwo['Mary']) in pairs
        assert check_stability(pairs)
Esempio n. 3
0
 def test_same_seed(self) -> None:
     seed = 42
     prev_result = None
     for _ in range(0, 100):
         pairs = generate_stable_pairs(self.a_list, self.b_list, seed)
         if prev_result:
             assert prev_result == pairs
         prev_result = pairs
         assert len(pairs) == self.count
         assert len(set([a for a, b in pairs])) == self.count
         assert len(set([b for a, b in pairs])) == self.count
         assert check_stability(pairs)
Esempio n. 4
0
 def test_stability_empty(self) -> None:
     assert check_stability([])
     assert check_stability(generate_stable_pairs([], []))
Esempio n. 5
0
 def test_empty(self) -> None:
     assert len(generate_stable_pairs([], [])) == 0