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}
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):
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}
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}
def test_Vertex_set_data_2(): vertex = Vertex(1) vertex.set_data(0) assert vertex.get_data() == 0
def test_Vertex_get_directed_edges_1(): vertex = Vertex(1) assert vertex.get_directed_edges() == set()
def test_Vertex_set_data_1(): vertex = Vertex(1) vertex.set_data(2) assert vertex.get_data() == 2
def test_Vertex_get_data_2(): vertex = Vertex(3) assert vertex.get_data() == 3
def test_Vertex_get_data_1(): vertex = Vertex(1) assert vertex.get_data() == 1
def test_Vertex_init_2(): vertex = Vertex(2) assert vertex.directed_edges == set()
def test_Vertex_init_1(): vertex = Vertex(1) assert vertex.data == 1