Esempio n. 1
0
 def test_graph_degree_code(self):
     g1 = Graph([
         (0, 1),
         (0, 2),
         (0, 3),
         (0, 5),
         (2, 3),
         (3, 4),
         (2, 5),
         (3, 5),
         (4, 6),
         (3, 6),
     ])
     g2 = Graph([
         (0, 1),
         (0, 4),
         (0, 2),
         (0, 6),
         (0, 3),
         (1, 4),
         (2, 6),
         (2, 5),
         (3, 6),
         (2, 3),
     ])
     self.assertTrue(g1.is_isomorphic(g2))
     self.assertEqual(2057732, g1.degree_code())
     self.assertEqual(g1.degree_code(), g2.degree_code())
     for code, edges in DEGREE_CODE_TABLE:
         self.assertEqual(code, Graph(edges).degree_code())
Esempio n. 2
0
 def __is_valid_graph(self, edges: Iterable[Tuple[int, int]]) -> str:
     """Test graph and return True if it is valid."""
     try:
         g = Graph(edges)
     except (TypeError, ValueError):
         return "wrong format"
     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 ""
Esempio n. 3
0
 def test_graph_isomorphic(self):
     g1 = Graph([(0, 1), (0, 4), (1, 5), (2, 3), (2, 4), (3, 5), (4, 5)])
     g2 = Graph([(0, 2), (0, 4), (1, 3), (1, 4), (2, 5), (3, 5), (4, 5)])
     g3 = Graph([(0, 1), (0, 2), (1, 4), (2, 5), (3, 4), (3, 5), (4, 5)])
     self.assertTrue(g1.is_isomorphic(g2))
     self.assertFalse(g1.is_isomorphic(g3))