Ejemplo n.º 1
0
 def test_non_consecutive_adding(self):
     """Test adding vertices non-consecutively."""
     # Create { }.
     a_graph = UnionFind()
     # Add 1 to { }, which becomes { {0}, {1} }.
     # Here 0 is added implicitly.
     a_graph.add(1)
     self.assertEqual(a_graph.n_vertices(), 2)
     self.assertEqual(a_graph.connected(0, 0), True)
     self.assertEqual(a_graph.connected(0, 1), False)
     self.assertEqual(a_graph.connected(1, 1), True)
Ejemplo n.º 2
0
 def test_consecutive_adding(self):
     """Test adding vertices consecutively."""
     # Create { }.
     a_graph = UnionFind()
     # Add 0 to { }, which becomes { {0} }.
     a_graph.add(0)
     self.assertEqual(a_graph.n_vertices(), 1)
     self.assertEqual(a_graph.connected(0, 0), True)
     self.assertEqual(a_graph.connected(0, 1), False)
     self.assertEqual(a_graph.connected(1, 1), False)
     # Add 0 to { {0} }, nothing changes.
     a_graph.add(0)
     self.assertEqual(a_graph.n_vertices(), 1)
     self.assertEqual(a_graph.connected(0, 0), True)
     self.assertEqual(a_graph.connected(0, 1), False)
     self.assertEqual(a_graph.connected(1, 1), False)
     # Add 1 to { {0} }, which becomes { {0}, {1} }.
     a_graph.add(1)
     self.assertEqual(a_graph.n_vertices(), 2)
     self.assertEqual(a_graph.connected(0, 0), True)
     self.assertEqual(a_graph.connected(0, 1), False)
     self.assertEqual(a_graph.connected(1, 1), True)