Example #1
0
 def test_components_count_2(self):
     uf = WeightedQuickUnionPathCompressionUF(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 #2
0
 def test_union(self):
     uf = WeightedQuickUnionPathCompressionUF(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, 4, 4, 5, 6, 7, 8, 9],
         [0, 1, 2, 4, 4, 5, 6, 7, 4, 9],
         [0, 1, 2, 4, 4, 6, 6, 7, 4, 9],
         [0, 1, 2, 4, 4, 6, 6, 7, 4, 4],
         [0, 2, 2, 4, 4, 6, 6, 7, 4, 4],
         [0, 2, 2, 4, 4, 6, 6, 7, 4, 4],
         [6, 2, 2, 4, 4, 6, 6, 7, 4, 4],
         [6, 2, 2, 4, 4, 6, 6, 2, 4, 4],
         [6, 2, 6, 4, 4, 6, 6, 2, 4, 4],
         [6, 6, 6, 4, 4, 6, 6, 2, 4, 4],
         [6, 6, 6, 4, 4, 6, 6, 6, 4, 4],
     ]
     for (p, q), expected in zip(union_seq, expected_ids):
         uf.union(p, q)
         self.assertEqual(uf.id, expected)
Example #3
0
 def test_components_count_7(self):
     uf = WeightedQuickUnionPathCompressionUF(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 #4
0
 def test_components_count_10(self):
     uf = WeightedQuickUnionPathCompressionUF(10)
     self.assertEqual(uf.components_count, 10)
Example #5
0
 def test_type(self):
     uf = WeightedQuickUnionPathCompressionUF(10)
     self.assertIsInstance(uf, QuickUnionUF)