Exemple #1
0
def test_Vertex_add_directed_edge_2():
    vertex = Vertex(1)
    edge_1 = Vertex(3)
    edge_2 = Vertex(4)
    vertex.add_directed_edge(edge_1)
    vertex.add_directed_edge(edge_2)
    assert vertex.directed_edges == {edge_1, edge_2}
Exemple #2
0
 def __init__(self, name: str, parent: (Block, Device)):
     Vertex.__init__(self, name)
     Net.__init__(self, name, parent)
        v.value = curval[0]
        curval[0] -= 1

    for v in vertices:
        if v.vid not in visited:
            DFS(v)


if __name__ == "__main__":

    # A----->B----->C
    # |             ^
    # |             |
    # +----->D------+
    A = Vertex("A")
    B = Vertex("B")
    C = Vertex("C")
    D = Vertex("D")
    edges = [
        (A, B),
        (A, D),
        (B, C),
        (D, C),
    ]
    graph = DirectedGraph(edges=edges)
    topological_sort(graph)

    # ('A', 1) -> ('B', 3) -> ('C', 4)
    # ('A', 1) -> ('D', 2) -> ('C', 4)
    def dfspp(graph, start):
Exemple #4
0
def test_Vertex_get_directed_edges_2():
    vertex = Vertex(1)
    edge_1 = Vertex(2)
    edge_2 = Vertex(3)
    vertex.directed_edges = {edge_1, edge_2}
    assert vertex.get_directed_edges() == {edge_1, edge_2}
Exemple #5
0
def test_Vertex_add_directed_edge_1():
    vertex = Vertex(1)
    edge_1 = Vertex(2)
    vertex.add_directed_edge(edge_1)
    assert vertex.directed_edges == {edge_1}
Exemple #6
0
def test_Vertex_set_data_2():
    vertex = Vertex(1)
    vertex.set_data(0)
    assert vertex.get_data() == 0
Exemple #7
0
def test_Vertex_get_directed_edges_1():
    vertex = Vertex(1)
    assert vertex.get_directed_edges() == set()
Exemple #8
0
def test_Vertex_set_data_1():
    vertex = Vertex(1)
    vertex.set_data(2)
    assert vertex.get_data() == 2
Exemple #9
0
def test_Vertex_get_data_2():
    vertex = Vertex(3)
    assert vertex.get_data() == 3
Exemple #10
0
def test_Vertex_get_data_1():
    vertex = Vertex(1)
    assert vertex.get_data() == 1
Exemple #11
0
def test_Vertex_init_2():
    vertex = Vertex(2)
    assert vertex.directed_edges == set()
Exemple #12
0
def test_Vertex_init_1():
    vertex = Vertex(1)
    assert vertex.data == 1