test_distance_regular.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import networkx as nx
  2. from networkx import is_strongly_regular
  3. class TestDistanceRegular:
  4. def test_is_distance_regular(self):
  5. assert nx.is_distance_regular(nx.icosahedral_graph())
  6. assert nx.is_distance_regular(nx.petersen_graph())
  7. assert nx.is_distance_regular(nx.cubical_graph())
  8. assert nx.is_distance_regular(nx.complete_bipartite_graph(3, 3))
  9. assert nx.is_distance_regular(nx.tetrahedral_graph())
  10. assert nx.is_distance_regular(nx.dodecahedral_graph())
  11. assert nx.is_distance_regular(nx.pappus_graph())
  12. assert nx.is_distance_regular(nx.heawood_graph())
  13. assert nx.is_distance_regular(nx.cycle_graph(3))
  14. # no distance regular
  15. assert not nx.is_distance_regular(nx.path_graph(4))
  16. def test_not_connected(self):
  17. G = nx.cycle_graph(4)
  18. nx.add_cycle(G, [5, 6, 7])
  19. assert not nx.is_distance_regular(G)
  20. def test_global_parameters(self):
  21. b, c = nx.intersection_array(nx.cycle_graph(5))
  22. g = nx.global_parameters(b, c)
  23. assert list(g) == [(0, 0, 2), (1, 0, 1), (1, 1, 0)]
  24. b, c = nx.intersection_array(nx.cycle_graph(3))
  25. g = nx.global_parameters(b, c)
  26. assert list(g) == [(0, 0, 2), (1, 1, 0)]
  27. def test_intersection_array(self):
  28. b, c = nx.intersection_array(nx.cycle_graph(5))
  29. assert b == [2, 1]
  30. assert c == [1, 1]
  31. b, c = nx.intersection_array(nx.dodecahedral_graph())
  32. assert b == [3, 2, 1, 1, 1]
  33. assert c == [1, 1, 1, 2, 3]
  34. b, c = nx.intersection_array(nx.icosahedral_graph())
  35. assert b == [5, 2, 1]
  36. assert c == [1, 2, 5]
  37. class TestStronglyRegular:
  38. """Unit tests for the :func:`~networkx.is_strongly_regular`
  39. function.
  40. """
  41. def test_cycle_graph(self):
  42. """Tests that the cycle graph on five vertices is strongly
  43. regular.
  44. """
  45. G = nx.cycle_graph(5)
  46. assert is_strongly_regular(G)
  47. def test_petersen_graph(self):
  48. """Tests that the Petersen graph is strongly regular."""
  49. G = nx.petersen_graph()
  50. assert is_strongly_regular(G)
  51. def test_path_graph(self):
  52. """Tests that the path graph is not strongly regular."""
  53. G = nx.path_graph(4)
  54. assert not is_strongly_regular(G)