浏览代码

Test passing

master
Pete Shadbolt 8 年前
父节点
当前提交
c3402c6661
共有 2 个文件被更改,包括 12 次插入12 次删除
  1. +1
    -1
      graph.py
  2. +11
    -11
      tests/test_graph.py

+ 1
- 1
graph.py 查看文件

@@ -7,7 +7,7 @@ def graph(n):
""" Generate a graph with Hadamards on each qubit """
graph = [set() for i in xrange(n)]
vops = [0 for i in xrange(n)]
return graph, vops
return graph, vops # TODO: seems ugly

def add_edge(graph, v1, v2):
""" Add an edge between two vertices in the graph """


+ 11
- 11
tests/test_graph.py 查看文件

@@ -1,18 +1,18 @@
from graph import Graph
from graph import *

def test_graph():
g = Graph(3)
g.add_edge(0,1)
g.add_edge(1,2)
g.add_edge(2,0)
assert g.neighbours[0]==set([1,2])
g, v = graph(3)
add_edge(g, 0,1)
add_edge(g, 1,2)
add_edge(g, 2,0)
assert g[0]==set([1,2])

g.del_edge(0,1)
assert g.neighbours[0]==set([2])
el = g.edgelist()
del_edge(g, 0,1)
assert g[0]==set([2])
el = edgelist(g)
assert (1,2) in el
assert not (0,1) in el
assert len(el)==2

assert g.has_edge(1,2)
assert not g.has_edge(0,1)
assert has_edge(g, 1,2)
assert not has_edge(g, 0,1)

正在加载...
取消
保存