Beispiel #1
0
def test_topo_sorting_bad():
    g = Graph()
    nodes = []
    for i in xrange(3):
        g.add_node(i)
        nodes.append(g.get_node(i))
    edges = [(0, 1), (1, 2), (2, 1)]
    for n1, n2 in edges:
        nodes[n1].add_edge_to(nodes[n2])
    topo_sorting = g.produce_topo_sorting()
    assert topo_sorting is None
Beispiel #2
0
def test_topo_sorting_bad():
    g = Graph()
    nodes = []
    for i in xrange(3):
        g.add_node(i)
        nodes.append(g.get_node(i))
    edges = [(0, 1), (1, 2), (2, 1)]
    for n1, n2 in edges:
        nodes[n1].add_edge_to(nodes[n2])
    topo_sorting = g.produce_topo_sorting()
    assert topo_sorting is None
Beispiel #3
0
def test_topo_sorting_good():
    g = Graph()
    nodes = []
    for i in xrange(5):
        g.add_node(i)
        nodes.append(g.get_node(i))
    edges = [(0, 1), (1, 2), (1, 3), (2, 4), (3, 4)]
    for n1, n2 in edges:
        nodes[n1].add_edge_to(nodes[n2])
    topo_sorting = g.produce_topo_sorting()
    valid = [[0, 1, 2, 3, 4], [0, 1, 3, 2, 4]]
    assert topo_sorting in valid
Beispiel #4
0
def test_topo_sorting_good():
    g = Graph()
    nodes = []
    for i in xrange(5):
        g.add_node(i)
        nodes.append(g.get_node(i))
    edges = [(0, 1), (1, 2), (1, 3), (2, 4), (3, 4)]
    for n1, n2 in edges:
        nodes[n1].add_edge_to(nodes[n2])
    topo_sorting = g.produce_topo_sorting()
    valid = [[0, 1, 2, 3, 4],
             [0, 1, 3, 2, 4]]
    assert topo_sorting in valid