def test_vertices(): g = Graph() for i in range(10): assert len(g.vertices()) == g.get_vertex_count() g.add_vertex(i) assert i in g.vertices() for i in range(10): g.remove_vertex(i) assert len(g.vertices()) == g.get_vertex_count() assert i not in g.vertices()
def test_neighbours(): g = Graph() for i in range(10): g.add_vertex(i) for v in g.vertices(): for w in range(v): assert len(g.neighbours(v)) == g.degree(v) assert len(g.neighbours(v, outgoing = False)) == g.degree(v, outgoing = False) assert len(g.neighbours(v, ingoing = False)) == g.degree(v, ingoing = False) assert g.degree(v) == g.degree(v, outgoing = False) + g.degree(v, ingoing = False) g.add_edge(v,w,v-w) assert (w,v-w) in g.neighbours(v) assert (v,v-w) in g.neighbours(w) assert (w,v-w) in g.neighbours(v, ingoing = False) assert (v,v-w) in g.neighbours(w, outgoing = False) assert (w,v-w) not in g.neighbours(v, outgoing = False) assert (v,v-w) not in g.neighbours(w, ingoing = False)