Anders and Briegel in Python
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

70 wiersze
1.6KB

  1. from abp.graph import GraphState
  2. import abp.tables as tables
  3. import time
  4. def demograph():
  5. """ A graph for testing with """
  6. g = GraphState()
  7. g.add_edge(0, 1)
  8. g.add_edge(1, 2)
  9. g.add_edge(2, 0)
  10. g.add_edge(0, 3)
  11. g.add_edge(100, 200)
  12. return g
  13. def test_graph_basic():
  14. """ Test that we can construct graphs, delete edges, whatever """
  15. g = demograph()
  16. assert g.ngbh[0] == set([1, 2, 3])
  17. g.del_edge(0, 1)
  18. assert g.ngbh[0] == set([2, 3])
  19. assert g.has_edge(1, 2)
  20. assert not g.has_edge(0, 1)
  21. def test_local_complementation():
  22. """ Test that local complementation works as expected """
  23. g = demograph()
  24. g.local_complementation(0)
  25. assert g.has_edge(0, 1)
  26. assert g.has_edge(0, 2)
  27. assert not g.has_edge(1, 2)
  28. assert g.has_edge(3, 2)
  29. assert g.has_edge(3, 1)
  30. # TODO: test VOP conditions
  31. def test_remove_vop():
  32. """ Test that removing VOPs really works """
  33. g = demograph()
  34. g.remove_vop(0, 1)
  35. #assert g.vops[0] == lc.by_name["identity"]
  36. g.remove_vop(1, 1)
  37. #assert g.vops[1] == lc.by_name["identity"]
  38. g.remove_vop(2, 1)
  39. #assert g.vops[2] == lc.by_name["identity"]
  40. g.remove_vop(0, 1)
  41. #assert g.vops[0] == lc.by_name["identity"]
  42. def test_edgelist():
  43. """ Test making edgelists """
  44. g = demograph()
  45. el = g.edgelist()
  46. assert (0, 3) in el
  47. assert (0, 2) in el
  48. assert (100, 200) in el
  49. def test_million_sites():
  50. """ Testing that making a graph of ten thousand qubits takes less than half a second"""
  51. g = GraphState()
  52. t = time.clock()
  53. for i in xrange(100000):
  54. g.add_edge(i, i + 1)
  55. assert time.clock() - t < .5