示例#1
0
 def test_topologic(self):
     """Testing 'topologic' libraries.
     
     + 'topo' function.
     + 'Graph' class.
     """
     from core.libs import Graph
     G = Graph([(0, 1), (0, 4), (1, 5), (2, 3), (2, 4), (3, 5), (4, 5)])
     H = Graph([(0, 2), (0, 4), (1, 3), (1, 4), (2, 5), (3, 5), (4, 5)])
     I = Graph([(0, 1), (0, 2), (1, 4), (2, 5), (3, 4), (3, 5), (4, 5)])
     self.assertTrue(G.is_isomorphic(H))
     self.assertFalse(G.is_isomorphic(I))
     answer, time = topo([4, 2], degenerate=True)
     self.assertEqual(len(answer), 2)
示例#2
0
    def __is_valid_graph(self, g: Graph) -> str:
        """Test graph and return True if it is valid."""
        if not g.edges:
            return "is an empty graph"

        if not g.is_connected():
            return "is not a close chain"
        if not is_planar(g):
            return "is not a planar chain"
        if g.has_cut_link():
            return "has cut link"

        try:
            external_loop_layout(g, True)
        except ValueError as error:
            return str(error)

        for h in self.collections:
            if g.is_isomorphic(h):
                return f"is isomorphic with: {h.edges}"
        return ""