Esempio n. 1
0
def test_depth_scan_05():
    g = graph01()

    def criteria(n):
        return n < 5

    result = g.depth_scan(1, criteria)
    assert max(result) == 5, result
Esempio n. 2
0
def test01():
    """
    Asserts that the shortest_path is correct
    """
    g = graph01()
    dist, path = g.shortest_path(1, 4)
    assert [1, 3, 2, 4] == path, path
    assert 9 == dist, dist
Esempio n. 3
0
def test_depth_scan_04():
    """ criteria negative on start"""
    g = graph01()

    def criteria(n):
        return False

    empty_set = set()
    assert g.depth_scan(1, criteria) == empty_set
Esempio n. 4
0
def test_depth_scan_02():
    """ criteria not callable"""
    g = graph01()

    criteria = 41  # not callable
    try:
        g.depth_scan(1, criteria)
        assert False, "criteria must be a callable, so this is not possible"
    except TypeError:
        assert True
Esempio n. 5
0
def test_depth_scan_03():
    """ start not in graph """
    g = graph01()
    start_that_doesnt_exist = max(g.nodes()) + 1

    def criteria(n):
        return False

    try:
        g.depth_scan(start_that_doesnt_exist, criteria)
        assert False, "start isn't in g, so reaching this code isn't possible."
    except ValueError:
        assert True
Esempio n. 6
0
def test_to_list():
    g1 = graph01()
    g1.add_node(44)
    g2 = Graph(from_list=g1.to_list())
    assert g1.edges() == g2.edges()
    assert g1.nodes() == g2.nodes()