Пример #1
0
def test_adj():
    g = WeightedGraph()
    g.add_edge(u"A", u"C")
    g.add_node(u"B")
    print g.edges()
    assert g.adjacent(u"A", u"C") is True
    assert g.adjacent(u"C", u"A") is True
    assert g.adjacent(u"B", u"C") is False
    assert g.adjacent(u"B", u"A") is False
    with pytest.raises(KeyError):
        g.adjacent(u"A", u"D")
Пример #2
0
def test_del_edge():
    g = WeightedGraph()
    g.add_edge(u"A", u"C")
    g.del_edge(u"A", u"C")
    assert (u"A", u"C") not in g.edges()
    assert u"A" in g.nodes()
    assert u"C" in g.nodes()
    assert g.edgeWeights.pop((u"A", u"C"), False) == False
Пример #3
0
def test_edges_empty():
    g = WeightedGraph()
    assert g.edges() == set()
Пример #4
0
def test_del_node():
    g = WeightedGraph()
    g.add_edge(u"A", u"C")
    g.del_node(u"A")
    assert u"A" not in g.nodes()
    assert (u"A", u"C") not in g.edges()
Пример #5
0
def test_add_edge_two_new_nodes():
    g = WeightedGraph()
    g.add_edge(u"A", u"C")
    assert u"A" in g.nodes()
    assert u"C" in g.nodes()
    assert (u"A", u"C") in g.edges()
Пример #6
0
def test_add_edge():
    g = WeightedGraph()
    g.add_node(u"A")
    g.add_node(u"B")
    g.add_edge(u"A", u"B")
    assert (u"A", u"B") in g.edges()