Browse Source

Test passing

master
Pete Shadbolt 8 years ago
parent
commit
c3402c6661
2 changed files with 12 additions and 12 deletions
  1. +1
    -1
      graph.py
  2. +11
    -11
      tests/test_graph.py

+ 1
- 1
graph.py View File

@@ -7,7 +7,7 @@ def graph(n):
""" Generate a graph with Hadamards on each qubit """ """ Generate a graph with Hadamards on each qubit """
graph = [set() for i in xrange(n)] graph = [set() for i in xrange(n)]
vops = [0 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): def add_edge(graph, v1, v2):
""" Add an edge between two vertices in the graph """ """ Add an edge between two vertices in the graph """


+ 11
- 11
tests/test_graph.py View File

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


def test_graph(): 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 (1,2) in el
assert not (0,1) in el assert not (0,1) in el
assert len(el)==2 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)

Loading…
Cancel
Save