Anders and Briegel in Python
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
1.5KB

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