test_cographs.py 460 B

1234567891011121314151617181920
  1. """Unit tests for the :mod:`networkx.generators.cographs` module.
  2. """
  3. import networkx as nx
  4. def test_random_cograph():
  5. n = 3
  6. G = nx.random_cograph(n)
  7. assert len(G) == 2**n
  8. # Every connected subgraph of G has diameter <= 2
  9. if nx.is_connected(G):
  10. assert nx.diameter(G) <= 2
  11. else:
  12. components = nx.connected_components(G)
  13. for component in components:
  14. assert nx.diameter(G.subgraph(component)) <= 2