Example #1
0
 def test_components_count_7(self):
     """
     [0, 1, 2, 8, 8, 5, 5, 7, 8, 9]
     """
     uf = QuickFindUF(10)
     union_seq = [(4, 3), (3, 8), (6, 5)]
     for p, q in union_seq:
         uf.union(p, q)
     self.assertEqual(uf.components_count, 7)
Example #2
0
 def test_components_count_also_5(self):
     """
     [0, 1, 1, 8, 8, 5, 5, 7, 8, 8]
     """
     uf = QuickFindUF(10)
     union_seq = [(4, 3), (3, 8), (6, 5), (9, 4), (2, 1), (8, 9)]
     for p, q in union_seq:
         uf.union(p, q)
     self.assertEqual(uf.components_count, 5)
Example #3
0
 def test_components_count_2(self):
     """
     [1, 1, 1, 8, 8, 1, 1, 1, 8, 8]
     """
     uf = QuickFindUF(10)
     union_seq = [(4, 3), (3, 8), (6, 5), (9, 4), (2, 1), (8, 9), (5, 0),
                  (7, 2), (6, 1), (1, 0), (6, 7)]
     for p, q in union_seq:
         uf.union(p, q)
     self.assertEqual(uf.components_count, 2)
Example #4
0
 def test_union(self):
     uf = QuickFindUF(10)
     union_seq = [(4, 3), (3, 8), (6, 5), (9, 4), (2, 1), (8, 9), (5, 0),
                  (7, 2), (6, 1), (1, 0), (6, 7)]
     expected_ids = [
         [0, 1, 2, 3, 3, 5, 6, 7, 8, 9],
         [0, 1, 2, 8, 8, 5, 6, 7, 8, 9],
         [0, 1, 2, 8, 8, 5, 5, 7, 8, 9],
         [0, 1, 2, 8, 8, 5, 5, 7, 8, 8],
         [0, 1, 1, 8, 8, 5, 5, 7, 8, 8],
         [0, 1, 1, 8, 8, 5, 5, 7, 8, 8],
         [0, 1, 1, 8, 8, 0, 0, 7, 8, 8],
         [0, 1, 1, 8, 8, 0, 0, 1, 8, 8],
         [1, 1, 1, 8, 8, 1, 1, 1, 8, 8],
         [1, 1, 1, 8, 8, 1, 1, 1, 8, 8],
         [1, 1, 1, 8, 8, 1, 1, 1, 8, 8],
     ]
     for (p, q), expected in zip(union_seq, expected_ids):
         uf.union(p, q)
         self.assertEqual(uf.id, expected)