Anders and Briegel in Python
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

test_graph.py 1.5KB

hace 8 años
hace 8 años
hace 8 años
hace 8 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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