def test_connected_component():
    edge0 = Edge(0, 1)
    edge1 = Edge(2, 3)
    edges = [edge0, edge1]
    g = BaseGraph(edges)
    assert connected_component(g, 0) == BaseGraph([edge0])
    assert connected_component(g, 2) == BaseGraph([edge1])
Example #2
0
def test_intersection():
    graph0 = BaseGraph([Edge(i, i + 1) for i in range(2)])
    graph1 = BaseGraph([Edge(0, 1)])
    graph2 = BaseGraph([Edge("a", "b")])
    graph01 = graph0 * graph1
    graph02 = graph0 * graph2
    assert graph01.edges == set([Edge(0, 1)])
    assert graph02.edges == set()
Example #3
0
def test_vertices():
    edges = [Edge(i, i + 1) for i in range(3)]
    graph = BaseGraph(edges)
    vertices = []
    for i in graph.vertices:
        vertices.append(i)
    assert len(vertices) == 4
def test_neighborhood():
    edges = [Edge(0, 1)]
    g = BaseGraph(edges)
    assert neighborhood(g, 0) == g
    assert neighborhood(g, 1) == BaseGraph()
Example #5
0
def test_subtract():
    graph = BaseGraph([Edge(0, 1)])
    zero_graph = graph - graph
    assert zero_graph.edges == set()
Example #6
0
def test_add():
    graph0 = BaseGraph([Edge(0, 1)])
    graph1 = BaseGraph([Edge(1, 2)])
    sum_graph = graph0 + graph1
    assert sum_graph.edges == set([Edge(i, i + 1) for i in range(2)])
Example #7
0
def test_extend():
    graph = BaseGraph()
    edges = [Edge(i, i + 1) for i in range(2)]
    graph.extend(edges)
    assert graph.edges == set([Edge(i, i + 1) for i in range(2)])
Example #8
0
def test_append():
    graph = BaseGraph()
    edge = Edge(source="a", target="b")
    graph.append(edge)
    assert graph.edges == set([edge])
Example #9
0
def test_size():
    edges = [Edge(i, i + 1) for i in range(3)]
    graph = BaseGraph(edges)
    assert graph.size == 3
Example #10
0
def test_order():
    edges = [Edge(i, i + 1) for i in range(3)]
    graph = BaseGraph(edges)
    assert graph.order == 4
Example #11
0
def test_nonempty_graph():
    edges = [Edge(i, i + 1) for i in range(3)]
    graph = BaseGraph(edges)
    assert graph.edges == set([Edge(i, i + 1) for i in range(3)])
Example #12
0
def test_unhashable_edge():
    source = set()
    target = "b"
    edge = Edge(source=source, target=target)
    with pytest.raises(ValueError):
        BaseGraph([edge])
Example #13
0
def test_empty_graph():
    graph = BaseGraph()
    assert graph.edges == set()
Example #14
0
def test_not_equals():
    g = BaseGraph()
    h = BaseGraph([Edge("a", "b")])
    assert g != h
Example #15
0
def test_contains():
    edge = Edge(0, 1)
    non_edge = Edge("a", "b")
    graph = BaseGraph([edge])
    assert edge in graph.edges
    assert non_edge not in graph.edges